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:
Marc Billow
2026-07-30 18:23:47 +00:00
parent 5f5aecbe7d
commit 5e86f147d4
9 changed files with 750 additions and 22 deletions
+25
View File
@@ -985,6 +985,31 @@ def test_registry_reproduces_golden_state_keys_for_airconditioner_fac_bora_205_f
)
def test_registry_reproduces_golden_state_keys_for_artik051_krac_18k_slot():
"""The issue #214 reporter's single-split AR12NXWXCWKNEU: a
non-composite ARTIK051_KRAC_18K whose `/device/1` answers a full-shaped
batch with every operational rep empty {} and a populated
/energy/consumption/vs/1. The lifetime kWh counter used to be enough to
pass discover_partitioned's liveness gate, materializing a phantom
second air conditioner in HA; a meter is now excluded from that gate
(subdevices._has_live_primary_entity), so this golden must stay
byte-identical to airconditioner_artik051_krac_18k.json -- master keys
only, no `subdevice1_` prefix anywhere -- which is what
test_krac_18k_energy_only_slot_is_not_materialized asserts structurally."""
name = 'airconditioner_artik051_krac_18k_slot'
golden = json.loads((GOLDEN / f'{name}.json').read_text())
state_keys = _new_subdevice_aware_state_keys(name)
assert set(state_keys) == set(golden['state_keys']), (
f"state_keys mismatch:\n"
f" extra: {sorted(set(state_keys) - set(golden['state_keys']))}\n"
f" missing: {sorted(set(golden['state_keys']) - set(state_keys))}"
)
master_golden = json.loads(
(GOLDEN / 'airconditioner_artik051_krac_18k.json').read_text()
)
assert set(state_keys) == set(master_golden['state_keys'])
def test_registry_reproduces_golden_state_keys_for_air_purifier_avt_ww():
"""AVT-WW-TP1-23-AXX500 (issue #190) -- next-gen BESPOKE Cube Air board;
reports device_type 'unknown' with empty oneUiVersion because 'VTWW' as a