Distinguish not-yet-fetched stub reps from confirmed-empty ones (issue #127)
parse_device0_batch used to collapse /device/0's {"href": "..."} "no data
yet" marker into a plain {}, indistinguishable from a resource the device
had actually polled and confirmed empty. Every exists_fn using the "not
rep or ..." stub carve-out (and entity._is_included's default field-gate)
then treated both the same way, creating phantom always-"unknown" entities
for any resource a model simply doesn't support (e.g. GSzabados's fridge's
/energy/consumption/vs/0).
is_stub_rep() now recognizes only the literal {"href": ...} marker as a
stub; a genuine {} is treated as the device's real (if empty) answer and
gates the entity off like any other missing field. Updated the energy
meter, self-check error, cooktop burner, and range-hood auto-operation
exists_fn call sites, plus three golden fixtures that had baked the
phantom-entity behavior in as "expected".
This commit is contained in:
10 files changed
+129
-49
No files matched your search
@@ -253,13 +253,24 @@ class TestEnergyMeter:
|
||||
kwh = next(e for e in common.ENERGY_METER.entities if e.key == 'energy_kwh')
|
||||
assert kwh.exists_fn({'x.com.samsung.da.cumulativePower': '58900'}, {}) is True
|
||||
|
||||
def test_both_entities_included_on_empty_stub(self):
|
||||
"""An empty {} rep means the resource exists but data isn't fetched yet
|
||||
(see entity._is_included) -- include both so sub-polls populate them."""
|
||||
def test_both_entities_included_on_true_stub(self):
|
||||
"""A true stub -- /device/0's {"href": "..."} "not fetched yet"
|
||||
marker (see registry.batch.is_stub_rep) -- means the resource exists
|
||||
but data isn't fetched yet; include both so sub-polls populate them."""
|
||||
pw = next(e for e in common.ENERGY_METER.entities if e.key == 'power_watts')
|
||||
kwh = next(e for e in common.ENERGY_METER.entities if e.key == 'energy_kwh')
|
||||
assert pw.exists_fn({}, {}) is True
|
||||
assert kwh.exists_fn({}, {}) is True
|
||||
stub = {'href': '/energy/consumption/vs/0'}
|
||||
assert pw.exists_fn(stub, {}) is True
|
||||
assert kwh.exists_fn(stub, {}) is True
|
||||
|
||||
def test_both_entities_hidden_on_genuinely_empty_rep(self):
|
||||
"""A real {} rep (no 'href' key) is the device's confirmed -- if
|
||||
empty -- answer, not a stub, so a model that never populates this
|
||||
resource doesn't get a phantom always-"unknown" entity (issue #127)."""
|
||||
pw = next(e for e in common.ENERGY_METER.entities if e.key == 'power_watts')
|
||||
kwh = next(e for e in common.ENERGY_METER.entities if e.key == 'energy_kwh')
|
||||
assert pw.exists_fn({}, {}) is False
|
||||
assert kwh.exists_fn({}, {}) is False
|
||||
|
||||
def test_power_watts_hidden_when_field_absent_in_populated_rep(self):
|
||||
"""A populated rep that lacks instantaneousPower must not spawn a
|
||||
@@ -416,11 +427,17 @@ class TestSelfCheckError:
|
||||
desc = self._desc()
|
||||
assert desc.exists_fn({'x.com.samsung.da.status': 'Ready'}, {}) is False
|
||||
|
||||
def test_exists_for_empty_stub_rep(self):
|
||||
"""An empty {} rep is /device/0's not-yet-fetched-stub carve-out --
|
||||
must be included-for-now, same as ENERGY_METER's fields."""
|
||||
def test_exists_for_true_stub_rep(self):
|
||||
"""A true stub ({"href": "..."}) is /device/0's not-yet-fetched
|
||||
marker -- must be included-for-now, same as ENERGY_METER's fields."""
|
||||
desc = self._desc()
|
||||
assert desc.exists_fn({}, {}) is True
|
||||
assert desc.exists_fn({'href': '/selfcheck/vs/0'}, {}) is True
|
||||
|
||||
def test_hidden_for_genuinely_empty_rep(self):
|
||||
"""A real {} rep is the device's confirmed empty answer, not a stub --
|
||||
must NOT be force-included (issue #127's phantom-entity pattern)."""
|
||||
desc = self._desc()
|
||||
assert desc.exists_fn({}, {}) is False
|
||||
|
||||
def test_value_joins_list(self):
|
||||
desc = self._desc()
|
||||
|
||||
Reference in new issue
Block a user