diff --git a/automation/automation.go b/automation/automation.go index 363c830..cc734f6 100644 --- a/automation/automation.go +++ b/automation/automation.go @@ -42,4 +42,5 @@ func RegisterAutomations(client paho.Client, prefix string, hue *hue.Hue, notify kettleAutomation(client, prefix, home) darknessAutomation(client, hue) frontdoorAutomation(client, prefix, presence) + zeusAutomation(client, home) } diff --git a/automation/zeus.go b/automation/zeus.go new file mode 100644 index 0000000..3e5dac0 --- /dev/null +++ b/automation/zeus.go @@ -0,0 +1,23 @@ +package automation + +import ( + "automation/device" + "automation/home" + "fmt" + "log" + + paho "github.com/eclipse/paho.mqtt.golang" +) + +func zeusAutomation(client paho.Client, home *home.Home) { + const name = "living_room/zeus" + on(client, fmt.Sprintf("automation/appliance/%s", name), func(message struct{Activate bool `json:"activate"`}) { + computer, err := device.GetDevice[device.Activate](&home.Devices, name) + if err != nil { + log.Println(err) + return + } + + computer.Activate(message.Activate) + }) +} diff --git a/device/device.go b/device/device.go index 3a8f2bd..d0e2f03 100644 --- a/device/device.go +++ b/device/device.go @@ -13,6 +13,10 @@ type OnOff interface { GetOnOff() bool } +type Activate interface { + Activate(state bool) +} + func GetDevices[K any](devices *map[InternalName]Basic) map[InternalName]K { devs := make(map[InternalName]K) diff --git a/integration/wol/computer.go b/integration/wol/computer.go index 45d7636..a82011c 100644 --- a/integration/wol/computer.go +++ b/integration/wol/computer.go @@ -20,8 +20,17 @@ func NewComputer(macAddress string, name device.InternalName, url string) *compu return c } +// device.Basic +var _ device.Basic = (*computer)(nil) +func (c *computer) GetID() device.InternalName { + return device.InternalName(c.name) +} + +// device.Activate +var _ device.Activate = (*computer)(nil) func (c *computer) Activate(state bool) { if state { + log.Printf("Starting %s\n", c.name) _, err := http.Get(c.url) if err != nil { log.Println(err) @@ -31,12 +40,6 @@ func (c *computer) Activate(state bool) { } } -// device.Basic -var _ device.Basic = (*computer)(nil) -func (c *computer) GetID() device.InternalName { - return device.InternalName(c.name) -} - // google.DeviceInterface var _ google.DeviceInterface = (*computer)(nil) func (*computer) IsGoogleDevice() {}