From 0211046343c4a61d8dadcf6d9ec5a06e6c09551a Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 16 Mar 2026 18:55:49 +0100 Subject: [PATCH] chore: minor --- util/homeassistant/connection.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/util/homeassistant/connection.go b/util/homeassistant/connection.go index eab98f023..c05e66811 100644 --- a/util/homeassistant/connection.go +++ b/util/homeassistant/connection.go @@ -273,22 +273,17 @@ func (c *Connection) GetPhaseFloatStates(entities []string) (float64, float64, f return 0, 0, 0, errors.New("invalid phase entities") } - var l1, l2, l3 float64 - var err error + var res [3]float64 - if l1, err = c.GetFloatState(entities[0]); err != nil { - return 0, 0, 0, fmt.Errorf("phase L1: %w", err) + for i := range res { + f, err := c.GetFloatState(entities[i]) + if err != nil { + return 0, 0, 0, fmt.Errorf("phase L%d: %w", i+1, err) + } + res[i] = f } - if l2, err = c.GetFloatState(entities[1]); err != nil { - return 0, 0, 0, fmt.Errorf("phase L2: %w", err) - } - - if l3, err = c.GetFloatState(entities[2]); err != nil { - return 0, 0, 0, fmt.Errorf("phase L3: %w", err) - } - - return l1, l2, l3, nil + return res[0], res[1], res[2], nil } // ValidatePhaseEntities validates that phase entity arrays contain 1 or 3 entities @@ -297,12 +292,13 @@ func ValidatePhaseEntities(phases []string) ([]string, error) { t := strings.TrimSpace(s) return t, t != "" }) + switch len(entities) { case 0: return nil, nil case 3: return entities, nil default: - return nil, fmt.Errorf("must contain three-phase entities (L1, L2, L3), got %d", len(entities)) + return nil, errors.New("invalid phase entities") } }