From 7dd626c80e1fc5d0c265b0d06f2fd57a5f3ac4cf Mon Sep 17 00:00:00 2001 From: Jordan Hotmann Date: Thu, 14 Dec 2023 06:27:22 -0700 Subject: [PATCH] ha fixes --- pkg/homeassistant/rest.go | 6 ++++-- pkg/homeassistant/thermostat.go | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/homeassistant/rest.go b/pkg/homeassistant/rest.go index cee83ff..3d80463 100644 --- a/pkg/homeassistant/rest.go +++ b/pkg/homeassistant/rest.go @@ -75,11 +75,13 @@ func (c *RestClient) CallServices(inputs ...*CallServiceInput) error { go func(input *CallServiceInput) { defer wg.Done() err := c.CallService(input.EntityID, input.Service, input.Extras) - errorChannel <- err + if err != nil { + errorChannel <- fmt.Errorf("error calling service %s for %s: %w", input.Service, input.EntityID, err) + } }(input) } - var returnErrors []error + returnErrors := []error{} for err := range errorChannel { returnErrors = append(returnErrors, err) } diff --git a/pkg/homeassistant/thermostat.go b/pkg/homeassistant/thermostat.go index 1b10154..f3e6422 100644 --- a/pkg/homeassistant/thermostat.go +++ b/pkg/homeassistant/thermostat.go @@ -69,9 +69,11 @@ func (c *RestClient) SetThermostatState(entityId string, desiredState Thermostat return c.CallService(entityId, Services.TurnOff) } - err := c.CallService(entityId, Services.TurnOn) - if err != nil { - return fmt.Errorf("error turning on thermostat: %w", err) + if state, _ := c.GetState(entityId); !StateToBool(state.State) { + err := c.CallService(entityId, Services.TurnOn) + if err != nil { + return fmt.Errorf("error turning on thermostat: %w", err) + } } extras := map[string]any{