mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-07 20:07:13 -06:00
design and impl BaseServiceRequest
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/saml-dev/gome-assistant/internal/http"
|
||||
ws "github.com/saml-dev/gome-assistant/internal/websocket"
|
||||
"nhooyr.io/websocket"
|
||||
)
|
||||
|
||||
@@ -13,6 +14,26 @@ type HomeAssistant struct {
|
||||
httpClient *http.HttpClient
|
||||
}
|
||||
|
||||
// TODO: design how much reuse I can get between request types. E.g.
|
||||
// only difference between light.turnon and homeassistant.turnon is
|
||||
// domain and extra data
|
||||
func (ha *HomeAssistant) TurnOn(entityId string) {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "homeassistant"
|
||||
req.Service = "turn_on"
|
||||
|
||||
ws.WriteMessage(req, ha.conn, ha.ctx)
|
||||
}
|
||||
|
||||
func (ha *HomeAssistant) TurnOff(entityId string) {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "homeassistant"
|
||||
req.Service = "turn_off"
|
||||
|
||||
ws.WriteMessage(req, ha.conn, ha.ctx)
|
||||
}
|
||||
|
||||
func (ha *HomeAssistant) Toggle(entityId string) {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "homeassistant"
|
||||
req.Service = "toggle"
|
||||
|
||||
ws.WriteMessage(req, ha.conn, ha.ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user