Skip to content
Snippets Groups Projects
Commit 65b331eb authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Z2MDevice.Send() now publish .. no-more publish in xaal.go ;)

parent f7b3ef59
No related branches found
No related tags found
No related merge requests found
......@@ -147,17 +147,14 @@ func (dev *PowerRelay) update(payload map[string]interface{}) {
power := dev.GetAttribute("power")
if value == "ON" {
power.SetValue(true)
} else {
} else if value == "OFF" {
power.SetValue(false)
}
}
func (dev *PowerRelay) setState(value string) {
// TODO: put this in Z2MDevice
topic := dev.Z2MDevice.SetTopic()
client := GetGW().client
body := `{"state": "` + value + `"}`
client.Publish(topic, 0, false, body)
dev.Z2MDevice.Send(body)
}
func (dev *PowerRelay) On(xaal.MessageBody) *xaal.MessageBody {
......@@ -198,11 +195,8 @@ func (dev *Lamp) update(payload map[string]interface{}) {
}
func (dev *Lamp) setState(value string) {
// TODO: put this in Z2MDevice
topic := dev.Z2MDevice.SetTopic()
client := GetGW().client
body := `{"state": "` + value + `"}`
client.Publish(topic, 0, false, body)
dev.Z2MDevice.Send(body)
}
func (dev *Lamp) On(xaal.MessageBody) *xaal.MessageBody {
......
......@@ -74,6 +74,15 @@ func (zDev *Z2MDevice) SetTopic() string {
return zDev.GetTopic() + "/set"
}
func (zDev *Z2MDevice) Send(payload interface{}) {
topic := zDev.SetTopic()
slog.Debug("Sending", "topic", topic, "payload", payload)
client := GetGW().client
if token := client.Publish(topic, 0, false, payload); token.Wait() && token.Error() != nil {
slog.Error("Error sending", ":", token.Error())
}
}
func (l AccessLevel) String() string {
return [...]string{"--", "R", "W", "RW", "Err", "RN", "Err", "RWN"}[l]
// return fmt.Sprintf("%d", l)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment