diff --git a/tests/components/tomorrowio/test_init.py b/tests/components/tomorrowio/test_init.py index 27372094092..2c0a882ff5a 100644 --- a/tests/components/tomorrowio/test_init.py +++ b/tests/components/tomorrowio/test_init.py @@ -66,26 +66,31 @@ async def test_update_intervals( version=1, ) config_entry.add_to_hass(hass) - assert await hass.config_entries.async_setup(config_entry.entry_id) - await hass.async_block_till_done() - assert len(tomorrowio_config_entry_update.call_args_list) == 1 + with patch("homeassistant.helpers.update_coordinator.utcnow", return_value=now): + assert await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + assert len(tomorrowio_config_entry_update.call_args_list) == 1 + tomorrowio_config_entry_update.reset_mock() # Before the update interval, no updates yet - async_fire_time_changed(hass, now + timedelta(minutes=30)) - await hass.async_block_till_done() - assert len(tomorrowio_config_entry_update.call_args_list) == 0 + future = now + timedelta(minutes=30) + with patch("homeassistant.helpers.update_coordinator.utcnow", return_value=future): + async_fire_time_changed(hass, future) + await hass.async_block_till_done() + assert len(tomorrowio_config_entry_update.call_args_list) == 0 - # On the update interval, we get a new update - async_fire_time_changed(hass, now + timedelta(minutes=32)) - await hass.async_block_till_done() - assert len(tomorrowio_config_entry_update.call_args_list) == 1 tomorrowio_config_entry_update.reset_mock() - with patch( - "homeassistant.helpers.update_coordinator.utcnow", - return_value=now + timedelta(minutes=32), - ): + # On the update interval, we get a new update + future = now + timedelta(minutes=32) + with patch("homeassistant.helpers.update_coordinator.utcnow", return_value=future): + async_fire_time_changed(hass, now + timedelta(minutes=32)) + await hass.async_block_till_done() + assert len(tomorrowio_config_entry_update.call_args_list) == 1 + + tomorrowio_config_entry_update.reset_mock() + # Adding a second config entry should cause the update interval to double config_entry_2 = MockConfigEntry( domain=DOMAIN, @@ -101,17 +106,26 @@ async def test_update_intervals( # We should get an immediate call once the new config entry is setup for a # partial update assert len(tomorrowio_config_entry_update.call_args_list) == 1 - tomorrowio_config_entry_update.reset_mock() + + tomorrowio_config_entry_update.reset_mock() # We should get no new calls on our old interval - async_fire_time_changed(hass, now + timedelta(minutes=64)) - await hass.async_block_till_done() - assert len(tomorrowio_config_entry_update.call_args_list) == 0 + future = now + timedelta(minutes=64) + with patch("homeassistant.helpers.update_coordinator.utcnow", return_value=future): + async_fire_time_changed(hass, future) + await hass.async_block_till_done() + assert len(tomorrowio_config_entry_update.call_args_list) == 0 + + tomorrowio_config_entry_update.reset_mock() # We should get two calls on our new interval, one for each entry - async_fire_time_changed(hass, now + timedelta(minutes=96)) - await hass.async_block_till_done() - assert len(tomorrowio_config_entry_update.call_args_list) == 2 + future = now + timedelta(minutes=96) + with patch("homeassistant.helpers.update_coordinator.utcnow", return_value=future): + async_fire_time_changed(hass, future) + await hass.async_block_till_done() + assert len(tomorrowio_config_entry_update.call_args_list) == 2 + + tomorrowio_config_entry_update.reset_mock() async def test_climacell_migration_logic(