mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 05:15:15 -06:00
refactor: rename files into common naming, rename GetId to NextId, document function
This commit is contained in:
43
internal/services/home_assistant.go
Normal file
43
internal/services/home_assistant.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
)
|
||||
|
||||
type HomeAssistant struct {
|
||||
conn *ws.WebsocketWriter
|
||||
}
|
||||
|
||||
// TurnOn a Home Assistant entity. Takes an entityId and an optional
|
||||
// map that is translated into service_data.
|
||||
func (ha *HomeAssistant) TurnOn(entityId string, serviceData ...map[string]any) error {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "homeassistant"
|
||||
req.Service = "turn_on"
|
||||
if len(serviceData) != 0 {
|
||||
req.ServiceData = serviceData[0]
|
||||
}
|
||||
|
||||
return ha.conn.WriteMessage(req)
|
||||
}
|
||||
|
||||
// Toggle a Home Assistant entity. Takes an entityId and an optional
|
||||
// map that is translated into service_data.
|
||||
func (ha *HomeAssistant) Toggle(entityId string, serviceData ...map[string]any) error {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "homeassistant"
|
||||
req.Service = "toggle"
|
||||
if len(serviceData) != 0 {
|
||||
req.ServiceData = serviceData[0]
|
||||
}
|
||||
|
||||
return ha.conn.WriteMessage(req)
|
||||
}
|
||||
|
||||
func (ha *HomeAssistant) TurnOff(entityId string) error {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "homeassistant"
|
||||
req.Service = "turn_off"
|
||||
|
||||
return ha.conn.WriteMessage(req)
|
||||
}
|
||||
Reference in New Issue
Block a user