parent
85de9f6d5c
commit
64f800fdd0
|
@ -2,6 +2,7 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"code.jhot.me/jhot/hats/internal/api"
|
"code.jhot.me/jhot/hats/internal/api"
|
||||||
ha "code.jhot.me/jhot/hats/pkg/homeassistant"
|
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
|
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 {
|
func (c *HatsClient) CallService(entityId string, service string, extras ...map[string]any) error {
|
||||||
req := c.client.R()
|
req := c.client.R()
|
||||||
if len(extras) > 0 {
|
if len(extras) > 0 {
|
||||||
|
|
|
@ -29,6 +29,8 @@ type HatsConfig struct {
|
||||||
|
|
||||||
NtfyHost string
|
NtfyHost string
|
||||||
NtfyToken string
|
NtfyToken string
|
||||||
|
|
||||||
|
ConfigDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromEnvironment() *HatsConfig {
|
func FromEnvironment() *HatsConfig {
|
||||||
|
@ -50,6 +52,8 @@ func FromEnvironment() *HatsConfig {
|
||||||
|
|
||||||
NtfyHost: util.GetEnvWithDefault("NTFY_HOST", "https://ntfy.sh"),
|
NtfyHost: util.GetEnvWithDefault("NTFY_HOST", "https://ntfy.sh"),
|
||||||
NtfyToken: util.GetEnvWithDefault("NTFY_TOKEN", ""),
|
NtfyToken: util.GetEnvWithDefault("NTFY_TOKEN", ""),
|
||||||
|
|
||||||
|
ConfigDir: util.GetEnvWithDefault("CONFIG_DIR", "/config"),
|
||||||
}
|
}
|
||||||
|
|
||||||
config.HomeAssistantSecure, _ = strconv.ParseBool(util.GetEnvWithDefault("HASS_SECURE", "false"))
|
config.HomeAssistantSecure, _ = strconv.ParseBool(util.GetEnvWithDefault("HASS_SECURE", "false"))
|
||||||
|
|
Loading…
Reference in New Issue