Fix EEBus UI config: save fails after successful validation (#28592)
This commit is contained in:
parent
948dda081c
commit
23c6bbb431
3 changed files with 18 additions and 2 deletions
|
|
@ -100,6 +100,12 @@ func NewEEBus(ctx context.Context, ski, ip string, hasMeter, hasChargedEnergy, v
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// unregister device when context is cancelled (e.g. UI config validation)
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
eebus.Instance.UnregisterDevice(ski, c)
|
||||
}()
|
||||
|
||||
if hasMeter {
|
||||
var energyG func() (float64, error)
|
||||
if hasChargedEnergy {
|
||||
|
|
|
|||
|
|
@ -99,6 +99,12 @@ func NewEEBus(ctx context.Context, ski, ip string, usage *templates.Usage) (api.
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// unregister device when context is cancelled (e.g. UI config validation)
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
eebus.Instance.UnregisterDevice(ski, c)
|
||||
}()
|
||||
|
||||
// monitoring appliance
|
||||
eebus.LogEntities(c.log.DEBUG, "MA MPC", c.ma.MaMPCInterface)
|
||||
eebus.LogEntities(c.log.DEBUG, "MA MGCP", c.ma.MaMGCPInterface)
|
||||
|
|
|
|||
|
|
@ -236,14 +236,18 @@ func (c *EEBus) UnregisterDevice(ski string, device Device) {
|
|||
ski = shiputil.NormalizeSKI(ski)
|
||||
c.log.TRACE.Printf("unregistering ski: %s", ski)
|
||||
|
||||
c.service.UnregisterRemoteSKI(ski)
|
||||
|
||||
c.mux.Lock()
|
||||
defer c.mux.Unlock()
|
||||
|
||||
if idx := slices.Index(c.clients[ski], device); idx != -1 {
|
||||
c.clients[ski] = slices.Delete(c.clients[ski], idx, idx+1)
|
||||
}
|
||||
|
||||
// only tear down SHIP connection when no more clients need it
|
||||
if len(c.clients[ski]) == 0 {
|
||||
delete(c.clients, ski)
|
||||
c.service.UnregisterRemoteSKI(ski)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *EEBus) CustomerEnergyManagement() *CustomerEnergyManagement {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue