Squash-merge PR #251: fix appliance course labels and AC setup timeouts

- Add confirmed Samsung Table_02 washer course mappings (69-79, 88)
- Add confirmed dishwasher course mappings (82, 8a, a7, a8, 8c, 88)
- Localize new washer/dishwasher course labels in en, cs, nl
- Decode device-provided personal washer course names from TLV payloads
- Show unrecognized washer enum bytes as 'Unknown (0xNN)'
- Normalize select current-state and options through one display path
- Bound first-setup subdevice enumeration with a shared time budget

Co-authored-by: galaxysj <224385302+galaxysj@users.noreply.github.com>
This commit is contained in:
Marc Billowandgalaxysj committed 2026-08-08 21:17:43 +00:00
1 parent 55765fdf9a
commit 00db7890f5
19 files changed
+771 -49

No files matched your search

+48
View File
@@ -59,6 +59,54 @@ class TestCourseHelpers:
assert laundry.option_value(opts, "Course") == "1C"
assert laundry.option_value(opts, "Missing") is None
def test_decodes_device_provided_personal_course_names(self):
"""Real /wm/personalcourse/vs/0 entries from the reported washer.
The first TLV field contains a byte-counted UTF-8 name. It is the only
course-name metadata in the diagnostics and is safe to display without
assigning an inferred meaning to any standard course code.
"""
resources = {
'/wm/personalcourse/vs/0': {
'x.com.samsung.da.courses': [
'F1_0106EC868DEC98B7021EED8CACED8BB020EB93B1',
'F2_00',
'F3_0109EC9A94EAB8B0EBB3B40220ECA084EC9AA9',
],
},
}
first_name = bytes.fromhex('EC868DEC98B7').decode('utf-8')
second_name = bytes.fromhex('EC9A94EAB8B0EBB3B4').decode('utf-8')
assert laundry.personal_course_labels(resources) == {
'F1': first_name,
'F3': second_name,
}
def test_personal_course_names_reject_malformed_payloads(self):
resources = {
'/wm/personalcourse/vs/0': {
'x.com.samsung.da.courses': [
'F1_not-hex',
'F2_0106AA',
'F3_020141',
None,
],
},
}
assert laundry.personal_course_labels(resources) == {}
def test_washer_cycle_fallback_uses_labels_then_safe_unknown_text(self):
resources = {
'/wm/personalcourse/vs/0': {
'x.com.samsung.da.courses': ['F1_0106EC868DEC98B7'],
},
}
expected = bytes.fromhex('EC868DEC98B7').decode('utf-8')
assert laundry.washer_cycle_fallback('F1', resources) == expected
assert laundry.washer_cycle_fallback('69', resources) == 'Unknown (0x69)'
assert laundry.washer_cycle_fallback('6f', resources) == 'Unknown (0x6F)'
assert laundry.washer_cycle_fallback('Normal', resources) is None
class TestCourseCodesFromSupportedOptions:
"""cycle_options()'s fallback for boards that populate
+6
View File
@@ -46,3 +46,9 @@ def test_known_camel_case_state_uses_snake_case_translation_key():
def test_display_passes_through_non_string_values():
assert _display(None, _UNTRANSLATED) is None
def test_display_uses_fallback_when_translation_has_no_state_table():
assert _display('69', 'cycle', lambda value: f'Unknown (0x{value})') == (
'Unknown (0x69)'
)
+80
View File
@@ -6,6 +6,10 @@ and callable forms of SelectDesc.options.
from typing import ClassVar, cast
from custom_components.localthings.coordinator import LocalThingsCoordinator
from custom_components.localthings.registry.capabilities.laundry import (
cycle_select,
washer_cycle_fallback,
)
from custom_components.localthings.registry.capability import Capability
from custom_components.localthings.registry.discovery import BoundEntity
from custom_components.localthings.registry.entities import SelectDesc
@@ -113,3 +117,79 @@ async def test_unknown_vendor_option_round_trips_to_exact_raw_value():
assert entity.options[-1] == "Future Vendor Mode"
await entity.async_select_option("Future Vendor Mode")
assert coordinator.writes == ["FutureVendorMode"]
async def test_washer_diagnostic_cycle_values_share_one_display_and_write_path():
"""Regression for Course_69/EditCourseList_696F... from real hardware."""
class _WritableCoordinator(_FakeCoordinator):
data: ClassVar[dict] = {"cycle": "69"}
def __init__(self, last_resources):
super().__init__(last_resources)
self.writes = []
async def async_send_command(self, bound, value):
self.writes.append(value)
desc = cycle_select(
translation_key="washer_cycle",
icon="mdi:washing-machine",
table_href="/st/washercourse/vs/0",
display_fn=washer_cycle_fallback,
)
capability = Capability(href="/course/vs/0", entities=(desc,))
bound = BoundEntity(href="/course/vs/0", capability=capability, desc=desc)
resources = {
"/course/vs/0": {"x.com.samsung.da.options": ["Course_69"]},
"/st/washercourse/vs/0": {
"x.com.samsung.da.st.courseTable": "Table_02",
},
"/wm/editcourse/vs/0": {
"x.com.samsung.da.editCourseList": (
"EditCourseList_696F757801719688706D6A7376726C6E6B777479F1F3"
),
},
"/wm/personalcourse/vs/0": {
"x.com.samsung.da.courses": [
"F1_0106EC868DEC98B7",
"F3_0109EC9A94EAB8B0EBB3B4",
],
},
}
coordinator = _WritableCoordinator(resources)
entity = LocalThingsSelect(cast(LocalThingsCoordinator, coordinator), bound)
first_name = bytes.fromhex("EC868DEC98B7").decode("utf-8")
second_name = bytes.fromhex("EC9A94EAB8B0EBB3B4").decode("utf-8")
# Known catalog states stay as HA translation keys; the frontend renders
# this confirmed Table_02 mapping as "AI Wash".
assert entity.current_option == "69"
assert entity.options == [
"69",
"6f",
"75",
"78",
"01",
"71",
"96",
"88",
"70",
"6d",
"6a",
"73",
"76",
"72",
"6c",
"6e",
"6b",
"77",
"74",
"79",
first_name,
second_name,
]
await entity.async_select_option("6f")
await entity.async_select_option(first_name)
assert coordinator.writes == ["6F", "F1"]
+12
View File
@@ -277,6 +277,18 @@ async def test_fac_bora_2in1_unique_ids_include_subdevice_prefix(hass: HomeAssis
# capture instead of the synthetic sessions test_subdevices.py uses.
# ---------------------------------------------------------------------------
async def test_flat_probe_priority_puts_live_climate_state_before_cold_metrics(
hass: HomeAssistant,
):
"""Registry metadata drives fallback order without a model-specific list."""
resources, _oic_res, _seeds = _load_device_full("airconditioner_fac_bora_205_flat")
coordinator = _coordinator(hass)
priority = coordinator._subdevice_probe_priority(resources)
assert "/mode/vs/0" in priority[:4]
assert priority.index("/mode/vs/0") < priority.index("/energy/consumption/vs/0")
async def test_fac_bora_205_flat_fallback_finds_candidate_but_gate_holds_it_back(
hass: HomeAssistant,
+111
View File
@@ -10,6 +10,7 @@ from typing import cast
import cbor2
from custom_components.localthings.registry import subdevices as subdevices_module
from custom_components.localthings.registry.by_type import DeviceRegistry
from custom_components.localthings.registry.capability import Capability
from custom_components.localthings.registry.entities import BinarySensorDesc, SensorDesc
@@ -350,6 +351,116 @@ def test_enumerate_prefixed_flat_fallback_probe_log_reports_every_href_tried():
assert probes[f"/{_UUID}/mode/vs/0"] is True
def test_enumeration_budget_bounds_silent_prefixed_fallback_and_uses_priority(
monkeypatch,
):
"""A firmware that drops unknown prefixed paths cannot stall setup.
The Collection probe gets the larger blockwise allowance. The preferred
live-state href is then attempted first, and the last Property probe is
clamped to exactly the time left in the shared enumeration budget.
"""
class Clock:
now = 0.0
def monotonic(self):
return self.now
class SilentSession:
def __init__(self, clock):
self.clock = clock
self.calls = []
def get(self, path, timeout=10.0):
self.calls.append((tuple(path), timeout))
self.clock.now += timeout
raise TimeoutError
def pace(self):
pass
clock = Clock()
session = SilentSession(clock)
monkeypatch.setattr(subdevices_module.time, 'monotonic', clock.monotonic)
resources = {
'/subdevices/vs/0': {
'x.com.samsung.da.subdeviceIdList': [_UUID],
},
'/power/vs/0': {'power': 'On'},
'/mode/vs/0': {'mode': 'Cool'},
}
found, extra = enumerate_subdevices(
session,
resources,
oic_res_links=[],
preferred_hrefs=('/mode/vs/0',),
time_budget=7.0,
collection_timeout=4.0,
property_timeout=2.0,
)
assert found == []
assert extra == {}
assert clock.now == 7.0
assert session.calls == [
((_UUID, 'device', '0'), 4.0),
((_UUID, 'mode', 'vs', '0'), 2.0),
((_UUID, 'power', 'vs', '0'), 1.0),
]
def test_enumeration_keeps_preferred_response_found_before_budget_expires(
monkeypatch,
):
"""A useful early response survives later silent probes hitting the cap."""
class Clock:
now = 0.0
def monotonic(self):
return self.now
class PartlyResponsiveSession:
def __init__(self, clock):
self.clock = clock
def get(self, path, timeout=10.0):
if tuple(path) == (_UUID, 'mode', 'vs', '0'):
return 0x45, cbor2.dumps({'mode': 'Cool'})
self.clock.now += timeout
raise TimeoutError
def pace(self):
pass
clock = Clock()
monkeypatch.setattr(subdevices_module.time, 'monotonic', clock.monotonic)
resources = {
'/subdevices/vs/0': {
'x.com.samsung.da.subdeviceIdList': [_UUID],
},
'/power/vs/0': {'power': 'On'},
'/mode/vs/0': {'mode': 'Cool'},
}
found, extra = enumerate_subdevices(
PartlyResponsiveSession(clock),
resources,
oic_res_links=[],
preferred_hrefs=('/mode/vs/0',),
time_budget=7.0,
collection_timeout=4.0,
property_timeout=2.0,
)
assert [(subdevice.kind, subdevice.key) for subdevice in found] == [
('prefixed', _UUID),
]
assert found[0].flat_hrefs == ('/mode/vs/0',)
assert extra == {f'/{_UUID}/mode/vs/0': {'mode': 'Cool'}}
assert clock.now == 7.0
def test_enumerate_prefixed_flat_fallback_with_no_master_hrefs_to_probe_is_a_no_op():
"""The master itself having nothing but /subdevices/vs/0 in its own
resources this cycle (e.g. a very first, mostly-empty poll) must not
+87
View File
@@ -114,6 +114,93 @@ def test_no_catalog_carries_unresolved_core_references():
assert unresolved == [], language
def test_confirmed_korean_table_02_washer_course_names():
states = _load('en')['entity']['select']['washer_cycle_table_02']['state']
assert {code: states[code] for code in (
'69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71',
'72', '73', '74', '75', '76', '77', '78', '79', '88',
)} == {
'69': 'AI Wash',
'6a': 'Wool',
'6b': 'Denim',
'6c': 'Blouses',
'6d': 'Delicates',
'6e': 'Active Wear',
'6f': 'Bedding',
'70': 'Towels',
'71': 'Quick Wash',
'72': 'Shirts',
'73': 'Sanitize',
'74': 'Drum Clean',
'75': 'Outdoor',
'76': 'Baby Care',
'77': 'Cottons',
'78': 'Rinse + Spin',
'79': 'Spin Only',
'88': 'Pet Care',
}
def test_confirmed_dishwasher_course_names():
states = _load('en')['entity']['select']['dishwasher_cycle']['state']
assert {code: states[code] for code in (
'82', '8a', 'a7', 'a8', '8c', '88',
)} == {
'82': 'Auto',
'8a': 'Normal',
'a7': 'Heavy',
'a8': 'Express',
'8c': 'Extra Silence',
'88': 'Self Clean',
}
def test_confirmed_course_names_are_localized():
washer_codes = (
'69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71',
'72', '73', '74', '75', '76', '77', '78', '79', '88',
)
dishwasher_codes = ('82', '8a', 'a7', 'a8', '8c', '88')
expected = {
'cs': {
'washer': (
'AI praní', 'Vlna', 'Džíny', 'Halenky', 'Jemné prádlo',
'Sportovní oblečení', 'Ložní prádlo', 'Ručníky',
'Rychlé praní', 'Košile', 'Dezinfekce', 'Čištění bubnu',
'Outdoor', 'Dětské potřeby', 'Bavlna',
'Máchání + odstřeďování', 'Pouze odstřeďování',
'Péče o domácí mazlíčky',
),
'dishwasher': (
'Automatický', 'Normální', 'Intenzivní', 'Expresní',
'Extra tichý', 'Samočištění',
),
},
'nl': {
'washer': (
'AI Wash', 'Wol', 'Spijkergoed', 'Blouses', 'Fijne was',
'Sportkleding', 'Beddengoed', 'Handdoeken', 'Snelle was',
'Overhemden', 'Hygiëne', 'Trommel reinigen', 'Outdoor',
'Babyverzorging', 'Katoen', 'Spoelen + centrifugeren',
'Alleen centrifugeren', 'Pet Care',
),
'dishwasher': (
'Auto', 'Normaal', 'Intensief', 'Express', 'Extra stil',
'Zelfreiniging',
),
},
}
for language, translations in expected.items():
catalog = _load(language)['entity']['select']
washer = catalog['washer_cycle_table_02']['state']
dishwasher = catalog['dishwasher_cycle']['state']
assert tuple(washer[code] for code in washer_codes) == translations['washer']
assert tuple(dishwasher[code] for code in dishwasher_codes) == (
translations['dishwasher']
)
# The hood fan is its device's primary feature: fan.py sets _attr_name = None
# so it presents as the device itself, and never reads a catalog name. Same
# for the ARTIK051 air-purifier's airflow_fan (issue #56) -- ordered speed
+11
View File
@@ -120,6 +120,16 @@ class TestWasherCourse:
rep = {"x.com.samsung.da.options": ["DeviceType_0167", "Course_1C", "GMT_04"]}
assert desc.rep_fn(rep) == "1C"
def test_reported_table_02_course_codes_are_translated(self):
"""The owner confirmed this washer's newer Table_02 course family."""
from custom_components.localthings.catalog import translated_states
confirmed = {
'69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71',
'72', '73', '74', '75', '76', '77', '78', '79', '88',
}
assert confirmed <= translated_states('select', 'washer_cycle_table_02')
def test_missing_course_option_returns_none(self):
desc = next(e for e in washer.WASHER_COURSE.entities if e.key == "cycle")
assert desc.rep_fn is not None
@@ -132,6 +142,7 @@ class TestWasherCourse:
if e.key == "cycle" and isinstance(e, SelectDesc)
)
assert desc.options is laundry.cycle_options
assert desc.display_fn is laundry.washer_cycle_fallback
def test_exists_only_when_edit_course_list_is_live(self):
"""No hardcoded course table is kept -- the selector only appears