Parse the wattage out of microwave power_level instead of a raw string

"700W"/"0W" was passed straight through as an untyped string sensor.
Parse the numeral and set device_class/unit so HA treats it as a power
measurement. Add a unit-handling step to the adding-device-support skill
so future dumps get this right the first time.
This commit is contained in:
Marc Billow committed 2026-07-24 15:28:46 +00:00
1 parent ede8719636
commit 4a5d6bca59
3 files changed
+61 -11

No files matched your search

+9 -2
View File
@@ -84,9 +84,16 @@ def test_cavity_state_reads_state_field():
assert desc.value_fn('Ready') == 'Ready'
def test_power_level_reads_raw_string():
def test_power_level_parses_watts():
desc = next(e for e in microwave.MICROWAVE_CAVITY.entities if e.key == 'power_level')
assert desc.value_fn('700W') == '700W'
assert desc.value_fn('700W') == 700
assert desc.value_fn('0W') == 0
def test_power_level_rejects_unparseable():
desc = next(e for e in microwave.MICROWAVE_CAVITY.entities if e.key == 'power_level')
assert desc.value_fn('') is None
assert desc.value_fn(None) is None
# ---------------------------------------------------------------------------