HEMS: make Dimmed/Curtailed tri-state (once more) (#30712)

This commit is contained in:
andig 2026-06-10 22:16:58 +02:00 • committed by GitHub
parent d859ae9c7c
commit 45cab34ce9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 32 additions and 31 deletions

View file

@ -294,17 +294,17 @@ func (c *EEBus) setProductionLimit(limit float64, active bool) {
var _ api.HEMS = (*EEBus)(nil)
// Dimmed implements api.HEMS, derived from consumptionLimitActivated.
func (c *EEBus) Dimmed() bool {
func (c *EEBus) Dimmed() *bool {
c.mux.RLock()
defer c.mux.RUnlock()
return !c.consumptionLimitActivated.IsZero()
return new(!c.consumptionLimitActivated.IsZero())
}
// Curtailed implements api.HEMS, derived from productionLimitActivated.
func (c *EEBus) Curtailed() bool {
func (c *EEBus) Curtailed() *bool {
c.mux.RLock()
defer c.mux.RUnlock()
return !c.productionLimitActivated.IsZero()
return new(!c.productionLimitActivated.IsZero())
}
// MaxConsumptionPower implements api.HEMS, returning the consumption cap

View file

@ -49,14 +49,14 @@ func newTestEEBus(t *testing.T) *EEBus {
// assertConsumptionLimit checks the HEMS consumption state through the api.HEMS surface.
func assertConsumptionLimit(t *testing.T, c *EEBus, limit float64) {
t.Helper()
assert.Equal(t, limit > 0, c.Dimmed())
assert.Equal(t, new(limit > 0), c.Dimmed())
assert.Equal(t, limit, c.MaxConsumptionPower())
}
// assertProductionLimit checks the HEMS production state through the api.HEMS surface.
func assertProductionLimit(t *testing.T, c *EEBus, active bool) {
t.Helper()
assert.Equal(t, active, c.Curtailed())
assert.Equal(t, new(active), c.Curtailed())
}
// TestRun_HeartbeatLost_EntersFailsafe verifies the LPC-911/LPP-911 transition:

View file

@ -223,25 +223,25 @@ func (c *Fnn) setConsumptionLimit(limit float64) error {
var _ api.HEMS = (*Fnn)(nil)
// Dimmed implements api.HEMS.
func (c *Fnn) Dimmed() bool {
func (c *Fnn) Dimmed() *bool {
if c.w4 == nil {
return false
return nil
}
c.mu.Lock()
defer c.mu.Unlock()
return c.consumptionLimit > 0
return new(c.consumptionLimit > 0)
}
// Curtailed implements api.HEMS.
func (c *Fnn) Curtailed() bool {
func (c *Fnn) Curtailed() *bool {
if c.w3 == nil {
return false
return nil
}
c.mu.Lock()
defer c.mu.Unlock()
return c.productionLimit != nil
return new(c.productionLimit != nil)
}
// MaxConsumptionPower implements api.HEMS.

View file

@ -137,15 +137,16 @@ func (c *Relay) setConsumptionLimit(limit float64) error {
var _ api.HEMS = (*Relay)(nil)
// Dimmed implements api.HEMS, derived from the active consumption limit.
func (c *Relay) Dimmed() bool {
func (c *Relay) Dimmed() *bool {
c.mu.Lock()
defer c.mu.Unlock()
return c.limit != nil
return new(c.limit != nil)
}
// Curtailed implements api.HEMS. Relay does not curtail production.
func (c *Relay) Curtailed() bool {
return false
// Curtailed implements api.HEMS. Relay does not curtail production and
// hence makes no statement.
func (c *Relay) Curtailed() *bool {
return nil
}
// MaxConsumptionPower implements api.HEMS, returning the active wattage cap.