Skip to content

Commit

Permalink
device announce feature
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsgrill committed Aug 16, 2022
1 parent 5d4de84 commit 00276b0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions announce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package hass

import (
"encoding/json"

mqtt "github.com/eclipse/paho.mqtt.golang"
)

// <discovery_prefix>/<component>/[<node_id>/]<object_id>/config
func AnnounceDevice(client mqtt.Client, prefix string, nodeid string, objectid string, device IConfig) error {
c, err := json.Marshal(device)
if err != nil {
return err
}
topic := prefix + "/" + device.GetComponent() + "/" + nodeid + "/" + objectid + "/config"
client.Publish(topic, 0, true, c)
return nil
}

0 comments on commit 00276b0

Please sign in to comment.