diff --git a/tests/components/sun/test_init.py b/tests/components/sun/test_init.py index 56ac683582a..36eaa8398ac 100644 --- a/tests/components/sun/test_init.py +++ b/tests/components/sun/test_init.py @@ -120,11 +120,12 @@ async def test_state_change(hass, legacy_patchable_time): assert sun.STATE_BELOW_HORIZON == hass.states.get(sun.ENTITY_ID).state - hass.bus.async_fire( - ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: test_time + timedelta(seconds=5)} - ) - - await hass.async_block_till_done() + patched_time = test_time + timedelta(seconds=5) + with patch( + "homeassistant.helpers.condition.dt_util.utcnow", return_value=patched_time + ): + hass.bus.async_fire(ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: patched_time}) + await hass.async_block_till_done() assert sun.STATE_ABOVE_HORIZON == hass.states.get(sun.ENTITY_ID).state