diff --git a/pkg/client/client.go b/pkg/client/client.go index 13fb8c4..554a8f7 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "strconv" "code.jhot.me/jhot/hats/internal/api" ha "code.jhot.me/jhot/hats/pkg/homeassistant" @@ -68,6 +69,17 @@ func (c *HatsClient) GetStateBool(entityId string) (bool, error) { return ha.StateToBool(stateString), nil } +func (c *HatsClient) GetStateFloat(entityId string) (float64, error) { + stateString, err := c.GetState(entityId) + + if err != nil { + return 0.0, err + } + + parsed, err := strconv.ParseFloat(stateString, 64) + return parsed, err +} + func (c *HatsClient) CallService(entityId string, service string, extras ...map[string]any) error { req := c.client.R() if len(extras) > 0 { diff --git a/pkg/config/config.go b/pkg/config/config.go index 4f36e38..2aadeb7 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -29,6 +29,8 @@ type HatsConfig struct { NtfyHost string NtfyToken string + + ConfigDir string } func FromEnvironment() *HatsConfig { @@ -50,6 +52,8 @@ func FromEnvironment() *HatsConfig { NtfyHost: util.GetEnvWithDefault("NTFY_HOST", "https://ntfy.sh"), NtfyToken: util.GetEnvWithDefault("NTFY_TOKEN", ""), + + ConfigDir: util.GetEnvWithDefault("CONFIG_DIR", "/config"), } config.HomeAssistantSecure, _ = strconv.ParseBool(util.GetEnvWithDefault("HASS_SECURE", "false"))