mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-05 23:15:07 -06:00
94 lines
3.1 KiB
Go
94 lines
3.1 KiB
Go
package services
|
|
|
|
import (
|
|
"github.com/Xevion/go-ha/internal/connect"
|
|
)
|
|
|
|
type AlarmControlPanel struct {
|
|
conn *connect.HAConnection
|
|
}
|
|
|
|
// Send the alarm the command for arm away. Takes an entityId and an optional map that is translated into service_data.
|
|
func (acp AlarmControlPanel) ArmAway(entityId string, serviceData ...map[string]any) error {
|
|
req := NewBaseServiceRequest(entityId)
|
|
req.Domain = "alarm_control_panel"
|
|
req.Service = "alarm_arm_away"
|
|
if len(serviceData) != 0 {
|
|
req.ServiceData = serviceData[0]
|
|
}
|
|
|
|
return acp.conn.WriteMessage(req)
|
|
}
|
|
|
|
// Send the alarm the command for arm away. Takes an entityId and an optional map that is translated into service_data.
|
|
func (acp AlarmControlPanel) ArmWithCustomBypass(entityId string, serviceData ...map[string]any) error {
|
|
req := NewBaseServiceRequest(entityId)
|
|
req.Domain = "alarm_control_panel"
|
|
req.Service = "alarm_arm_custom_bypass"
|
|
if len(serviceData) != 0 {
|
|
req.ServiceData = serviceData[0]
|
|
}
|
|
|
|
return acp.conn.WriteMessage(req)
|
|
}
|
|
|
|
// Send the alarm the command for arm home. Takes an entityId and an optional map that is translated into service_data.
|
|
func (acp AlarmControlPanel) ArmHome(entityId string, serviceData ...map[string]any) error {
|
|
req := NewBaseServiceRequest(entityId)
|
|
req.Domain = "alarm_control_panel"
|
|
req.Service = "alarm_arm_home"
|
|
if len(serviceData) != 0 {
|
|
req.ServiceData = serviceData[0]
|
|
}
|
|
|
|
return acp.conn.WriteMessage(req)
|
|
}
|
|
|
|
// Send the alarm the command for arm night. Takes an entityId and an optional map that is translated into service_data.
|
|
func (acp AlarmControlPanel) ArmNight(entityId string, serviceData ...map[string]any) error {
|
|
req := NewBaseServiceRequest(entityId)
|
|
req.Domain = "alarm_control_panel"
|
|
req.Service = "alarm_arm_night"
|
|
if len(serviceData) != 0 {
|
|
req.ServiceData = serviceData[0]
|
|
}
|
|
|
|
return acp.conn.WriteMessage(req)
|
|
}
|
|
|
|
// Send the alarm the command for arm vacation. Takes an entityId and an optional map that is translated into service_data.
|
|
func (acp AlarmControlPanel) ArmVacation(entityId string, serviceData ...map[string]any) error {
|
|
req := NewBaseServiceRequest(entityId)
|
|
req.Domain = "alarm_control_panel"
|
|
req.Service = "alarm_arm_vacation"
|
|
if len(serviceData) != 0 {
|
|
req.ServiceData = serviceData[0]
|
|
}
|
|
|
|
return acp.conn.WriteMessage(req)
|
|
}
|
|
|
|
// Send the alarm the command for disarm. Takes an entityId and an optional map that is translated into service_data.
|
|
func (acp AlarmControlPanel) Disarm(entityId string, serviceData ...map[string]any) error {
|
|
req := NewBaseServiceRequest(entityId)
|
|
req.Domain = "alarm_control_panel"
|
|
req.Service = "alarm_disarm"
|
|
if len(serviceData) != 0 {
|
|
req.ServiceData = serviceData[0]
|
|
}
|
|
|
|
return acp.conn.WriteMessage(req)
|
|
}
|
|
|
|
// Send the alarm the command for trigger. Takes an entityId and an optional map that is translated into service_data.
|
|
func (acp AlarmControlPanel) Trigger(entityId string, serviceData ...map[string]any) error {
|
|
req := NewBaseServiceRequest(entityId)
|
|
req.Domain = "alarm_control_panel"
|
|
req.Service = "alarm_trigger"
|
|
if len(serviceData) != 0 {
|
|
req.ServiceData = serviceData[0]
|
|
}
|
|
|
|
return acp.conn.WriteMessage(req)
|
|
}
|