Mqtt: fix error handling for tree cleanup

This commit is contained in:
andig 2024-03-04 11:22:39 +01:00
parent 0ece8c6e20
commit 83720c6f1a
2 changed files with 5 additions and 2 deletions

View file

@ -123,7 +123,7 @@ func (m *Client) ConnectionHandler(client paho.Client) {
// Cleanup recursively removes a topic
func (m *Client) Cleanup(topic string, retained bool) error {
if m.Client.Subscribe(topic, m.Qos, func(c paho.Client, msg paho.Message) {
if !m.Client.Subscribe(topic, m.Qos, func(c paho.Client, msg paho.Message) {
if len(msg.Payload()) == 0 {
return
}
@ -136,7 +136,7 @@ func (m *Client) Cleanup(topic string, retained bool) error {
time.Sleep(time.Second)
if m.Client.Unsubscribe(topic).WaitTimeout(request.Timeout) {
if !m.Client.Unsubscribe(topic).WaitTimeout(request.Timeout) {
return api.ErrTimeout
}

View file

@ -37,6 +37,9 @@ func NewMQTT(root string, site site.API) (*MQTT, error) {
if err == nil {
err = m.Listen(site)
}
if err != nil {
err = fmt.Errorf("mqtt: %w", err)
}
return m, err
}