progress_percentage lacked the active-state gate already applied to progress/cycle_active/finish_time, so it kept showing a stale device value (e.g. 1%) while idle -- now zeroed the same way. Shared by dryer/dishwasher/ oven via operational.py's OPERATIONAL_STATE. Also exposes detergent/softener auto-dispense quantity, water hardness/ concentration, and low-reservoir alarms from /course/vs/0's options array, using the same decode/RMW helpers already used for course selection and drum-clean tracking. Gated by exists_fn so washer models without these fields (e.g. the existing test fixture) are unaffected. Water consumption is unaffected -- common.WATER_METER is already wired into the washer registry; this reporter's device just doesn't expose /water/consumption/vs/0.
57 lines
2.9 KiB
Python
57 lines
2.9 KiB
Python
from custom_components.localthings.registry.capabilities.operational import OPERATIONAL_STATE
|
|
|
|
|
|
def test_machine_state_maps_samsung_to_ocf():
|
|
ms = next(e for e in OPERATIONAL_STATE.entities if e.key == 'machine_state')
|
|
assert ms.value_fn('Run') == 'active'
|
|
assert ms.value_fn('Pause') == 'pause'
|
|
assert ms.value_fn('Ready') == 'idle'
|
|
|
|
|
|
class TestProgressPercentage:
|
|
"""issue #9: device firmware leaves progressPercentage stale (e.g. '1')
|
|
after a cycle ends instead of resetting it, so it must be gated on
|
|
active state the same way `progress`/`cycle_active`/`finish_time` are."""
|
|
|
|
def test_zeroed_when_not_active(self):
|
|
desc = next(e for e in OPERATIONAL_STATE.entities if e.key == 'progress_percentage')
|
|
rep = {'x.com.samsung.da.state': 'Ready', 'x.com.samsung.da.progressPercentage': '1'}
|
|
assert desc.rep_fn(rep) == 0
|
|
|
|
def test_passes_through_when_active(self):
|
|
desc = next(e for e in OPERATIONAL_STATE.entities if e.key == 'progress_percentage')
|
|
rep = {'x.com.samsung.da.state': 'Run', 'x.com.samsung.da.progressPercentage': '42'}
|
|
assert desc.rep_fn(rep) == 42
|
|
|
|
|
|
class TestDelayFieldFallback:
|
|
def test_reads_delay_end_time_when_delay_start_time_absent(self):
|
|
from custom_components.localthings.registry.capabilities.operational import OPERATIONAL_STATE
|
|
desc = next(e for e in OPERATIONAL_STATE.entities if e.key == 'delay_start_hours')
|
|
rep = {'x.com.samsung.da.delayEndTime': '02:30:00'}
|
|
assert desc.rep_fn(rep) == 2.5
|
|
|
|
def test_prefers_delay_start_time_when_both_present(self):
|
|
from custom_components.localthings.registry.capabilities.operational import OPERATIONAL_STATE
|
|
desc = next(e for e in OPERATIONAL_STATE.entities if e.key == 'delay_start_hours')
|
|
rep = {
|
|
'x.com.samsung.da.delayStartTime': '01:00:00',
|
|
'x.com.samsung.da.delayEndTime': '02:00:00',
|
|
}
|
|
assert desc.rep_fn(rep) == 1.0
|
|
|
|
def test_write_targets_delay_end_time_when_that_is_what_device_reports(self):
|
|
from custom_components.localthings.registry.capabilities.operational import OPERATIONAL_STATE
|
|
desc = next(e for e in OPERATIONAL_STATE.entities if e.key == 'delay_start_hours')
|
|
rep = {'x.com.samsung.da.delayEndTime': '00:00:00'}
|
|
path, body = desc.write_fn(1.5, rep)
|
|
assert path == ['operational', 'state', 'vs', '0']
|
|
assert body == {'x.com.samsung.da.delayEndTime': '1:30:00'}
|
|
|
|
def test_write_targets_delay_start_time_by_default(self):
|
|
from custom_components.localthings.registry.capabilities.operational import OPERATIONAL_STATE
|
|
desc = next(e for e in OPERATIONAL_STATE.entities if e.key == 'delay_start_hours')
|
|
rep = {'x.com.samsung.da.delayStartTime': '00:00:00'}
|
|
path, body = desc.write_fn(1.5, rep)
|
|
assert body == {'x.com.samsung.da.delayStartTime': '1:30:00'}
|