mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 01:15:10 -06:00
40 lines
891 B
Go
40 lines
891 B
Go
package services
|
|
|
|
import (
|
|
ws "github.com/Xevion/go-ha/internal/websocket"
|
|
)
|
|
|
|
/* Structs */
|
|
|
|
type Lock struct {
|
|
conn *ws.WebsocketWriter
|
|
}
|
|
|
|
/* 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) error {
|
|
req := NewBaseServiceRequest(entityId)
|
|
req.Domain = "lock"
|
|
req.Service = "lock"
|
|
if len(serviceData) != 0 {
|
|
req.ServiceData = serviceData[0]
|
|
}
|
|
|
|
return l.conn.WriteMessage(req)
|
|
}
|
|
|
|
// 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) error {
|
|
req := NewBaseServiceRequest(entityId)
|
|
req.Domain = "lock"
|
|
req.Service = "unlock"
|
|
if len(serviceData) != 0 {
|
|
req.ServiceData = serviceData[0]
|
|
}
|
|
|
|
return l.conn.WriteMessage(req)
|
|
}
|