fix: drop unsupported local kwarg from async_track_time_change (NQ-080-001, NQ-080-002)
This commit is contained in:
@@ -298,7 +298,7 @@ def _register_day_rollover_listener(
|
|||||||
await _materialize_run(database, start_date, end_date)
|
await _materialize_run(database, start_date, end_date)
|
||||||
|
|
||||||
return async_track_time_change(
|
return async_track_time_change(
|
||||||
hass, _run_materialization, hour=hour, minute=minute, local=True
|
hass, _run_materialization, hour=hour, minute=minute
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+8
-7
@@ -248,7 +248,7 @@ class TimeChangeRegistry:
|
|||||||
"""Models HA's time-change listener bookkeeping.
|
"""Models HA's time-change listener bookkeeping.
|
||||||
|
|
||||||
``track`` mirrors ``homeassistant.helpers.event.async_track_time_change``:
|
``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
|
a remove callable that reverses the registration. Tests inspect
|
||||||
``registrations`` and exercise the newest action through :meth:`fire`.
|
``registrations`` and exercise the newest action through :meth:`fire`.
|
||||||
"""
|
"""
|
||||||
@@ -257,13 +257,12 @@ class TimeChangeRegistry:
|
|||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._registrations: list[dict] = []
|
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 = {
|
record = {
|
||||||
"action": action,
|
"action": action,
|
||||||
"hour": hour,
|
"hour": hour,
|
||||||
"minute": minute,
|
"minute": minute,
|
||||||
"second": second,
|
"second": second,
|
||||||
"local": local,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def _remove():
|
def _remove():
|
||||||
@@ -290,17 +289,19 @@ class TimeChangeRegistry:
|
|||||||
await result
|
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.
|
"""Mirror homeassistant.helpers.event.async_track_time_change.
|
||||||
|
|
||||||
Routes to the registry attached to ``hass`` (created on demand), so
|
Exact HA 2024.6 signature — no ``local`` keyword: the local-time
|
||||||
tests reach the registrations via ``hass.time_change``.
|
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)
|
registry = getattr(hass, "time_change", None)
|
||||||
if registry is None:
|
if registry is None:
|
||||||
registry = TimeChangeRegistry(hass)
|
registry = TimeChangeRegistry(hass)
|
||||||
hass.time_change = registry
|
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
|
_ha_mock("homeassistant.helpers.event").async_track_time_change = _async_track_time_change
|
||||||
|
|||||||
+17
-1
@@ -251,7 +251,6 @@ async def test_setup_registers_day_rollover_listener(hass, make_entry) -> None:
|
|||||||
registration = hass.time_change.registrations[0]
|
registration = hass.time_change.registrations[0]
|
||||||
assert registration["hour"] == 0
|
assert registration["hour"] == 0
|
||||||
assert registration["minute"] == 0
|
assert registration["minute"] == 0
|
||||||
assert registration["local"] is True
|
|
||||||
assert callable(entry.runtime_data.remove_time_change_listener)
|
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)
|
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:
|
async def test_setup_applies_all_v1_tables(hass, make_entry) -> None:
|
||||||
"""Setup applies the full v1 DDL: all four v1 tables exist afterwards."""
|
"""Setup applies the full v1 DDL: all four v1 tables exist afterwards."""
|
||||||
entry = _wire(make_entry(), hass.registry)
|
entry = _wire(make_entry(), hass.registry)
|
||||||
|
|||||||
Reference in New Issue
Block a user