Added option to activate computer through mqtt
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
51958a0542
commit
d42afecd67
|
@ -42,4 +42,5 @@ func RegisterAutomations(client paho.Client, prefix string, hue *hue.Hue, notify
|
||||||
kettleAutomation(client, prefix, home)
|
kettleAutomation(client, prefix, home)
|
||||||
darknessAutomation(client, hue)
|
darknessAutomation(client, hue)
|
||||||
frontdoorAutomation(client, prefix, presence)
|
frontdoorAutomation(client, prefix, presence)
|
||||||
|
zeusAutomation(client, home)
|
||||||
}
|
}
|
||||||
|
|
23
automation/zeus.go
Normal file
23
automation/zeus.go
Normal file
|
@ -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)
|
||||||
|
})
|
||||||
|
}
|
|
@ -13,6 +13,10 @@ type OnOff interface {
|
||||||
GetOnOff() bool
|
GetOnOff() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Activate interface {
|
||||||
|
Activate(state bool)
|
||||||
|
}
|
||||||
|
|
||||||
func GetDevices[K any](devices *map[InternalName]Basic) map[InternalName]K {
|
func GetDevices[K any](devices *map[InternalName]Basic) map[InternalName]K {
|
||||||
devs := make(map[InternalName]K)
|
devs := make(map[InternalName]K)
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,17 @@ func NewComputer(macAddress string, name device.InternalName, url string) *compu
|
||||||
return c
|
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) {
|
func (c *computer) Activate(state bool) {
|
||||||
if state {
|
if state {
|
||||||
|
log.Printf("Starting %s\n", c.name)
|
||||||
_, err := http.Get(c.url)
|
_, err := http.Get(c.url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
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
|
// google.DeviceInterface
|
||||||
var _ google.DeviceInterface = (*computer)(nil)
|
var _ google.DeviceInterface = (*computer)(nil)
|
||||||
func (*computer) IsGoogleDevice() {}
|
func (*computer) IsGoogleDevice() {}
|
||||||
|
|
Reference in New Issue
Block a user