fix(subdevices): don't materialize a slot whose only live state is a meter
Issue #214: a single-split ARTIK051_KRAC_18K showed up in HA as two air conditioners. Its /device/1 answers the same unused-slot shape the Pattern A reporter's /device/2 does -- every operational rep empty {} -- but also reports a populated /energy/consumption/vs/1. Running discovery against the reporter's own quoted subdevice block reproduces their diagnostics exactly (21 bound entities, the same six hrefs), and of those 21 the only primary entity with a non-None value is energy_kwh: a lifetime kWh total was the sole thing passing discover_partitioned's liveness gate and materializing the phantom. A single-split AC has one compressor and one energy meter, so a whole-appliance running total appearing under a second index is the appliance's own bookkeeping, not evidence that hardware is installed at that slot. Exclude cumulative meters (HA's total/total_increasing state classes, plus the energy/water/gas device classes for the descriptors that deliberately declare no state class) from the gate. The gate never applies to MAIN, and across the whole fixture corpus every device has at least one non-meter live primary, so no existing device's entities change -- verified by the golden for the new fixture being identical to the plain KRAC one. Also implement async_remove_config_entry_device. A subdevice's HA device outlives the discovery that created it, so a phantom materialized by an earlier release stays in the registry with no way to delete it from the UI -- which is the state the second reporter on that issue is in, with a refrigerator whose diagnostics now report no subdevices at all. Devices the entry currently provides still refuse removal. No automatic pruning: enumeration is one-shot and a real sibling can miss a poll (issue #205 on the reference hardware), so auto-removal would discard a live subdevice's name, area and automations on a transient miss. The new fixture's /device/1 seed is the reporter's verbatim capture; its master half comes from the corpus's other KRAC unit, with the deviations spelled out in seeds_note. Claude-Session: https://claude.ai/code/session_01HzUMLnSWBT64o4BQkVEzXp
This commit is contained in:
9 files changed
+750
-22
No files matched your search
@@ -662,6 +662,79 @@ def test_discover_partitioned_materializes_candidate_with_live_primary_entity():
|
||||
assert hrefs == {'/mode/vs/1', '/alarms/vs/1'}
|
||||
|
||||
|
||||
def test_discover_partitioned_skips_candidate_whose_only_live_primary_is_a_meter():
|
||||
"""A cumulative meter doesn't count as evidence either (issue #214) --
|
||||
the reporter's non-composite ARTIK051_KRAC_18K answers /device/1 with
|
||||
every operational rep empty {} plus a populated /energy/consumption/vs/1,
|
||||
and that lifetime kWh total was enough to materialize a phantom second
|
||||
air conditioner. It's the appliance's own counter, not proof a second
|
||||
indoor unit is installed at that slot."""
|
||||
energy_cap = Capability(
|
||||
href='/energy/consumption/vs/0',
|
||||
entities=(SensorDesc(key='energy_kwh', field='kwh',
|
||||
device_class='energy',
|
||||
state_class='total_increasing'),), # primary, but a meter
|
||||
)
|
||||
climate_cap = Capability(
|
||||
href='/mode/vs/0',
|
||||
entities=(BinarySensorDesc(key='mode', field='m'),),
|
||||
)
|
||||
reg = _FakeRegistry(
|
||||
'airconditioner',
|
||||
{'/energy/consumption/vs/0': [energy_cap], '/mode/vs/0': [climate_cap]},
|
||||
)
|
||||
unit1 = _indexed('1')
|
||||
resources = {
|
||||
'/energy/consumption/vs/0': {'kwh': 1175.2},
|
||||
'/mode/vs/0': {'m': 'Cool'},
|
||||
'/energy/consumption/vs/1': {'kwh': 1175.2}, # populated, but a meter
|
||||
'/mode/vs/1': {}, # the slot's real state: empty
|
||||
}
|
||||
|
||||
bound, _, materialized, skipped = discover_partitioned(
|
||||
resources, [unit1], lambda r: reg, fallback_capabilities={},
|
||||
)
|
||||
assert materialized == []
|
||||
assert [s.subdevice for s in skipped] == [unit1]
|
||||
assert all(b.subdevice != unit1 for b in bound)
|
||||
|
||||
|
||||
def test_discover_partitioned_meter_carve_out_does_not_gate_out_a_live_subdevice():
|
||||
"""The carve-out removes one *kind* of evidence, not the subdevice: a
|
||||
candidate reporting its own operational state alongside a meter still
|
||||
materializes, and still gets its meter entity once it does."""
|
||||
energy_cap = Capability(
|
||||
href='/energy/consumption/vs/0',
|
||||
entities=(SensorDesc(key='energy_kwh', field='kwh',
|
||||
device_class='energy',
|
||||
state_class='total_increasing'),),
|
||||
)
|
||||
climate_cap = Capability(
|
||||
href='/mode/vs/0',
|
||||
entities=(BinarySensorDesc(key='mode', field='m'),),
|
||||
)
|
||||
reg = _FakeRegistry(
|
||||
'airconditioner',
|
||||
{'/energy/consumption/vs/0': [energy_cap], '/mode/vs/0': [climate_cap]},
|
||||
)
|
||||
unit1 = _indexed('1')
|
||||
resources = {
|
||||
'/energy/consumption/vs/0': {'kwh': 1175.2},
|
||||
'/mode/vs/0': {'m': 'Auto'},
|
||||
'/energy/consumption/vs/1': {'kwh': 1175.2},
|
||||
'/mode/vs/1': {'m': 'Cool'}, # its own state -- this is what counts
|
||||
}
|
||||
|
||||
bound, _, materialized, skipped = discover_partitioned(
|
||||
resources, [unit1], lambda r: reg, fallback_capabilities={},
|
||||
)
|
||||
assert materialized == [unit1]
|
||||
assert skipped == []
|
||||
assert {b.href for b in bound if b.subdevice == unit1} == {
|
||||
'/mode/vs/1', '/energy/consumption/vs/1',
|
||||
}
|
||||
|
||||
|
||||
def test_discover_partitioned_skipped_candidate_contributes_no_hot_warm_hrefs():
|
||||
"""A skipped candidate's hrefs must not appear via tier_log either --
|
||||
'no entities, no hot/warm hrefs' (the skip is total, not just
|
||||
|
||||
Reference in new issue
Block a user