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

Cleaning the MQTT API

parent 29292853
No related branches found
No related tags found
No related merge requests found
......@@ -69,19 +69,7 @@ func (zDev *Z2MDevice) GetTopic() string {
return mqttTopic + "/" + zDev.FriendlyName
}
func (zDev *Z2MDevice) SetTopic() string {
return zDev.GetTopic() + "/set"
}
func (zDev *Z2MDevice) Set(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("SEND Error", ":", token.Error())
}
}
// Publish the payload to the right topic
func (zDev *Z2MDevice) Publish(topic string, payload interface{}) {
topic = zDev.GetTopic() + "/" + topic
slog.Debug("Sending", "topic", topic, "payload", payload)
......@@ -91,6 +79,11 @@ func (zDev *Z2MDevice) Publish(topic string, payload interface{}) {
}
}
// Publish the device wanted state
func (zDev *Z2MDevice) Set(payload interface{}) {
zDev.Publish("set", payload)
}
// Check if the device is available, Z2M will send an availability message
// if this enable in Z2M config
func (zDev *Z2MDevice) Available() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment