EEBus: clamp the curtailment percent to the documented maximum (#33300)

This commit is contained in:
andig 2026-08-30 10:31:40 +02:00 • committed by GitHub
parent dbe100b24b
commit d379b7802e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View file

@ -393,7 +393,8 @@ func (c *EEBus) CurtailedPercent() *int {
percent := 100
if limitActive(c.productionLimitActivated) {
percent = int(c.effectiveProductionLimit() / c.productionNominalMax * 100)
// the EG may state a limit above the nominal production power
percent = min(int(c.effectiveProductionLimit()/c.productionNominalMax*100), 100)
}
return &percent

View file

@ -325,6 +325,21 @@ func TestProductionLimit_FailsafeUnconfigured(t *testing.T) {
assert.Equal(t, 0.0, *power)
}
// TestCurtailedPercent_AboveNominal verifies a limit above the nominal production
// power reports 100%, not more - api.HEMS documents the percent as 0..100 and it
// reaches the inverter unchecked.
func TestCurtailedPercent_AboveNominal(t *testing.T) {
c := newTestEEBus(t)
c.heartbeat.Set(struct{}{})
c.productionLimit = ucapi.LoadLimit{Value: -2 * testProductionNominal, IsActive: true}
require.NoError(t, c.run())
percent := c.CurtailedPercent()
require.NotNil(t, percent)
assert.Equal(t, 100, *percent)
}
// TestMaxProductionPower verifies the api.HEMS export cap is a positive wattage,
// while LPP states its limits as negative watts.
func TestMaxProductionPower(t *testing.T) {