Fix MQTT threading bug (#43667)
This commit is contained in:
parent
e1de36fda8
commit
8ff10ad3b8
2 changed files with 7 additions and 5 deletions
|
@ -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."""
|
||||
|
|
|
@ -638,8 +638,9 @@ 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)
|
||||
mqtt_mock._mqtt_on_connect(None, None, None, 0)
|
||||
await hass.async_block_till_done()
|
||||
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,8 +672,9 @@ 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)
|
||||
mqtt_mock._mqtt_on_connect(None, None, None, 0)
|
||||
await hass.async_block_till_done()
|
||||
with patch("homeassistant.components.mqtt.DISCOVERY_COOLDOWN", 0):
|
||||
mqtt_mock._mqtt_on_connect(None, None, None, 0)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
expected.append(call("test/state", 1))
|
||||
assert mqtt_client_mock.subscribe.mock_calls == expected
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue