mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 15:15:14 -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.
38 lines
681 B
Go
38 lines
681 B
Go
package services
|
|
|
|
import (
|
|
ws "saml.dev/gome-assistant/internal/websocket"
|
|
)
|
|
|
|
/* Structs */
|
|
|
|
type Switch struct {
|
|
conn *ws.WebsocketWriter
|
|
}
|
|
|
|
/* Public API */
|
|
|
|
func (s Switch) TurnOn(entityId string) error {
|
|
req := NewBaseServiceRequest(entityId)
|
|
req.Domain = "switch"
|
|
req.Service = "turn_on"
|
|
|
|
return s.conn.WriteMessage(req)
|
|
}
|
|
|
|
func (s Switch) Toggle(entityId string) error {
|
|
req := NewBaseServiceRequest(entityId)
|
|
req.Domain = "switch"
|
|
req.Service = "toggle"
|
|
|
|
return s.conn.WriteMessage(req)
|
|
}
|
|
|
|
func (s Switch) TurnOff(entityId string) error {
|
|
req := NewBaseServiceRequest(entityId)
|
|
req.Domain = "switch"
|
|
req.Service = "turn_off"
|
|
|
|
return s.conn.WriteMessage(req)
|
|
}
|