mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 09:15:12 -06:00
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.
47 lines
1.1 KiB
Go
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)
|
|
}
|