Add support for Samsung room air conditioners (ARTIK051_PRAC-class), the first device whose core controls map onto a single Home Assistant `climate` entity rather than a scatter of switches/selects/numbers. - New `climate` platform + `ClimateDesc`: one composite entity that reads power, HVAC mode, current/target temperature, fan (wind) strength, swing (wind direction) and the convenient-mode preset across several OCF resources and writes back to each. On/off folds into HVACMode.OFF / TURN_ON/OFF; convenient mode folds into preset_mode. The entity binds one primary resource (/mode/vs/0) and reads its siblings from the coordinator snapshot, reusing the cross-resource read pattern from number/select. - New `airconditioner` capability module + by_type registry, routed via the `_PRAC_` modelNum token. Reuses common ALARMS/ENERGY_METER, fridge.FIRMWARE_UPDATE and dishwasher.DIAGNOSIS; air purify and auto clean as config switches; air dust filter status/usage as diagnostics (usage normalized to a percentage of rated capacity). - Climate-consumed and all-zero/ambiguous resources (temperature/wind, /sensors, /humidity) are declared as AC-scoped coverage so every href in the dump binds or is covered -- no coverage-gap repair. - Fan/swing modes map onto HA standard constants (auto-localized); the custom fan `turbo`, presets `quiet/smart/speed`, and the filter-status enum get translations in strings.json + translations/en.json. - Scrubbed fixture, golden, and tests: registry routing, zero unbound hrefs, the climate write contract, and filter-% normalization.
95 lines
3.6 KiB
Python
95 lines
3.6 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
GOLDEN = Path(__file__).parent / 'fixtures' / 'golden'
|
|
|
|
|
|
def _new_state_keys(name, resources):
|
|
from custom_components.localthings.registry.by_type import for_device, for_device_by_model
|
|
from custom_components.localthings.registry.discovery import discover
|
|
from custom_components.localthings.registry.adapter import flatten
|
|
otn = resources.get('/otninformation/vs/0', {})
|
|
one_ui = otn.get('swVersionInfo', {}).get('oneUiVersion', '')
|
|
info = resources.get('/information/vs/0', {})
|
|
reg = for_device(one_ui) if one_ui else None
|
|
if reg is None:
|
|
reg = for_device_by_model(
|
|
info.get('x.com.samsung.da.modelNum', ''),
|
|
info.get('x.com.samsung.da.description', ''),
|
|
)
|
|
if reg is None:
|
|
from custom_components.localthings.registry.registry import CAPABILITIES
|
|
caps, pats = CAPABILITIES, []
|
|
else:
|
|
caps, pats = reg.capabilities, reg.pattern_capabilities
|
|
bound = discover(resources, caps, pats)
|
|
state = flatten(bound, resources)
|
|
return sorted(state.keys())
|
|
|
|
|
|
@pytest.mark.parametrize('name,ip', [
|
|
('dishwasher', '10.0.0.129'),
|
|
('refrigerator', '10.0.0.254'),
|
|
])
|
|
def test_registry_reproduces_golden_state_keys(name, ip, request):
|
|
from tests.conftest import _load_resources
|
|
resources = _load_resources(ip)
|
|
golden = json.loads((GOLDEN / f'{name}.json').read_text())
|
|
state_keys = _new_state_keys(name, resources)
|
|
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))}"
|
|
)
|
|
|
|
|
|
def test_registry_reproduces_golden_state_keys_for_washer():
|
|
from tests.conftest import _load_device
|
|
resources = _load_device('washer')
|
|
golden = json.loads((GOLDEN / 'washer.json').read_text())
|
|
state_keys = _new_state_keys('washer', resources)
|
|
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))}"
|
|
)
|
|
|
|
|
|
def test_registry_reproduces_golden_state_keys_for_dryer():
|
|
from tests.conftest import _load_device
|
|
resources = _load_device('dryer')
|
|
golden = json.loads((GOLDEN / 'dryer.json').read_text())
|
|
state_keys = _new_state_keys('dryer', resources)
|
|
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))}"
|
|
)
|
|
|
|
|
|
def test_registry_reproduces_golden_state_keys_for_airconditioner():
|
|
from tests.conftest import _load_device
|
|
resources = _load_device('airconditioner')
|
|
golden = json.loads((GOLDEN / 'airconditioner.json').read_text())
|
|
state_keys = _new_state_keys('airconditioner', resources)
|
|
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))}"
|
|
)
|
|
|
|
|
|
def test_resources_from_batch_preferred_over_flat():
|
|
from tests.conftest import _resources_from_dump
|
|
dump = {
|
|
'device0': [
|
|
{'di': 'device'}, # [0] device-level rep, skipped
|
|
{'href': '/foo', 'rep': {'x': 1}},
|
|
],
|
|
'resources': {'/foo': {'x': 99}},
|
|
}
|
|
result = _resources_from_dump(dump)
|
|
assert result == {'/foo': {'x': 1}}
|