Read oven cook modes live from the device instead of a hardcoded list

Follow-up to the issue #138 fix: rather than hand-adding
ConvectionRoast/KeepWarm/BreadProof/AirFryer/Dehydrate/SelfClean/SteamClean
to oven._OVEN_MODES, read them from the device's own /mode/vs/0
supportedModes when it reports one, falling back to the static
NV7000BS-era guess only when it doesn't. Matches the adding-device-support
skill's preference for device-reported option lists over hardcoded ones,
and the SelectDesc's write validation now checks the same live list it
displays instead of a separate static tuple.
This commit is contained in:
Marc Billow committed 2026-07-28 13:26:41 +00:00
1 parent 1fb27c30ae
commit 1cdad7f84c
3 files changed
+65 -24

No files matched your search

+32 -2
View File
@@ -120,12 +120,29 @@ def test_oven_setpoint_native_bounds_track_live_unit():
# ---------------------------------------------------------------------------
def test_oven_mode_options_nonempty():
assert len(oven.OVEN_MODE.entities[0].options) > 0
desc = oven.OVEN_MODE.entities[0]
assert callable(desc.options)
assert len(desc.options({})) > 0
def test_oven_mode_options_falls_back_when_no_live_supported_modes():
desc = oven.OVEN_MODE.entities[0]
assert desc.options({}) == list(oven._OVEN_MODES)
def test_oven_mode_options_reads_live_supported_modes():
"""issue #138: the device's own supportedModes list is used verbatim
when present, instead of the static _OVEN_MODES guess."""
desc = oven.OVEN_MODE.entities[0]
resources = {'/mode/vs/0': {
'x.com.samsung.da.supportedModes': ['Bake', 'AirFryer', 'SelfClean'],
}}
assert desc.options(resources) == ['Bake', 'AirFryer', 'SelfClean']
def test_oven_mode_write_round_trips():
desc = oven.OVEN_MODE.entities[0]
valid_mode = desc.options[1] # e.g. 'Bake'
valid_mode = desc.options({})[1] # e.g. 'Bake'
path, body = desc.write_fn(valid_mode, {})
assert path == ['mode', 'vs', '0']
assert body['x.com.samsung.da.modes'] == [valid_mode]
@@ -136,6 +153,19 @@ def test_oven_mode_rejects_unknown():
assert desc.write_fn('SpaghettiMode', {}) is None
def test_oven_mode_write_validates_against_live_supported_modes():
"""A device reporting its own supportedModes is validated against that
list, not the static fallback -- issue #138's AirFryer/SelfClean/etc.
are accepted, and a mode outside the device's own list is rejected even
if some other model's static guess would have allowed it."""
desc = oven.OVEN_MODE.entities[0]
rep = {'x.com.samsung.da.supportedModes': ['Bake', 'AirFryer', 'SelfClean']}
path, body = desc.write_fn('AirFryer', rep)
assert path == ['mode', 'vs', '0']
assert body['x.com.samsung.da.modes'] == ['AirFryer']
assert desc.write_fn('FrozenPizzaPlus', rep) is None
# ---------------------------------------------------------------------------
# OVEN_MODE options-array writes (lamp, sound, fast_preheat, natural_steam).
# Confirmed on real hardware (issue #54): a write only needs to carry the