Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@stackia
Copy link
Contributor

@stackia stackia commented Mar 27, 2024

I found the auto reconnect feature is totally broken on my G3. Here is a fix.


gateway = hass.data[DOMAIN][entry.entry_id]
gateway.stop()
await gateway.async_disconnect()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleans up the leftover thread (started by _mqttc.loop_start()) on entry unload.

Comment on lines -73 to -78
async def async_stop_mqtt(_event: Event):
"""Stop MQTT component."""
await hass.data[DOMAIN][entry.entry_id].async_disconnect()

hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_stop_mqtt)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary here because home assistant calls async_unload_entry when being stopped.

def on_disconnect(self, client, userdata, ret):
# pylint: disable=unused-argument
""" on disconnect to mqtt server """
self._mqttc.disconnect()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling _mqttc.disconnect() will cause the mqtt loop thread to exit which breaks the internal reconnecting mechanism of _mqttc.loop_start().

@niceboygithub niceboygithub merged commit e2cf211 into niceboygithub:master Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants