Mqtt: fix clearing retained topics

This commit is contained in:
andig 2021-10-10 13:39:59 +02:00
parent f19c87b8ca
commit 1ba175bd5c
2 changed files with 3 additions and 3 deletions

View file

@ -124,7 +124,7 @@ func (m *Client) Listen(topic string, callback func(string)) {
func (m *Client) ListenSetter(topic string, callback func(string)) {
m.Listen(topic, func(payload string) {
callback(payload)
if err := m.Publish(topic, false, nil); err != nil {
if err := m.Publish(topic, true, ""); err != nil {
m.log.ERROR.Printf("clear: %v", err)
}
})

View file

@ -103,7 +103,7 @@ func (m *MQTT) Run(site site.API, in <-chan util.Param) {
m.publish(topic, true, "online")
// site setters
m.Handler.Listen(fmt.Sprintf("%s/site/prioritySoC/set", m.root), func(payload string) {
m.Handler.ListenSetter(fmt.Sprintf("%s/site/prioritySoC/set", m.root), func(payload string) {
soc, err := strconv.Atoi(payload)
if err == nil {
_ = site.SetPrioritySoC(float64(soc))
@ -128,7 +128,7 @@ func (m *MQTT) Run(site site.API, in <-chan util.Param) {
for id := range site.LoadPoints() {
topic := fmt.Sprintf("%s/loadpoints/%d", m.root, id+1)
for _, dep := range []string{"range", "socCharge", "vehicleSoc"} {
m.publish(fmt.Sprintf("%s/%s", topic, dep), true, nil)
m.publish(fmt.Sprintf("%s/%s", topic, dep), true, "")
}
}