mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 13:15:14 -06:00
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.
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
ws "saml.dev/gome-assistant/internal/websocket"
|
||||
)
|
||||
|
||||
@@ -10,13 +8,12 @@ import (
|
||||
|
||||
type Scene struct {
|
||||
conn *ws.WebsocketWriter
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
/* Public API */
|
||||
|
||||
// Apply a scene. Takes map that is translated into service_data.
|
||||
func (s Scene) Apply(serviceData ...map[string]any) {
|
||||
func (s Scene) Apply(serviceData ...map[string]any) error {
|
||||
req := NewBaseServiceRequest("")
|
||||
req.Domain = "scene"
|
||||
req.Service = "apply"
|
||||
@@ -24,12 +21,12 @@ func (s Scene) Apply(serviceData ...map[string]any) {
|
||||
req.ServiceData = serviceData[0]
|
||||
}
|
||||
|
||||
s.conn.WriteMessage(req, s.ctx)
|
||||
return s.conn.WriteMessage(req)
|
||||
}
|
||||
|
||||
// Create a scene entity. Takes an entityId and an optional
|
||||
// map that is translated into service_data.
|
||||
func (s Scene) Create(entityId string, serviceData ...map[string]any) {
|
||||
func (s Scene) Create(entityId string, serviceData ...map[string]any) error {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "scene"
|
||||
req.Service = "create"
|
||||
@@ -37,21 +34,21 @@ func (s Scene) Create(entityId string, serviceData ...map[string]any) {
|
||||
req.ServiceData = serviceData[0]
|
||||
}
|
||||
|
||||
s.conn.WriteMessage(req, s.ctx)
|
||||
return s.conn.WriteMessage(req)
|
||||
}
|
||||
|
||||
// Reload the scenes.
|
||||
func (s Scene) Reload() {
|
||||
func (s Scene) Reload() error {
|
||||
req := NewBaseServiceRequest("")
|
||||
req.Domain = "scene"
|
||||
req.Service = "reload"
|
||||
|
||||
s.conn.WriteMessage(req, s.ctx)
|
||||
return s.conn.WriteMessage(req)
|
||||
}
|
||||
|
||||
// TurnOn a scene entity. Takes an entityId and an optional
|
||||
// map that is translated into service_data.
|
||||
func (s Scene) TurnOn(entityId string, serviceData ...map[string]any) {
|
||||
func (s Scene) TurnOn(entityId string, serviceData ...map[string]any) error {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "scene"
|
||||
req.Service = "turn_on"
|
||||
@@ -59,5 +56,5 @@ func (s Scene) TurnOn(entityId string, serviceData ...map[string]any) {
|
||||
req.ServiceData = serviceData[0]
|
||||
}
|
||||
|
||||
s.conn.WriteMessage(req, s.ctx)
|
||||
return s.conn.WriteMessage(req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user