mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-05 23:15:07 -06:00
40 lines
886 B
Go
40 lines
886 B
Go
package services
|
|
|
|
import (
|
|
ws "github.com/Xevion/go-ha/internal/connect"
|
|
)
|
|
|
|
/* Structs */
|
|
|
|
type Lock struct {
|
|
conn *ws.HAConnection
|
|
}
|
|
|
|
/* 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)
|
|
}
|