Keep entity._is_included's default gate permissive on confirmed-empty reps
Opus review of #149 caught that swapping is_stub_rep(rep) in for the default field-presence gate (not just the 9 hand-audited exists_fn call sites) was too broad: it silently excludes entities on ANY resource whose normal, valid state includes reporting {} -- /alarms/vs/0's {} is fridge.py's documented no-alarm state, not an absence signal, and it's not the only one (job_beginning_status, diagnosis_status, sabbath_mode, defrost_delay, ice_maker_enabled all lost entities on real fixtures under the broader change). That's the opposite of #127's fix: a real fridge would have dropped its alarm sensor on first-poll timing, not just its phantom energy sensors. Restored the default gate to include on either a stub or a genuinely-empty rep -- verified byte-identical to the pre-#149 baseline across all 40 fixtures, apart from the 9 deliberately-audited exists_fn sites (energy meter, self-check error, cooktop burner, range-hood auto-op), which are unaffected and still fix #127. Added tests/test_entity.py exercising _is_included directly (previously untested) and fixed two now-stale "not rep" doc references the review also flagged.
This commit is contained in:
4 files changed
+100
-9
No files matched your search
@@ -24,10 +24,15 @@ def _is_included(bound: BoundEntity, coordinator: 'LocalThingsCoordinator') -> b
|
||||
|
||||
A stub rep (is_stub_rep — /device/0's "resource exists, no data fetched
|
||||
yet" marker) is included anyway so it can be populated by sub-polls. A
|
||||
genuinely empty {} rep is the device's confirmed (if empty) answer, not
|
||||
a stub, and gates the entity off like any other missing field — else a
|
||||
resource this model never populates would spawn a phantom always-
|
||||
"unknown" entity every session (issue #127).
|
||||
genuinely empty {} rep is included too by this default gate -- whether
|
||||
empty means "not populated yet" or "permanently unsupported" needs
|
||||
per-field domain knowledge this generic gate doesn't have: /alarms/vs/0's
|
||||
{} is fridge.py's documented *normal* no-alarm state (see
|
||||
_active_alarm_codes), not an absence signal, and it's far from the only
|
||||
resource like that. Only a capability whose author has actually verified
|
||||
a field is genuinely never populated on unsupported hardware opts into
|
||||
stricter gating with its own is_stub_rep-based exists_fn (see
|
||||
common.ENERGY_METER, issue #127) -- this default stays permissive.
|
||||
"""
|
||||
rep = coordinator.last_resources.get(bound.href)
|
||||
if rep is None:
|
||||
@@ -35,7 +40,7 @@ def _is_included(bound: BoundEntity, coordinator: 'LocalThingsCoordinator') -> b
|
||||
if bound.desc.exists_fn is not None:
|
||||
return bound.desc.exists_fn(rep, coordinator.last_resources)
|
||||
if bound.desc.field:
|
||||
if is_stub_rep(rep):
|
||||
if not rep or is_stub_rep(rep):
|
||||
return True
|
||||
return bound.desc.field in rep
|
||||
return True # rep_fn or no-field entities (ButtonDesc) are always included
|
||||
|
||||
@@ -503,7 +503,7 @@ AI_ENERGY_LEVEL = Capability(
|
||||
href='/energy/ailevel/vs/0',
|
||||
poll_tier='cold',
|
||||
entities=(
|
||||
# No `not rep` stub carve-out on either side, unlike most exists_fn
|
||||
# No is_stub_rep carve-out on either side, unlike most exists_fn
|
||||
# gates in this file -- entity creation only ever runs once, against
|
||||
# whichever snapshot happens to be current the moment platforms are
|
||||
# set up (see entity._is_included / __init__.py's
|
||||
|
||||
Reference in new issue
Block a user