Fix mqtt subscribe debouncer initial delay too long when birth message is disabled (#92188)
Fix mqtt subscribe deboucer initial delay
This commit is contained in:
parent
f8f7de5d5a
commit
cff7829a8d
2 changed files with 16 additions and 0 deletions
|
@ -740,6 +740,9 @@ class MQTT:
|
||||||
asyncio.run_coroutine_threadsafe(
|
asyncio.run_coroutine_threadsafe(
|
||||||
publish_birth_message(birth_message), self.hass.loop
|
publish_birth_message(birth_message), self.hass.loop
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
# Update subscribe cooldown period to a shorter time
|
||||||
|
self._subscribe_debouncer.set_timeout(SUBSCRIBE_COOLDOWN)
|
||||||
|
|
||||||
async def _async_resubscribe(self) -> None:
|
async def _async_resubscribe(self) -> None:
|
||||||
"""Resubscribe on reconnect."""
|
"""Resubscribe on reconnect."""
|
||||||
|
|
|
@ -2062,6 +2062,19 @@ async def test_no_birth_message(
|
||||||
await asyncio.sleep(0.2)
|
await asyncio.sleep(0.2)
|
||||||
mqtt_client_mock.publish.assert_not_called()
|
mqtt_client_mock.publish.assert_not_called()
|
||||||
|
|
||||||
|
async def callback(msg: ReceiveMessage) -> None:
|
||||||
|
"""Handle birth message."""
|
||||||
|
|
||||||
|
# Assert the subscribe debouncer subscribes after
|
||||||
|
# about SUBSCRIBE_COOLDOWN (0.1) sec
|
||||||
|
# but sooner than INITIAL_SUBSCRIBE_COOLDOWN (1.0)
|
||||||
|
|
||||||
|
mqtt_client_mock.reset_mock()
|
||||||
|
await mqtt.async_subscribe(hass, "homeassistant/some-topic", callback)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
await asyncio.sleep(0.2)
|
||||||
|
mqtt_client_mock.subscribe.assert_called()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"mqtt_config_entry_data",
|
"mqtt_config_entry_data",
|
||||||
|
|
Loading…
Add table
Reference in a new issue