Convert from MQTT bridge architecture to a proper Home Assistant integration (custom_components/localthings/): - Config flow: IP-only entry, probes ports [49154,49155], cert/key reused from first device on subsequent adds - Coordinator: DataUpdateCoordinator wrapping blocking DTLS session via async_add_executor_job; discovery on first poll; dynamic 5s/30s interval based on active_when - Entity platforms: sensor, binary_sensor, switch, number, select - Library cleanup: delete bridge.py, main.py, config.py, logger.py, keepalive.py, poll_scheduler.py, sensors.py, state_cache.py - adapter.py stripped to flatten(), is_active(), _key() - _parse_device0_batch moved to samsung_appliance/batch.py
20 lines
722 B
Python
20 lines
722 B
Python
"""OCF /device/0 batch response parser."""
|
|
from __future__ import annotations
|
|
|
|
|
|
def parse_device0_batch(device0: list) -> dict[str, dict]:
|
|
"""Extract {href: rep} from a /device/0 CBOR list response."""
|
|
out = {}
|
|
for entry in device0[1:]: # skip [0] (device-level rep)
|
|
if not isinstance(entry, dict):
|
|
continue
|
|
href = entry.get('href')
|
|
rep = entry.get('rep')
|
|
if not href:
|
|
continue
|
|
# rep == {"href": "..."} is a stub (resource present, no current data).
|
|
# Include it as {} so capabilities still bind and the entity exists.
|
|
if isinstance(rep, dict):
|
|
out[href] = {} if set(rep.keys()) == {'href'} else rep
|
|
return out
|