From 2b16c415bbb1a588638645a668e4c09be657dd7e Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 8 May 2026 09:20:51 +0200 Subject: [PATCH] Fritz: make unit 1-based (BC) (#29741) --- meter/fritz/smarthome/smarthome.go | 4 ++-- meter/fritzdect.go | 5 ++++- templates/definition/charger/fritzdect.yaml | 1 + templates/definition/meter/fritzdect.yaml | 1 + templates/definition/meter/fritzgrid.yaml | 1 + 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/meter/fritz/smarthome/smarthome.go b/meter/fritz/smarthome/smarthome.go index 23a75ac32..ef9db252a 100644 --- a/meter/fritz/smarthome/smarthome.go +++ b/meter/fritz/smarthome/smarthome.go @@ -88,10 +88,10 @@ func (c *Connection) resolveUnitUID(unit int) (string, error) { if d.AIN != c.AIN { continue } - if len(d.UnitUids) < unit+1 { + if len(d.UnitUids) < unit { return "", fmt.Errorf("invalid unit %d, got %v", unit, d.UnitUids) } - return d.UnitUids[unit], nil + return d.UnitUids[unit-1], nil } return "", fmt.Errorf("ain not found: %s", c.AIN) diff --git a/meter/fritzdect.go b/meter/fritzdect.go index caa281e1f..d25e5b513 100644 --- a/meter/fritzdect.go +++ b/meter/fritzdect.go @@ -18,7 +18,10 @@ func init() { // NewFritzDECTFromConfig creates a fritzdect meter from generic config func NewFritzDECTFromConfig(other map[string]any) (api.Meter, error) { - var cc fritz.Settings + cc := fritz.Settings{ + Unit: 1, + } + if err := util.DecodeOther(other, &cc); err != nil { return nil, err } diff --git a/templates/definition/charger/fritzdect.yaml b/templates/definition/charger/fritzdect.yaml index 2d75a7ddd..509168375 100644 --- a/templates/definition/charger/fritzdect.yaml +++ b/templates/definition/charger/fritzdect.yaml @@ -39,6 +39,7 @@ params: - name: unit advanced: true type: int + default: 1 description: de: Einheit en: Unit diff --git a/templates/definition/meter/fritzdect.yaml b/templates/definition/meter/fritzdect.yaml index c4ca34a97..1a659d54f 100644 --- a/templates/definition/meter/fritzdect.yaml +++ b/templates/definition/meter/fritzdect.yaml @@ -40,6 +40,7 @@ params: - name: unit advanced: true type: int + default: 1 description: de: Einheit en: Unit diff --git a/templates/definition/meter/fritzgrid.yaml b/templates/definition/meter/fritzgrid.yaml index 125ea2cbd..5f683e469 100644 --- a/templates/definition/meter/fritzgrid.yaml +++ b/templates/definition/meter/fritzgrid.yaml @@ -18,6 +18,7 @@ params: - name: unit advanced: true type: int + default: 1 description: de: Einheit en: Unit