mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 01:15:10 -06:00
add Timer service
This commit is contained in:
@@ -26,6 +26,7 @@ func BuildService[
|
||||
Scene |
|
||||
Script |
|
||||
TTS |
|
||||
Timer |
|
||||
Vacuum |
|
||||
ZWaveJS,
|
||||
](conn *ws.WebsocketWriter) *T {
|
||||
|
||||
69
internal/services/timer.go
Normal file
69
internal/services/timer.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "saml.dev/gome-assistant/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
type Timer struct {
|
||||
conn *ws.WebsocketWriter
|
||||
}
|
||||
|
||||
/* Public API */
|
||||
|
||||
// See https://www.home-assistant.io/integrations/timer/#action-timerstart
|
||||
func (t Timer) Start(entityId string, duration string) error {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "timer"
|
||||
req.Service = "start"
|
||||
req.ServiceData = map[string]any{
|
||||
"duration": duration,
|
||||
}
|
||||
|
||||
return t.conn.WriteMessage(req)
|
||||
}
|
||||
|
||||
// See https://www.home-assistant.io/integrations/timer/#action-timerstart
|
||||
func (t Timer) Change(entityId string, duration string) error {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "timer"
|
||||
req.Service = "change"
|
||||
req.ServiceData = map[string]any{
|
||||
"duration": duration,
|
||||
}
|
||||
|
||||
return t.conn.WriteMessage(req)
|
||||
}
|
||||
|
||||
// See https://www.home-assistant.io/integrations/timer/#action-timerpause
|
||||
func (t Timer) Pause(entityId string) error {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "timer"
|
||||
req.Service = "pause"
|
||||
return t.conn.WriteMessage(req)
|
||||
}
|
||||
|
||||
// See https://www.home-assistant.io/integrations/timer/#action-timercancel
|
||||
func (t Timer) Cancel() error {
|
||||
req := NewBaseServiceRequest("")
|
||||
req.Domain = "timer"
|
||||
req.Service = "cancel"
|
||||
return t.conn.WriteMessage(req)
|
||||
}
|
||||
|
||||
// See https://www.home-assistant.io/integrations/timer/#action-timerfinish
|
||||
func (t Timer) Finish(entityId string) error {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "timer"
|
||||
req.Service = "finish"
|
||||
return t.conn.WriteMessage(req)
|
||||
}
|
||||
|
||||
// See https://www.home-assistant.io/integrations/timer/#action-timerreload
|
||||
func (t Timer) Reload() error {
|
||||
req := NewBaseServiceRequest("")
|
||||
req.Domain = "timer"
|
||||
req.Service = "reload"
|
||||
return t.conn.WriteMessage(req)
|
||||
}
|
||||
@@ -25,6 +25,7 @@ type Service struct {
|
||||
Number *services.Number
|
||||
Scene *services.Scene
|
||||
Script *services.Script
|
||||
Timer *services.Timer
|
||||
TTS *services.TTS
|
||||
Vacuum *services.Vacuum
|
||||
ZWaveJS *services.ZWaveJS
|
||||
@@ -51,6 +52,7 @@ func newService(conn *ws.WebsocketWriter) *Service {
|
||||
Number: services.BuildService[services.Number](conn),
|
||||
Scene: services.BuildService[services.Scene](conn),
|
||||
Script: services.BuildService[services.Script](conn),
|
||||
Timer: services.BuildService[services.Timer](conn),
|
||||
TTS: services.BuildService[services.TTS](conn),
|
||||
Vacuum: services.BuildService[services.Vacuum](conn),
|
||||
ZWaveJS: services.BuildService[services.ZWaveJS](conn),
|
||||
|
||||
Reference in New Issue
Block a user