mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Fix publish cancellation handling in MQTT (#120826)
This commit is contained in:
parent
25932dff28
commit
8f98fb2ec4
@ -1141,8 +1141,8 @@ class MQTT:
|
|||||||
# see https://github.com/eclipse/paho.mqtt.python/issues/687
|
# see https://github.com/eclipse/paho.mqtt.python/issues/687
|
||||||
# properties and reason codes are not used in Home Assistant
|
# properties and reason codes are not used in Home Assistant
|
||||||
future = self._async_get_mid_future(mid)
|
future = self._async_get_mid_future(mid)
|
||||||
if future.done() and future.exception():
|
if future.done() and (future.cancelled() or future.exception()):
|
||||||
# Timed out
|
# Timed out or cancelled
|
||||||
return
|
return
|
||||||
future.set_result(None)
|
future.set_result(None)
|
||||||
|
|
||||||
|
@ -1194,6 +1194,23 @@ async def test_handle_mqtt_on_callback(
|
|||||||
assert "No ACK from MQTT server" not in caplog.text
|
assert "No ACK from MQTT server" not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
async def test_handle_mqtt_on_callback_after_cancellation(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
|
mqtt_client_mock: MqttMockPahoClient,
|
||||||
|
) -> None:
|
||||||
|
"""Test receiving an ACK after a cancellation."""
|
||||||
|
mqtt_mock = await mqtt_mock_entry()
|
||||||
|
# Simulate the mid future getting a cancellation
|
||||||
|
mqtt_mock()._async_get_mid_future(101).cancel()
|
||||||
|
# Simulate an ACK for mid == 101, being received after the cancellation
|
||||||
|
mqtt_client_mock.on_publish(mqtt_client_mock, None, 101)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert "No ACK from MQTT server" not in caplog.text
|
||||||
|
assert "InvalidStateError" not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_handle_mqtt_on_callback_after_timeout(
|
async def test_handle_mqtt_on_callback_after_timeout(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user