Fix MQTT threading bug (#43667)

This commit is contained in:
Erik Montnemery 2020-11-26 22:33:58 +01:00 committed by GitHub
parent e1de36fda8
commit 8ff10ad3b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View file

@ -944,7 +944,7 @@ class MQTT:
)
birth_message = Message(**self.conf[CONF_BIRTH_MESSAGE])
self.hass.loop.create_task(publish_birth_message(birth_message))
self.hass.add_job(publish_birth_message(birth_message))
def _mqtt_on_message(self, _mqttc, _userdata, msg) -> None:
"""Message received callback."""

View file

@ -638,6 +638,7 @@ async def test_restore_subscriptions_on_reconnect(hass, mqtt_client_mock, mqtt_m
assert mqtt_client_mock.subscribe.call_count == 1
mqtt_mock._mqtt_on_disconnect(None, None, 0)
with patch("homeassistant.components.mqtt.DISCOVERY_COOLDOWN", 0):
mqtt_mock._mqtt_on_connect(None, None, None, 0)
await hass.async_block_till_done()
assert mqtt_client_mock.subscribe.call_count == 2
@ -671,6 +672,7 @@ async def test_restore_all_active_subscriptions_on_reconnect(
assert mqtt_client_mock.unsubscribe.call_count == 0
mqtt_mock._mqtt_on_disconnect(None, None, 0)
with patch("homeassistant.components.mqtt.DISCOVERY_COOLDOWN", 0):
mqtt_mock._mqtt_on_connect(None, None, None, 0)
await hass.async_block_till_done()