Config UI: cleanup circuit references (#21525)

This commit is contained in:
Simon Schenk 2025-05-31 10:21:36 +02:00 • committed by GitHub
parent e30102270c
commit e5b3ce8271
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 5 deletions

View file

@ -5,8 +5,9 @@ const (
Title = "title" // loadpoint title
Mode = "mode" // charge mode
DefaultMode = "defaultMode" // default charge mode
Charger = "charger" // charger ref
Meter = "meter" // meter ref
Charger = "charger" // charger ref
Meter = "meter" // meter ref
Circuit = "circuit" // circuit ref
DefaultVehicle = "vehicle" // default vehicle ref
Priority = "priority" // priority
MinCurrent = "minCurrent" // min current

View file

@ -26,8 +26,6 @@ type API interface {
// references
//
// TODO SetCircuitRef
// GetChargerRef returns the loadpoint charger
GetChargerRef() string
// SetChargerRef sets the loadpoint charger
@ -36,8 +34,10 @@ type API interface {
GetMeterRef() string
// SetMeterRef sets the loadpoint meter
SetMeterRef(string)
// GetCircuitRef returns the loadpoint circuit name
// GetCircuitRef returns the loadpoint circuit
GetCircuitRef() string
// SetCircuitRef sets the loadpoint circuit
SetCircuitRef(string)
// GetCircuit returns the loadpoint circuit
GetCircuit() api.Circuit
// GetDefaultVehicleRef returns the loadpoint default vehicle

View file

@ -696,6 +696,18 @@ func (mr *MockAPIMockRecorder) SetChargerRef(arg0 any) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetChargerRef", reflect.TypeOf((*MockAPI)(nil).SetChargerRef), arg0)
}
// SetCircuitRef mocks base method.
func (m *MockAPI) SetCircuitRef(arg0 string) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetCircuitRef", arg0)
}
// SetCircuitRef indicates an expected call of SetCircuitRef.
func (mr *MockAPIMockRecorder) SetCircuitRef(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetCircuitRef", reflect.TypeOf((*MockAPI)(nil).SetCircuitRef), arg0)
}
// SetDefaultMode mocks base method.
func (m *MockAPI) SetDefaultMode(arg0 api.ChargeMode) {
m.ctrl.T.Helper()

View file

@ -66,6 +66,21 @@ func (lp *Loadpoint) GetCircuitRef() string {
return lp.CircuitRef
}
// SetCircuitRef sets the loadpoint circuit
func (lp *Loadpoint) SetCircuitRef(ref string) {
if !lp.isConfigurable() {
lp.log.ERROR.Println("cannot set circuit ref: not configurable")
return
}
lp.log.DEBUG.Println("set circuit ref:", ref)
lp.Lock()
defer lp.Unlock()
lp.CircuitRef = ref
lp.settings.SetString(keys.Circuit, ref)
}
// GetDefaultVehicleRef returns the loadpoint default vehicle
func (lp *Loadpoint) GetDefaultVehicleRef() string {
lp.RLock()

View file

@ -487,6 +487,14 @@ func deleteDeviceHandler(site site.API) func(w http.ResponseWriter, r *http.Requ
case templates.Circuit:
err = deleteDevice(id, config.Circuits())
// cleanup references
for _, dev := range h.Devices() {
lp := dev.Instance()
if lp.GetCircuitRef() == config.NameForID(id) {
lp.SetCircuitRef("")
}
}
}
setConfigDirty()