Add Samsung microwave support (TP2X_DA-KS-MICROWAVE-01011-class, issue #66)

Reuses the oven family's door/connected/operational-state capabilities
wholesale (identical resource shapes) and adds microwave-specific mode/
cavity/temperature capabilities for the fields that differ (cook-mode
vocabulary, powerLevel, no setpoint write). Resolves via a new '-MICROWAVE-'
modelNum token fallback, mirroring the existing '-OVEN-'/'-RANGE-' rules.
This commit is contained in:
Marc Billow committed 2026-07-24 15:26:21 +00:00
1 parent 77cc875608
commit ede8719636
9 files changed
+544 -3

No files matched your search

@@ -3,7 +3,7 @@ from typing import Optional
from ._base import DeviceRegistry
from . import (
air_purifier, airconditioner, cooktop, dishwasher, dryer, oven,
air_purifier, airconditioner, cooktop, dishwasher, dryer, microwave, oven,
range as _range, range_hood, refrigerator, washer,
)
@@ -21,6 +21,7 @@ _REGISTRY_BY_KEY: dict[str, DeviceRegistry] = {
'cooktop': cooktop.REGISTRY,
'dishwasher': dishwasher.REGISTRY,
'dryer': dryer.REGISTRY,
'microwave': microwave.REGISTRY,
'oven': oven.REGISTRY,
'hood': range_hood.REGISTRY,
'range': _range.REGISTRY,
@@ -141,6 +142,11 @@ def for_device_by_model(model_num: str, description: str) -> Optional[DeviceRegi
# oneUiVersion and doesn't match the washer/dryer/dishwasher prefix map.
if key is None and '-OVEN-' in (model_num or '').upper():
key = 'oven'
# Microwaves (e.g. TP2X_DA-KS-MICROWAVE-01011, issue #66) -- same
# board-family naming as the range/oven combos above; reports no
# oneUiVersion and doesn't match the washer/dryer/dishwasher prefix map.
if key is None and '-MICROWAVE-' in (model_num or '').upper():
key = 'microwave'
return _REGISTRY_BY_KEY.get(key) if key else None
@@ -0,0 +1,24 @@
"""Microwave device registry — issue #66.
Reuses the oven family's door/connected/operational-state capabilities
wholesale (byte-for-byte identical resource shapes, all generically-keyed)
and adds microwave-specific mode/cavity/temperature capabilities for the
fields that differ. See capabilities/microwave.py's module docstring.
"""
from ..capabilities import common, ignored, microwave, oven
from ._base import DeviceRegistry, _build
REGISTRY = DeviceRegistry(
name='microwave',
capabilities=_build([
*ignored.IGNORED,
*common.UNIVERSAL,
*common.POWER,
oven.OVEN_DOOR,
oven.OVEN_CONNECTED,
oven.OVEN_OPERATIONAL_STATE,
microwave.MICROWAVE_MODE,
microwave.MICROWAVE_CAVITY,
microwave.MICROWAVE_TEMPERATURE,
]),
)
@@ -131,4 +131,11 @@ IGNORED: list[Capability] = [
# parallel write-capable capability around an unverified generic OCF
# write contract.
Capability(href='/operational/state/0'),
# Microwave (issue #66): JSON-encoded {language, menu, servingSize,
# option} display string for the active cook recipe/program. Every
# field is empty on the only dump seen so far (device idle, no active
# cook program) -- no confirmed shape to build an entity around.
# Revisit if a dump with an active cook program surfaces.
Capability(href='/recipe/cook/vs/0'),
]
@@ -0,0 +1,132 @@
"""Capabilities for the microwave family (Samsung MW5300A-class, issue #66).
/doors/vs/0, /connected/vs/0, and /operational/state/vs/0 report the exact
same field shapes as the oven family's resources of the same name (all
generically-keyed: door_open, cloud_connected, machine_state, cycle_active,
progress_percentage, operation_time_minutes, finish_time, cook_time, stop),
so those capabilities are reused directly from oven.py rather than
re-declared here -- see by_type/microwave.py.
/mode/vs/0's cook-mode vocabulary (MicroWave/MicroWaveGrill/Grill/Autocook)
and options-array toggles (only a Sound_On/Off slot on this dump -- no
UpperLamp/fastpreheat/NaturalSteam like the oven family) are microwave-
specific, so it gets its own capability here. /oven/vs/0 additionally
reports a powerLevel field the oven family's cavity capability doesn't
carry, so it also gets its own.
Cycle start/pause is deliberately not modeled: unlike the oven family
(whose module docstring documents confirmed-unreliable local cycle-start
writes from live testing), no live microwave has exercised writes at all --
this module is built from a single diagnostics dump. The shared
STOP_BUTTON's state='Ready' RMW is safe and reused via
oven.OVEN_OPERATIONAL_STATE. The /temperatures/vs/0 reading is exposed
read-only for the same reason: desired='0' on the only dump seen, well
below any plausible cook temperature, with no confirmed write contract.
/recipe/cook/vs/0 (a JSON-encoded {language, menu, servingSize, option}
display string) is not modeled here -- every field is empty on this dump
(device idle, no active cook program); see ignored.py.
"""
from ..capability import Capability
from ..entities import SelectDesc, SensorDesc, SwitchDesc
from .common import normalize_temp_unit
def _int(v):
try:
return int(v)
except (TypeError, ValueError):
return None
def _cavity_temp_unit(rep):
items = rep.get('x.com.samsung.da.items') or []
unit = items[0].get('x.com.samsung.da.unit') if items else None
return normalize_temp_unit(unit, default='°C')
def _option_value(options, prefix):
"""Find `<prefix>_<value>` in an options array and return <value>."""
for o in (options or []):
if isinstance(o, str) and o.startswith(prefix + '_'):
return o.split('_', 1)[1]
return None
def _replace_in_options(options, prefix, new_value):
"""Return a new options list with the `<prefix>_*` slot replaced."""
return [f"{prefix}_{new_value}" if o.startswith(prefix + '_') else o
for o in options]
def _sound_write(p, rep, href=None):
if p not in ('On', 'Off'):
return None
opts = list(rep.get('x.com.samsung.da.options') or [])
if not opts:
return None
return ['mode', 'vs', '0'], {
'x.com.samsung.da.options': _replace_in_options(opts, 'Sound', p),
}
# Cook modes as reported by /mode/vs/0's supportedModes (issue #66 dump) --
# no oven-style Bake/Broil vocabulary applies to a microwave.
_MICROWAVE_MODES = (
'NoOperation',
'MicroWave',
'MicroWaveGrill',
'Grill',
'Autocook',
'AutocookCustom',
)
def _mode_write(p, rep, href=None):
if p not in _MICROWAVE_MODES:
return None
return ['mode', 'vs', '0'], {'x.com.samsung.da.modes': [p]}
MICROWAVE_MODE = Capability(
href='/mode/vs/0',
poll_tier='warm',
entities=(
SelectDesc(key='cook_mode', field='x.com.samsung.da.modes',
name='Cooking mode', icon='mdi:tune',
options=_MICROWAVE_MODES,
value_fn=lambda v: v[0] if v else None,
write_fn=_mode_write),
SwitchDesc(key='sound', field='x.com.samsung.da.options',
name='Sound', icon='mdi:volume-high',
entity_category='config',
value_fn=lambda opts: _option_value(opts, 'Sound') == 'On',
write_fn=_sound_write),
),
)
MICROWAVE_CAVITY = Capability(
href='/oven/vs/0',
poll_tier='hot',
entities=(
SensorDesc(key='cavity_state', field='x.com.samsung.da.state',
name='Cavity state'),
# e.g. "0W"/"700W" -- unit is embedded in the string on every dump
# seen so far; shown as reported rather than parsed apart.
SensorDesc(key='power_level', field='x.com.samsung.da.powerLevel',
name='Power level', icon='mdi:flash'),
),
)
MICROWAVE_TEMPERATURE = Capability(
href='/temperatures/vs/0',
poll_tier='warm',
entities=(
SensorDesc(key='cavity_temp', field='x.com.samsung.da.items',
name='Cavity temperature', device_class='temperature',
state_class='measurement', entity_category='diagnostic',
unit_fn=_cavity_temp_unit,
value_fn=lambda items: _int(
(items[0].get('x.com.samsung.da.current') if items else None))),
),
)