Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions homeassistant/helpers/update_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def __init__(
if entry := self.config_entry:
job_name += f" {entry.title} {entry.domain} {entry.entry_id}"
self._job = HassJob(
self._handle_refresh_interval,
self.__wrap_handle_refresh_interval,
job_name,
job_type=HassJobType.Coroutinefunction,
job_type=HassJobType.Callback,
)
self._unsub_refresh: CALLBACK_TYPE | None = None
self._unsub_shutdown: CALLBACK_TYPE | None = None
Expand Down Expand Up @@ -250,6 +250,11 @@ def _schedule_refresh(self) -> None:
next_refresh, hass.async_run_hass_job, self._job
).cancel

@callback
def __wrap_handle_refresh_interval(self) -> None:
"""Handle a refresh interval occurrence."""
self.hass.async_create_task(self._handle_refresh_interval(), eager_start=True)

async def _handle_refresh_interval(self, _now: datetime | None = None) -> None:
"""Handle a refresh interval occurrence."""
self._unsub_refresh = None
Expand Down
7 changes: 4 additions & 3 deletions tests/components/bmw_connected_drive/test_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ async def test_update_failed(
assert coordinator.last_update_success is True

freezer.tick(timedelta(minutes=5, seconds=1))
async_fire_time_changed(hass)

with patch(
"bimmer_connected.account.MyBMWAccount.get_vehicles",
side_effect=MyBMWAPIError("Test error"),
):
async_fire_time_changed(hass)
await hass.async_block_till_done()

assert coordinator.last_update_success is False
Expand All @@ -70,22 +71,22 @@ async def test_update_reauth(
assert coordinator.last_update_success is True

freezer.tick(timedelta(minutes=5, seconds=1))
async_fire_time_changed(hass)
with patch(
"bimmer_connected.account.MyBMWAccount.get_vehicles",
side_effect=MyBMWAuthError("Test error"),
):
async_fire_time_changed(hass)
await hass.async_block_till_done()

assert coordinator.last_update_success is False
assert isinstance(coordinator.last_exception, UpdateFailed) is True

freezer.tick(timedelta(minutes=5, seconds=1))
async_fire_time_changed(hass)
with patch(
"bimmer_connected.account.MyBMWAccount.get_vehicles",
side_effect=MyBMWAuthError("Test error"),
):
async_fire_time_changed(hass)
await hass.async_block_till_done()

assert coordinator.last_update_success is False
Expand Down
5 changes: 3 additions & 2 deletions tests/components/roborock/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def test_floorplan_image(
assert body is not None
# Call a third time - this time forcing it to update
now = dt_util.utcnow() + timedelta(seconds=91)
async_fire_time_changed(hass, now)

# Copy the device prop so we don't override it
prop = copy.deepcopy(PROP)
prop.status.in_cleaning = 1
Expand All @@ -40,6 +40,7 @@ async def test_floorplan_image(
), patch(
"homeassistant.components.roborock.image.dt_util.utcnow", return_value=now
):
async_fire_time_changed(hass, now)
await hass.async_block_till_done()
resp = await client.get("/api/image_proxy/image.roborock_s7_maxv_upstairs")
assert resp.status == HTTPStatus.OK
Expand All @@ -57,7 +58,6 @@ async def test_floorplan_image_failed_parse(
map_data = copy.deepcopy(MAP_DATA)
map_data.image = None
now = dt_util.utcnow() + timedelta(seconds=91)
async_fire_time_changed(hass, now)
# Copy the device prop so we don't override it
prop = copy.deepcopy(PROP)
prop.status.in_cleaning = 1
Expand All @@ -71,5 +71,6 @@ async def test_floorplan_image_failed_parse(
), patch(
"homeassistant.components.roborock.image.dt_util.utcnow", return_value=now
):
async_fire_time_changed(hass, now)
resp = await client.get("/api/image_proxy/image.roborock_s7_maxv_upstairs")
assert not resp.ok
1 change: 1 addition & 0 deletions tests/components/switcher_kis/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ async def test_update_fail(
async_fire_time_changed(
hass, dt_util.utcnow() + timedelta(seconds=MAX_UPDATE_INTERVAL_SEC - 1)
)
await hass.async_block_till_done()

for device in DUMMY_SWITCHER_DEVICES:
entity_id = f"switch.{slugify(device.name)}"
Expand Down