Fix no will published when mqtt is down (#116319)
This commit is contained in:
parent
50405fae5f
commit
43dc5415de
2 changed files with 5 additions and 4 deletions
|
@ -710,7 +710,8 @@ class MQTT:
|
||||||
async with self._connection_lock:
|
async with self._connection_lock:
|
||||||
self._should_reconnect = False
|
self._should_reconnect = False
|
||||||
self._async_cancel_reconnect()
|
self._async_cancel_reconnect()
|
||||||
self._mqttc.disconnect()
|
# We do not gracefully disconnect to ensure
|
||||||
|
# the broker publishes the will message
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_restore_tracked_subscriptions(
|
def async_restore_tracked_subscriptions(
|
||||||
|
|
|
@ -141,17 +141,17 @@ async def test_mqtt_connects_on_home_assistant_mqtt_setup(
|
||||||
assert mqtt_client_mock.connect.call_count == 1
|
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,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
mqtt_client_mock: MqttMockPahoClient,
|
mqtt_client_mock: MqttMockPahoClient,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test if client stops on HA stop."""
|
"""Test if client is not disconnected on HA stop."""
|
||||||
await mqtt_mock_entry()
|
await mqtt_mock_entry()
|
||||||
hass.bus.fire(EVENT_HOMEASSISTANT_STOP)
|
hass.bus.fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
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(
|
async def test_mqtt_await_ack_at_disconnect(
|
||||||
|
|
Loading…
Add table
Reference in a new issue