Fix no will published when mqtt is down (#116319)

This commit is contained in:
Jan Bouwhuis 2024-04-28 01:42:38 +02:00 committed by GitHub
parent 50405fae5f
commit 43dc5415de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View file

@ -710,7 +710,8 @@ class MQTT:
async with self._connection_lock:
self._should_reconnect = False
self._async_cancel_reconnect()
self._mqttc.disconnect()
# We do not gracefully disconnect to ensure
# the broker publishes the will message
@callback
def async_restore_tracked_subscriptions(

View file

@ -141,17 +141,17 @@ async def test_mqtt_connects_on_home_assistant_mqtt_setup(
assert mqtt_client_mock.connect.call_count == 1
async def test_mqtt_disconnects_on_home_assistant_stop(
async def test_mqtt_does_not_disconnect_on_home_assistant_stop(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
mqtt_client_mock: MqttMockPahoClient,
) -> None:
"""Test if client stops on HA stop."""
"""Test if client is not disconnected on HA stop."""
await mqtt_mock_entry()
hass.bus.fire(EVENT_HOMEASSISTANT_STOP)
await hass.async_block_till_done()
await hass.async_block_till_done()
assert mqtt_client_mock.disconnect.call_count == 1
assert mqtt_client_mock.disconnect.call_count == 0
async def test_mqtt_await_ack_at_disconnect(