Config UI: cleanup circuit references (#21525)
This commit is contained in:
parent
e30102270c
commit
e5b3ce8271
5 changed files with 41 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue