Remove every automatic timezone-setting mechanism (task 7f685179)
The application timezone is now only ever set by an admin saving it: - API: drop adopt_reported_timezone; the panel household clock reads the stored settings only and ignores any timezone request header. - Integration: stop reporting Home Assistant's time_zone in an X-NestQuest-Timezone header (snapshot, completion and SSE requests). - Admin app: remove the browser-zone detection and the automatic PATCH on load; the timezone field stays a manual control. - Remove the timezone_configured marker from the core settings, the settings store and the admin settings API. A stored document that still carries the key loads harmlessly (unknown keys are ignored). Tests replace the adoption expectations with proofs that a panel timezone header never changes the stored settings, a fresh install's empty zone stays empty with no settings write, the admin settings carry no timezone_configured, and a manual admin timezone PATCH persists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -114,24 +114,11 @@ CONF_CELEBRATION_ENABLED = "celebration_enabled"
|
||||
DEFAULT_AUTOMATION_ENABLED = True
|
||||
# The household's IANA time zone (e.g. ``America/New_York``) the API
|
||||
# service reads its clock in. The empty string is the API host's own
|
||||
# local time. While the admin has not chosen a zone
|
||||
# (``timezone_configured`` is ``False``) the API adopts the zone the
|
||||
# integration reports from Home Assistant's configured ``time_zone``
|
||||
# (:data:`PANEL_TIMEZONE_HEADER`), so the default is the household's
|
||||
# zone without any manual setup. The integration itself always uses
|
||||
# local time. Only an admin sets it (manually, from the admin app);
|
||||
# nothing sets it automatically. The integration itself always uses
|
||||
# Home Assistant's ``time_zone`` and ignores this field.
|
||||
CONF_TIMEZONE = "timezone"
|
||||
DEFAULT_TIMEZONE = ""
|
||||
# Whether the admin has made an explicit ``timezone`` choice. ``False``
|
||||
# (a fresh install) lets the API follow Home Assistant's reported zone
|
||||
# and the admin UI auto-set the browser's zone once while none is
|
||||
# stored; ``True`` pins the stored value — including an explicitly-chosen
|
||||
# empty ``timezone`` (the API host's local time) — so neither changes it.
|
||||
CONF_TIMEZONE_CONFIGURED = "timezone_configured"
|
||||
DEFAULT_TIMEZONE_CONFIGURED = False
|
||||
# The panel-plane request header carrying Home Assistant's configured
|
||||
# IANA ``time_zone`` from the integration to the API service.
|
||||
PANEL_TIMEZONE_HEADER = "X-NestQuest-Timezone"
|
||||
|
||||
# Panel-plane API client (Feature 18): the integration reaches the
|
||||
# NestQuest API service (Feature 16) over HTTP instead of the database.
|
||||
|
||||
@@ -49,7 +49,6 @@ from .const import (
|
||||
CONF_MORNING_SUMMARY_TIME,
|
||||
CONF_NOTIFY_TARGET,
|
||||
CONF_TIMEZONE,
|
||||
CONF_TIMEZONE_CONFIGURED,
|
||||
DEFAULT_AFTERNOON_REMINDER_TIME,
|
||||
DEFAULT_AUTOMATION_ENABLED,
|
||||
DEFAULT_DAY_ROLLOVER_TIME,
|
||||
@@ -57,7 +56,6 @@ from .const import (
|
||||
DEFAULT_HORIZON_DAYS,
|
||||
DEFAULT_MORNING_SUMMARY_TIME,
|
||||
DEFAULT_TIMEZONE,
|
||||
DEFAULT_TIMEZONE_CONFIGURED,
|
||||
LOGGER,
|
||||
TIME_PATTERN,
|
||||
)
|
||||
@@ -243,12 +241,6 @@ _FIELDS: tuple[tuple[str, str, Any, Callable[[Any], Any]], ...] = (
|
||||
_resolve_bool,
|
||||
),
|
||||
("timezone", CONF_TIMEZONE, DEFAULT_TIMEZONE, _resolve_timezone),
|
||||
(
|
||||
"timezone_configured",
|
||||
CONF_TIMEZONE_CONFIGURED,
|
||||
DEFAULT_TIMEZONE_CONFIGURED,
|
||||
_resolve_bool,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -279,10 +271,6 @@ class NestQuestSettings:
|
||||
end_of_day_report_enabled: bool = DEFAULT_AUTOMATION_ENABLED
|
||||
celebration_enabled: bool = DEFAULT_AUTOMATION_ENABLED
|
||||
timezone: str = DEFAULT_TIMEZONE
|
||||
#: ``True`` once the admin explicitly chose :attr:`timezone` (even
|
||||
#: the empty host-local value); ``False`` on a fresh install, where
|
||||
#: the admin UI may auto-set the browser's zone.
|
||||
timezone_configured: bool = DEFAULT_TIMEZONE_CONFIGURED
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
# Validate STRICTLY at construction so a hand-built instance
|
||||
@@ -315,7 +303,6 @@ class NestQuestSettings:
|
||||
"afternoon_reminder_enabled",
|
||||
"end_of_day_report_enabled",
|
||||
"celebration_enabled",
|
||||
"timezone_configured",
|
||||
):
|
||||
value = getattr(self, name)
|
||||
if not isinstance(value, bool):
|
||||
|
||||
@@ -33,12 +33,8 @@ after the first update:
|
||||
booleans,
|
||||
- ``timezone`` — ``""`` (the API host's local time) or an IANA time
|
||||
zone name such as ``America/New_York``. A document stored before
|
||||
this field existed simply lacks it and resolves to ``""``,
|
||||
- ``timezone_configured`` — a real boolean: ``True`` once the admin
|
||||
explicitly chose ``timezone`` (including the empty host-local value),
|
||||
so neither Home Assistant's reported zone
|
||||
(:func:`adopt_reported_timezone`) nor the admin UI changes it again. A document stored before
|
||||
this field existed lacks it and resolves to ``False``.
|
||||
this field existed simply lacks it and resolves to ``""``. Only an
|
||||
admin's explicit update ever writes it; nothing sets it automatically.
|
||||
|
||||
Only values whose core validators ACCEPTED are ever written, so a
|
||||
stored document always round-trips through the core's option builders.
|
||||
@@ -180,15 +176,10 @@ async def update_settings(
|
||||
update can never leave a half-applied document behind.
|
||||
|
||||
The validated changes are merged onto the current effective
|
||||
settings and the merged (complete, twelve-field) document is persisted
|
||||
settings and the merged (complete, eleven-field) document is persisted
|
||||
in one atomic upsert; the updated settings are returned. The whole
|
||||
read → merge → write span runs inside the per-database settings
|
||||
lock, so concurrent updates queue instead of interleaving.
|
||||
|
||||
Supplying ``timezone`` without ``timezone_configured`` records the
|
||||
zone as the admin's explicit choice (``timezone_configured`` is
|
||||
persisted ``True`` in the same write); an explicitly supplied
|
||||
``timezone_configured`` is kept exactly as given.
|
||||
"""
|
||||
if not isinstance(changes, Mapping):
|
||||
raise ValueError(
|
||||
@@ -204,37 +195,11 @@ async def update_settings(
|
||||
raise ValueError(
|
||||
f"unknown settings field(s): {listed}; known fields: {known}"
|
||||
)
|
||||
if "timezone" in changes and "timezone_configured" not in changes:
|
||||
# An admin-supplied zone is an explicit choice, so Home
|
||||
# Assistant's reported zone must no longer replace it.
|
||||
changes = {**changes, "timezone_configured": True}
|
||||
async with _settings_lock(database):
|
||||
current = await load_settings(database)
|
||||
return await _write_merged(database, current, changes)
|
||||
|
||||
|
||||
async def adopt_reported_timezone(
|
||||
database: NestQuestDatabase, zone: str
|
||||
) -> NestQuestSettings:
|
||||
"""Adopt Home Assistant's reported ``zone`` unless the admin chose one.
|
||||
|
||||
While ``timezone_configured`` is ``False`` the stored ``timezone``
|
||||
follows the zone the integration reports, so the API's clock is the
|
||||
household's without any manual setup; ``timezone_configured`` stays
|
||||
``False`` (the value is automatic, not an admin choice). Once the
|
||||
admin has chosen — including an explicitly-chosen empty zone — the
|
||||
stored settings are returned untouched. The check and the write
|
||||
share the settings lock, so a concurrent admin choice is never
|
||||
overwritten. An invalid ``zone`` raises a ``ValueError`` naming
|
||||
``timezone`` and writes nothing.
|
||||
"""
|
||||
async with _settings_lock(database):
|
||||
current = await load_settings(database)
|
||||
if current.timezone_configured or current.timezone == zone:
|
||||
return current
|
||||
return await _write_merged(database, current, {"timezone": zone})
|
||||
|
||||
|
||||
async def _write_merged(
|
||||
database: NestQuestDatabase,
|
||||
current: NestQuestSettings,
|
||||
|
||||
Reference in New Issue
Block a user