diff --git a/homeassistant/helpers/debounce.py b/homeassistant/helpers/debounce.py index 2fe42e19a67..773fff6ebc6 100644 --- a/homeassistant/helpers/debounce.py +++ b/homeassistant/helpers/debounce.py @@ -109,7 +109,7 @@ class Debouncer(Generic[_R_co]): assert self._job is not None try: - if task := self.hass.async_run_hass_job(self._job): + if task := self.hass.async_run_hass_job(self._job, eager_start=True): await task finally: self._schedule_timer() @@ -130,7 +130,7 @@ class Debouncer(Generic[_R_co]): return try: - if task := self.hass.async_run_hass_job(self._job): + if task := self.hass.async_run_hass_job(self._job, eager_start=True): await task except Exception: # pylint: disable=broad-except self.logger.exception("Unexpected exception from %s", self.function) diff --git a/tests/components/bluetooth/test_active_update_processor.py b/tests/components/bluetooth/test_active_update_processor.py index 13045048fc1..e894ef3dab4 100644 --- a/tests/components/bluetooth/test_active_update_processor.py +++ b/tests/components/bluetooth/test_active_update_processor.py @@ -330,7 +330,7 @@ async def test_second_poll_needed( inject_bluetooth_service_info(hass, GENERIC_BLUETOOTH_SERVICE_INFO_2) await hass.async_block_till_done() - assert async_handle_update.mock_calls[-1] == call({"testdata": 1}) + assert async_handle_update.mock_calls[1] == call({"testdata": 1}) cancel() diff --git a/tests/components/hue/test_light_v1.py b/tests/components/hue/test_light_v1.py index fc2163326bb..9a74d9cd994 100644 --- a/tests/components/hue/test_light_v1.py +++ b/tests/components/hue/test_light_v1.py @@ -413,6 +413,8 @@ async def test_group_removed(hass: HomeAssistant, mock_bridge_v1) -> None: await hass.services.async_call( "light", "turn_on", {"entity_id": "light.group_1"}, blocking=True ) + # Wait for the group to be updated + await hass.async_block_till_done() # 2x group update, 1x light update, 1 turn on request assert len(mock_bridge_v1.mock_requests) == 4 @@ -440,6 +442,8 @@ async def test_light_removed(hass: HomeAssistant, mock_bridge_v1) -> None: await hass.services.async_call( "light", "turn_on", {"entity_id": "light.hue_lamp_1"}, blocking=True ) + # Wait for the light to be updated + await hass.async_block_till_done() # 2x light update, 1 group update, 1 turn on request assert len(mock_bridge_v1.mock_requests) == 4 diff --git a/tests/components/shelly/test_config_flow.py b/tests/components/shelly/test_config_flow.py index 7ce111fdf21..c3c1fc36c2e 100644 --- a/tests/components/shelly/test_config_flow.py +++ b/tests/components/shelly/test_config_flow.py @@ -1,6 +1,7 @@ """Test the Shelly config flow.""" from dataclasses import replace +from datetime import timedelta from ipaddress import ip_address from typing import Any from unittest.mock import AsyncMock, Mock, patch @@ -21,13 +22,15 @@ from homeassistant.components.shelly.const import ( DOMAIN, BLEScannerMode, ) +from homeassistant.components.shelly.coordinator import ENTRY_RELOAD_COOLDOWN from homeassistant.config_entries import SOURCE_REAUTH from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component +from homeassistant.util import dt as dt_util from . import init_integration -from tests.common import MockConfigEntry +from tests.common import MockConfigEntry, async_fire_time_changed from tests.typing import WebSocketGenerator DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo( @@ -1030,6 +1033,9 @@ async def test_zeroconf_already_configured_triggers_refresh_mac_in_name( monkeypatch.setattr(mock_rpc_device, "connected", False) mock_rpc_device.mock_disconnected() + async_fire_time_changed( + hass, dt_util.utcnow() + timedelta(seconds=ENTRY_RELOAD_COOLDOWN) + ) await hass.async_block_till_done() assert len(mock_rpc_device.initialize.mock_calls) == 2 @@ -1062,6 +1068,9 @@ async def test_zeroconf_already_configured_triggers_refresh( monkeypatch.setattr(mock_rpc_device, "connected", False) mock_rpc_device.mock_disconnected() + async_fire_time_changed( + hass, dt_util.utcnow() + timedelta(seconds=ENTRY_RELOAD_COOLDOWN) + ) await hass.async_block_till_done() assert len(mock_rpc_device.initialize.mock_calls) == 2 @@ -1100,6 +1109,9 @@ async def test_zeroconf_sleeping_device_not_triggers_refresh( monkeypatch.setattr(mock_rpc_device, "connected", False) mock_rpc_device.mock_disconnected() + async_fire_time_changed( + hass, dt_util.utcnow() + timedelta(seconds=ENTRY_RELOAD_COOLDOWN) + ) await hass.async_block_till_done() assert len(mock_rpc_device.initialize.mock_calls) == 0 assert "device did not update" not in caplog.text