parent
85de9f6d5c
commit
64f800fdd0
|
@ -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 {
|
||||
|
|
|
@ -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"))
|
||||
|
|
Loading…
Reference in New Issue