Address review: prefs helper requires the redirect, visible stamp rejection, lock aware age re-probe, wider marker regexes

This commit is contained in:
J. Nick Koston
2026-09-03 21:01:49 +02:00
parent 19f5641706
commit 36468022ea
3 changed files with 25 additions and 11 deletions
+7 -5
View File
@@ -1,7 +1,7 @@
"""Helpers for manipulating the host platform's preferences file.
ESPHome's host platform stores preferences in
``~/.esphome/prefs/<app_name>.prefs`` using a simple binary layout that
``$ESPHOME_PREFDIR/<app_name>.prefs`` using a simple binary layout that
mirrors ``HostPreferences::sync()``:
``[uint32_t key][uint8_t len][uint8_t data[len]]`` per entry.
@@ -19,11 +19,13 @@ import struct
def host_prefs_path(device_name: str) -> Path:
"""Return the on-disk prefs file path for a host-platform device.
Honors ESPHOME_PREFDIR, which the autouse isolated_preferences fixture
sets, so seeds land where the binary will look."""
Requires ESPHOME_PREFDIR, which the autouse isolated_preferences fixture
sets; refusing the ~/.esphome/prefs fallback keeps tests off real user
data if the fixture is ever bypassed."""
prefdir = os.environ.get("ESPHOME_PREFDIR")
base = Path(prefdir) if prefdir else Path.home() / ".esphome" / "prefs"
return base / f"{device_name}.prefs"
if not prefdir:
raise RuntimeError("ESPHOME_PREFDIR is not set; refusing the real prefs dir")
return Path(prefdir) / f"{device_name}.prefs"
def clear_host_prefs(device_name: str) -> None: