mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Refresh now() templates on second=0 (#42225)
This commit is contained in:
parent
4e917cf62c
commit
cb0c937b3e
@ -792,11 +792,13 @@ class _TrackTemplateResultInfo:
|
||||
|
||||
@callback
|
||||
def _setup_time_listener(self, template: Template, has_time: bool) -> None:
|
||||
if template in self._time_listeners:
|
||||
self._time_listeners.pop(template)()
|
||||
|
||||
# now() or utcnow() has left the scope of the template
|
||||
if not has_time:
|
||||
if template in self._time_listeners:
|
||||
# now() or utcnow() has left the scope of the template
|
||||
self._time_listeners.pop(template)()
|
||||
return
|
||||
|
||||
if template in self._time_listeners:
|
||||
return
|
||||
|
||||
track_templates = [
|
||||
@ -809,8 +811,8 @@ class _TrackTemplateResultInfo:
|
||||
def _refresh_from_time(now: datetime) -> None:
|
||||
self._refresh(None, track_templates=track_templates)
|
||||
|
||||
self._time_listeners[template] = async_call_later(
|
||||
self.hass, 60.45, _refresh_from_time
|
||||
self._time_listeners[template] = async_track_utc_time_change(
|
||||
self.hass, _refresh_from_time, second=0
|
||||
)
|
||||
|
||||
@callback
|
||||
|
@ -2172,15 +2172,17 @@ async def test_track_template_with_time_that_leaves_scope(hass):
|
||||
"time": True,
|
||||
}
|
||||
|
||||
# Verify we do not update a second time
|
||||
# if the state change happens
|
||||
# Verify we do not update before the minute rolls over
|
||||
callback_count_before_time_change = len(specific_runs)
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=59))
|
||||
test_time = dt_util.utcnow().replace(second=1)
|
||||
async_fire_time_changed(hass, test_time)
|
||||
await hass.async_block_till_done()
|
||||
async_fire_time_changed(hass, test_time + timedelta(seconds=58))
|
||||
await hass.async_block_till_done()
|
||||
assert len(specific_runs) == callback_count_before_time_change
|
||||
|
||||
# Verify we do update on the next time change
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=61))
|
||||
# Verify we do update on the next change of minute
|
||||
async_fire_time_changed(hass, test_time + timedelta(seconds=59))
|
||||
await hass.async_block_till_done()
|
||||
assert len(specific_runs) == callback_count_before_time_change + 1
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user