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 Paulus Schoutsen
parent abf45a0e0c
commit bfcffb5cb1
2 changed files with 5 additions and 4 deletions

View File

@ -711,7 +711,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(