fix: drop unsupported local kwarg from async_track_time_change (NQ-080-001, NQ-080-002)

This commit is contained in:
2026-09-17 15:05:51 -04:00
parent 6231344520
commit 8bee1bbb41
3 changed files with 26 additions and 9 deletions
+8 -7
View File
@@ -248,7 +248,7 @@ class TimeChangeRegistry:
"""Models HA's time-change listener bookkeeping.
``track`` mirrors ``homeassistant.helpers.event.async_track_time_change``:
each call appends a record (action + hour/minute/second/local) and returns
each call appends a record (action + hour/minute/second) and returns
a remove callable that reverses the registration. Tests inspect
``registrations`` and exercise the newest action through :meth:`fire`.
"""
@@ -257,13 +257,12 @@ class TimeChangeRegistry:
self._hass = hass
self._registrations: list[dict] = []
def track(self, action, hour=None, minute=None, second=None, local=False):
def track(self, action, hour=None, minute=None, second=None):
record = {
"action": action,
"hour": hour,
"minute": minute,
"second": second,
"local": local,
}
def _remove():
@@ -290,17 +289,19 @@ class TimeChangeRegistry:
await result
def _async_track_time_change(hass, action, hour=None, minute=None, second=None, local=False):
def _async_track_time_change(hass, action, hour=None, minute=None, second=None):
"""Mirror homeassistant.helpers.event.async_track_time_change.
Routes to the registry attached to ``hass`` (created on demand), so
tests reach the registrations via ``hass.time_change``.
Exact HA 2024.6 signature — no ``local`` keyword: the local-time
wrapper is already this function. Routes to the registry attached to
``hass`` (created on demand), so tests reach the registrations via
``hass.time_change``.
"""
registry = getattr(hass, "time_change", None)
if registry is None:
registry = TimeChangeRegistry(hass)
hass.time_change = registry
return registry.track(action, hour=hour, minute=minute, second=second, local=local)
return registry.track(action, hour=hour, minute=minute, second=second)
_ha_mock("homeassistant.helpers.event").async_track_time_change = _async_track_time_change
+17 -1
View File
@@ -251,7 +251,6 @@ async def test_setup_registers_day_rollover_listener(hass, make_entry) -> None:
registration = hass.time_change.registrations[0]
assert registration["hour"] == 0
assert registration["minute"] == 0
assert registration["local"] is True
assert callable(entry.runtime_data.remove_time_change_listener)
@@ -322,6 +321,23 @@ async def test_day_rollover_listener_materializes_ha_local_horizon(
fake.assert_awaited_once_with(database, expected_start, expected_end)
def test_day_rollover_time_change_tracker_rejects_local_kwarg() -> None:
"""The fake async_track_time_change mirrors HA 2024.6 (no ``local`` kwarg).
Setup drives the local-time wrapper directly, so passing ``local=`` must
raise TypeError — otherwise a regression in the production call would be
silently masked by the fake.
"""
import inspect as _inspect
from homeassistant.helpers.event import async_track_time_change
params = _inspect.signature(async_track_time_change).parameters
assert list(params) == ["hass", "action", "hour", "minute", "second"]
with pytest.raises(TypeError):
async_track_time_change(None, lambda _now: None, hour=0, minute=0, local=True)
async def test_setup_applies_all_v1_tables(hass, make_entry) -> None:
"""Setup applies the full v1 DDL: all four v1 tables exist afterwards."""
entry = _wire(make_entry(), hass.registry)