Added lots of services and fixed bug with ID for websocket calls

This commit is contained in:
Sam Lewis
2022-10-13 02:17:36 -04:00
parent 7f9e346d34
commit b99c1e5925
13 changed files with 379 additions and 59 deletions

43
internal/services/lock.go Normal file
View File

@@ -0,0 +1,43 @@
package services
import (
"context"
ws "github.com/saml-dev/gome-assistant/internal/websocket"
"nhooyr.io/websocket"
)
/* Structs */
type Lock struct {
conn *websocket.Conn
ctx context.Context
}
/* Public API */
// Lock a lock entity. Takes an entityId and an optional
// map that is translated into service_data.
func (l Lock) Lock(entityId string, serviceData ...map[string]any) {
req := NewBaseServiceRequest(entityId)
req.Domain = "lock"
req.Service = "lock"
if len(serviceData) != 0 {
req.ServiceData = serviceData[0]
}
ws.WriteMessage(req, l.conn, l.ctx)
}
// Unlock a lock entity. Takes an entityId and an optional
// map that is translated into service_data.
func (l Lock) Unlock(entityId string, serviceData ...map[string]any) {
req := NewBaseServiceRequest(entityId)
req.Domain = "lock"
req.Service = "unlock"
if len(serviceData) != 0 {
req.ServiceData = serviceData[0]
}
ws.WriteMessage(req, l.conn, l.ctx)
}