1
0
Fork 0

Get state with default

main v0.4.0
Jordan Hotmann 2023-10-16 15:20:08 -06:00
parent e86eee3984
commit 35c7a5c0e5
No known key found for this signature in database
GPG Key ID: 01B504170C2A2EA3
2 changed files with 26 additions and 16 deletions

View File

@ -46,6 +46,14 @@ func (c *HatsClient) GetState(entityId string) (string, error) {
return resp.String(), nil
}
func (c *HatsClient) GetStateWithDefault(entityId string, defaultValue string) string {
state, err := c.GetState(entityId)
if err != nil {
return defaultValue
}
return state
}
func (c *HatsClient) GetStateBool(entityId string) (bool, error) {
stateString, err := c.GetState(entityId)

View File

@ -38,23 +38,25 @@ var Domains = struct {
// Home Assistant services
var Services = struct {
TurnOn string
TurnOff string
Toggle string
Reload string
Lock string
Unlock string
OpenCover string
CloseCover string
TurnOn string
TurnOff string
Toggle string
Reload string
Lock string
Unlock string
OpenCover string
CloseCover string
SelectOption string
}{
TurnOn: "turn_on",
TurnOff: "turn_off",
Toggle: "toggle",
Reload: "reload",
Lock: "lock",
Unlock: "unlock",
OpenCover: "open_cover",
CloseCover: "close_cover",
TurnOn: "turn_on",
TurnOff: "turn_off",
Toggle: "toggle",
Reload: "reload",
Lock: "lock",
Unlock: "unlock",
OpenCover: "open_cover",
CloseCover: "close_cover",
SelectOption: "select_option",
}
// Extra props that can be sent when calling a Home Assistant service