From 0e3a9dcd804ea9cfacccaacfae608c0470fec49b Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 29 Sep 2025 08:49:22 +0200 Subject: [PATCH] =?UTF-8?q?HEMS:=20indicate=20=C2=A714a=20circuit=20limit?= =?UTF-8?q?=20(#23927)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/api.go | 4 ++++ api/mock.go | 26 ++++++++++++++++++++++++++ core/circuit/circuit.go | 22 ++++++++++++++++++++++ core/site_circuits.go | 2 ++ hems/eebus/eebus.go | 1 + hems/relay/relay.go | 1 + 6 files changed, 56 insertions(+) diff --git a/api/api.go b/api/api.go index f09290e1d..887508562 100644 --- a/api/api.go +++ b/api/api.go @@ -258,6 +258,10 @@ type Circuit interface { Update([]CircuitLoad) error ValidateCurrent(old, new float64) float64 ValidatePower(old, new float64) float64 + + // ยง14a + Dim(bool) + Dimmed() bool } // Redactor is an interface to redact sensitive data diff --git a/api/mock.go b/api/mock.go index 3e93da220..8c7270832 100644 --- a/api/mock.go +++ b/api/mock.go @@ -816,6 +816,32 @@ func (m *MockCircuit) EXPECT() *MockCircuitMockRecorder { return m.recorder } +// Dim mocks base method. +func (m *MockCircuit) Dim(arg0 bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Dim", arg0) +} + +// Dim indicates an expected call of Dim. +func (mr *MockCircuitMockRecorder) Dim(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Dim", reflect.TypeOf((*MockCircuit)(nil).Dim), arg0) +} + +// Dimmed mocks base method. +func (m *MockCircuit) Dimmed() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Dimmed") + ret0, _ := ret[0].(bool) + return ret0 +} + +// Dimmed indicates an expected call of Dimmed. +func (mr *MockCircuitMockRecorder) Dimmed() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Dimmed", reflect.TypeOf((*MockCircuit)(nil).Dimmed)) +} + // GetChargePower mocks base method. func (m *MockCircuit) GetChargePower() float64 { m.ctrl.T.Helper() diff --git a/core/circuit/circuit.go b/core/circuit/circuit.go index d2a7ceff9..6a06d69a4 100644 --- a/core/circuit/circuit.go +++ b/core/circuit/circuit.go @@ -36,6 +36,7 @@ type Circuit struct { current float64 power float64 + dimmed bool currentUpdated time.Time powerUpdated time.Time @@ -374,3 +375,24 @@ func (c *Circuit) ValidateCurrent(old, new float64) float64 { return c.parent.ValidateCurrent(old, new) } + +func (c *Circuit) Dim(dim bool) { + c.mu.Lock() + defer c.mu.Unlock() + c.dimmed = dim +} + +func (c *Circuit) Dimmed() bool { + c.mu.RLock() + defer c.mu.RUnlock() + + if c.dimmed { + return true + } + + if c.parent == nil { + return false + } + + return c.parent.Dimmed() +} diff --git a/core/site_circuits.go b/core/site_circuits.go index 17ce21a33..1a6305417 100644 --- a/core/site_circuits.go +++ b/core/site_circuits.go @@ -13,6 +13,7 @@ type circuitStruct struct { Current *float64 `json:"current,omitempty"` MaxPower float64 `json:"maxPower,omitempty"` MaxCurrent float64 `json:"maxCurrent,omitempty"` + Dimmed bool `json:"dimmed"` } // publishCircuits returns a list of circuit titles @@ -30,6 +31,7 @@ func (site *Site) publishCircuits() { Power: instance.GetChargePower(), MaxPower: instance.GetMaxPower(), MaxCurrent: instance.GetMaxCurrent(), + Dimmed: instance.Dimmed(), } if instance.GetMaxCurrent() > 0 { diff --git a/hems/eebus/eebus.go b/hems/eebus/eebus.go index 12c8d5bae..1ec211df5 100644 --- a/hems/eebus/eebus.go +++ b/hems/eebus/eebus.go @@ -222,5 +222,6 @@ func (c *EEBus) setStatusAndLimit(status status, limit float64) { } func (c *EEBus) setLimit(limit float64) { + c.root.Dim(limit > 0) c.root.SetMaxPower(limit) } diff --git a/hems/relay/relay.go b/hems/relay/relay.go index 3e72fb458..583f3fcc6 100644 --- a/hems/relay/relay.go +++ b/hems/relay/relay.go @@ -95,6 +95,7 @@ func (c *Relay) run() error { power = c.maxPower } + c.root.Dim(limit) c.root.SetMaxPower(power) return nil