Files
go-ha/internal/services/light.go
Matthias Loibl 02b6c413f1 Return Service errors
Additionally, removed the context that gets passed into the Services but isn't used in one of them. The websockets APIs also don't have any use for context.
2025-01-17 17:50:06 +01:00

47 lines
1.1 KiB
Go

package services
import (
ws "saml.dev/gome-assistant/internal/websocket"
)
/* Structs */
type Light struct {
conn *ws.WebsocketWriter
}
/* Public API */
// TurnOn a light entity. Takes an entityId and an optional
// map that is translated into service_data.
func (l Light) TurnOn(entityId string, serviceData ...map[string]any) error {
req := NewBaseServiceRequest(entityId)
req.Domain = "light"
req.Service = "turn_on"
if len(serviceData) != 0 {
req.ServiceData = serviceData[0]
}
return l.conn.WriteMessage(req)
}
// Toggle a light entity. Takes an entityId and an optional
// map that is translated into service_data.
func (l Light) Toggle(entityId string, serviceData ...map[string]any) error {
req := NewBaseServiceRequest(entityId)
req.Domain = "light"
req.Service = "toggle"
if len(serviceData) != 0 {
req.ServiceData = serviceData[0]
}
return l.conn.WriteMessage(req)
}
func (l Light) TurnOff(entityId string) error {
req := NewBaseServiceRequest(entityId)
req.Domain = "light"
req.Service = "turn_off"
return l.conn.WriteMessage(req)
}