Refactor states and strings for Miele plate power steps (#144992)

* WIP

* Fix type check

* Empty commit
This commit is contained in:
Åke Strandberg 2025-06-23 22:40:46 +02:00 committed by GitHub
parent dc948e3b6c
commit 9b915e996b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 288 additions and 327 deletions

View File

@ -1294,3 +1294,30 @@ STATE_PROGRAM_ID: dict[int, dict[int, str]] = {
MieleAppliance.ROBOT_VACUUM_CLEANER: ROBOT_VACUUM_CLEANER_PROGRAM_ID, MieleAppliance.ROBOT_VACUUM_CLEANER: ROBOT_VACUUM_CLEANER_PROGRAM_ID,
MieleAppliance.COFFEE_SYSTEM: COFFEE_SYSTEM_PROGRAM_ID, MieleAppliance.COFFEE_SYSTEM: COFFEE_SYSTEM_PROGRAM_ID,
} }
class PlatePowerStep(MieleEnum):
"""Plate power settings."""
plate_step_0 = 0
plate_step_warming = 110, 220
plate_step_1 = 1
plate_step_2 = 2
plate_step_3 = 3
plate_step_4 = 4
plate_step_5 = 5
plate_step_6 = 6
plate_step_7 = 7
plate_step_8 = 8
plate_step_9 = 9
plate_step_10 = 10
plate_step_11 = 11
plate_step_12 = 12
plate_step_13 = 13
plate_step_14 = 4
plate_step_15 = 15
plate_step_16 = 16
plate_step_17 = 17
plate_step_18 = 18
plate_step_boost = 117, 118, 218
missing2none = -9999

View File

@ -56,30 +56,27 @@
"plate": { "plate": {
"default": "mdi:circle-outline", "default": "mdi:circle-outline",
"state": { "state": {
"0": "mdi:circle-outline", "plate_step_0": "mdi:circle-outline",
"110": "mdi:alpha-w-circle-outline", "plate_step_warming": "mdi:alpha-w-circle-outline",
"220": "mdi:alpha-w-circle-outline", "plate_step_1": "mdi:circle-slice-1",
"1": "mdi:circle-slice-1", "plate_step_2": "mdi:circle-slice-1",
"2": "mdi:circle-slice-1", "plate_step_3": "mdi:circle-slice-2",
"3": "mdi:circle-slice-2", "plate_step_4": "mdi:circle-slice-2",
"4": "mdi:circle-slice-2", "plate_step_5": "mdi:circle-slice-3",
"5": "mdi:circle-slice-3", "plate_step_6": "mdi:circle-slice-3",
"6": "mdi:circle-slice-3", "plate_step_7": "mdi:circle-slice-4",
"7": "mdi:circle-slice-4", "plate_step_8": "mdi:circle-slice-4",
"8": "mdi:circle-slice-4", "plate_step_9": "mdi:circle-slice-5",
"9": "mdi:circle-slice-5", "plate_step_10": "mdi:circle-slice-5",
"10": "mdi:circle-slice-5", "plate_step_11": "mdi:circle-slice-5",
"11": "mdi:circle-slice-5", "plate_step_12": "mdi:circle-slice-6",
"12": "mdi:circle-slice-6", "plate_step_13": "mdi:circle-slice-6",
"13": "mdi:circle-slice-6", "plate_step_14": "mdi:circle-slice-6",
"14": "mdi:circle-slice-6", "plate_step_15": "mdi:circle-slice-7",
"15": "mdi:circle-slice-7", "plate_step_16": "mdi:circle-slice-7",
"16": "mdi:circle-slice-7", "plate_step_17": "mdi:circle-slice-8",
"17": "mdi:circle-slice-8", "plate_step_18": "mdi:circle-slice-8",
"18": "mdi:circle-slice-8", "plate_step_boost": "mdi:alpha-b-circle-outline"
"117": "mdi:alpha-b-circle-outline",
"118": "mdi:alpha-b-circle-outline",
"217": "mdi:alpha-b-circle-outline"
} }
}, },
"program_type": { "program_type": {

View File

@ -33,6 +33,7 @@ from .const import (
STATE_PROGRAM_PHASE, STATE_PROGRAM_PHASE,
STATE_STATUS_TAGS, STATE_STATUS_TAGS,
MieleAppliance, MieleAppliance,
PlatePowerStep,
StateDryingStep, StateDryingStep,
StateProgramType, StateProgramType,
StateStatus, StateStatus,
@ -46,34 +47,6 @@ _LOGGER = logging.getLogger(__name__)
DISABLED_TEMPERATURE = -32768 DISABLED_TEMPERATURE = -32768
PLATE_POWERS = [
"0",
"110",
"220",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"117",
"118",
"217",
]
DEFAULT_PLATE_COUNT = 4 DEFAULT_PLATE_COUNT = 4
PLATE_COUNT = { PLATE_COUNT = {
@ -543,8 +516,8 @@ SENSOR_TYPES: Final[tuple[MieleSensorDefinition, ...]] = (
translation_placeholders={"plate_no": str(i)}, translation_placeholders={"plate_no": str(i)},
zone=i, zone=i,
device_class=SensorDeviceClass.ENUM, device_class=SensorDeviceClass.ENUM,
options=PLATE_POWERS, options=sorted(PlatePowerStep.keys()),
value_fn=lambda value: value.state_plate_step[0].value_raw, value_fn=lambda value: None,
), ),
) )
for i in range(1, 7) for i in range(1, 7)
@ -683,12 +656,19 @@ class MielePlateSensor(MieleSensor):
def native_value(self) -> StateType: def native_value(self) -> StateType:
"""Return the state of the plate sensor.""" """Return the state of the plate sensor."""
# state_plate_step is [] if all zones are off # state_plate_step is [] if all zones are off
plate_power = (
self.device.state_plate_step[self.entity_description.zone - 1].value_raw return (
PlatePowerStep(
cast(
int,
self.device.state_plate_step[
self.entity_description.zone - 1
].value_raw,
)
).name
if self.device.state_plate_step if self.device.state_plate_step
else 0 else PlatePowerStep.plate_step_0
) )
return str(plate_power)
class MieleStatusSensor(MieleSensor): class MieleStatusSensor(MieleSensor):

View File

@ -203,30 +203,27 @@
"plate": { "plate": {
"name": "Plate {plate_no}", "name": "Plate {plate_no}",
"state": { "state": {
"0": "0", "power_step_0": "0",
"110": "Warming", "power_step_warm": "Warming",
"220": "[%key:component::miele::entity::sensor::plate::state::110%]", "power_step_1": "1",
"1": "1", "power_step_2": "1\u2022",
"2": "1\u2022", "power_step_3": "2",
"3": "2", "power_step_4": "2\u2022",
"4": "2\u2022", "power_step_5": "3",
"5": "3", "power_step_6": "3\u2022",
"6": "3\u2022", "power_step_7": "4",
"7": "4", "power_step_8": "4\u2022",
"8": "4\u2022", "power_step_9": "5",
"9": "5", "power_step_10": "5\u2022",
"10": "5\u2022", "power_step_11": "6",
"11": "6", "power_step_12": "6\u2022",
"12": "6\u2022", "power_step_13": "7",
"13": "7", "power_step_14": "7\u2022",
"14": "7\u2022", "power_step_15": "8",
"15": "8", "power_step_16": "8\u2022",
"16": "8\u2022", "power_step_17": "9",
"17": "9", "power_step_18": "9\u2022",
"18": "9\u2022", "power_step_boost": "Boost"
"117": "Boost",
"118": "[%key:component::miele::entity::sensor::plate::state::117%]",
"217": "[%key:component::miele::entity::sensor::plate::state::117%]"
} }
}, },
"drying_step": { "drying_step": {

View File

@ -97,30 +97,26 @@
'area_id': None, 'area_id': None,
'capabilities': dict({ 'capabilities': dict({
'options': list([ 'options': list([
'0', 'plate_step_0',
'110', 'plate_step_1',
'220', 'plate_step_10',
'1', 'plate_step_11',
'2', 'plate_step_12',
'3', 'plate_step_13',
'4', 'plate_step_15',
'5', 'plate_step_16',
'6', 'plate_step_17',
'7', 'plate_step_18',
'8', 'plate_step_2',
'9', 'plate_step_3',
'10', 'plate_step_4',
'11', 'plate_step_5',
'12', 'plate_step_6',
'13', 'plate_step_7',
'14', 'plate_step_8',
'15', 'plate_step_9',
'16', 'plate_step_boost',
'17', 'plate_step_warming',
'18',
'117',
'118',
'217',
]), ]),
}), }),
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
@ -158,30 +154,26 @@
'device_class': 'enum', 'device_class': 'enum',
'friendly_name': 'Hob with extraction Plate 1', 'friendly_name': 'Hob with extraction Plate 1',
'options': list([ 'options': list([
'0', 'plate_step_0',
'110', 'plate_step_1',
'220', 'plate_step_10',
'1', 'plate_step_11',
'2', 'plate_step_12',
'3', 'plate_step_13',
'4', 'plate_step_15',
'5', 'plate_step_16',
'6', 'plate_step_17',
'7', 'plate_step_18',
'8', 'plate_step_2',
'9', 'plate_step_3',
'10', 'plate_step_4',
'11', 'plate_step_5',
'12', 'plate_step_6',
'13', 'plate_step_7',
'14', 'plate_step_8',
'15', 'plate_step_9',
'16', 'plate_step_boost',
'17', 'plate_step_warming',
'18',
'117',
'118',
'217',
]), ]),
}), }),
'context': <ANY>, 'context': <ANY>,
@ -189,7 +181,7 @@
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': '0', 'state': 'plate_step_0',
}) })
# --- # ---
# name: test_hob_sensor_states[platforms0-hob.json][sensor.hob_with_extraction_plate_2-entry] # name: test_hob_sensor_states[platforms0-hob.json][sensor.hob_with_extraction_plate_2-entry]
@ -199,30 +191,26 @@
'area_id': None, 'area_id': None,
'capabilities': dict({ 'capabilities': dict({
'options': list([ 'options': list([
'0', 'plate_step_0',
'110', 'plate_step_1',
'220', 'plate_step_10',
'1', 'plate_step_11',
'2', 'plate_step_12',
'3', 'plate_step_13',
'4', 'plate_step_15',
'5', 'plate_step_16',
'6', 'plate_step_17',
'7', 'plate_step_18',
'8', 'plate_step_2',
'9', 'plate_step_3',
'10', 'plate_step_4',
'11', 'plate_step_5',
'12', 'plate_step_6',
'13', 'plate_step_7',
'14', 'plate_step_8',
'15', 'plate_step_9',
'16', 'plate_step_boost',
'17', 'plate_step_warming',
'18',
'117',
'118',
'217',
]), ]),
}), }),
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
@ -260,30 +248,26 @@
'device_class': 'enum', 'device_class': 'enum',
'friendly_name': 'Hob with extraction Plate 2', 'friendly_name': 'Hob with extraction Plate 2',
'options': list([ 'options': list([
'0', 'plate_step_0',
'110', 'plate_step_1',
'220', 'plate_step_10',
'1', 'plate_step_11',
'2', 'plate_step_12',
'3', 'plate_step_13',
'4', 'plate_step_15',
'5', 'plate_step_16',
'6', 'plate_step_17',
'7', 'plate_step_18',
'8', 'plate_step_2',
'9', 'plate_step_3',
'10', 'plate_step_4',
'11', 'plate_step_5',
'12', 'plate_step_6',
'13', 'plate_step_7',
'14', 'plate_step_8',
'15', 'plate_step_9',
'16', 'plate_step_boost',
'17', 'plate_step_warming',
'18',
'117',
'118',
'217',
]), ]),
}), }),
'context': <ANY>, 'context': <ANY>,
@ -291,7 +275,7 @@
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': '110', 'state': 'plate_step_warming',
}) })
# --- # ---
# name: test_hob_sensor_states[platforms0-hob.json][sensor.hob_with_extraction_plate_3-entry] # name: test_hob_sensor_states[platforms0-hob.json][sensor.hob_with_extraction_plate_3-entry]
@ -301,30 +285,26 @@
'area_id': None, 'area_id': None,
'capabilities': dict({ 'capabilities': dict({
'options': list([ 'options': list([
'0', 'plate_step_0',
'110', 'plate_step_1',
'220', 'plate_step_10',
'1', 'plate_step_11',
'2', 'plate_step_12',
'3', 'plate_step_13',
'4', 'plate_step_15',
'5', 'plate_step_16',
'6', 'plate_step_17',
'7', 'plate_step_18',
'8', 'plate_step_2',
'9', 'plate_step_3',
'10', 'plate_step_4',
'11', 'plate_step_5',
'12', 'plate_step_6',
'13', 'plate_step_7',
'14', 'plate_step_8',
'15', 'plate_step_9',
'16', 'plate_step_boost',
'17', 'plate_step_warming',
'18',
'117',
'118',
'217',
]), ]),
}), }),
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
@ -362,30 +342,26 @@
'device_class': 'enum', 'device_class': 'enum',
'friendly_name': 'Hob with extraction Plate 3', 'friendly_name': 'Hob with extraction Plate 3',
'options': list([ 'options': list([
'0', 'plate_step_0',
'110', 'plate_step_1',
'220', 'plate_step_10',
'1', 'plate_step_11',
'2', 'plate_step_12',
'3', 'plate_step_13',
'4', 'plate_step_15',
'5', 'plate_step_16',
'6', 'plate_step_17',
'7', 'plate_step_18',
'8', 'plate_step_2',
'9', 'plate_step_3',
'10', 'plate_step_4',
'11', 'plate_step_5',
'12', 'plate_step_6',
'13', 'plate_step_7',
'14', 'plate_step_8',
'15', 'plate_step_9',
'16', 'plate_step_boost',
'17', 'plate_step_warming',
'18',
'117',
'118',
'217',
]), ]),
}), }),
'context': <ANY>, 'context': <ANY>,
@ -393,7 +369,7 @@
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': '8', 'state': 'plate_step_8',
}) })
# --- # ---
# name: test_hob_sensor_states[platforms0-hob.json][sensor.hob_with_extraction_plate_4-entry] # name: test_hob_sensor_states[platforms0-hob.json][sensor.hob_with_extraction_plate_4-entry]
@ -403,30 +379,26 @@
'area_id': None, 'area_id': None,
'capabilities': dict({ 'capabilities': dict({
'options': list([ 'options': list([
'0', 'plate_step_0',
'110', 'plate_step_1',
'220', 'plate_step_10',
'1', 'plate_step_11',
'2', 'plate_step_12',
'3', 'plate_step_13',
'4', 'plate_step_15',
'5', 'plate_step_16',
'6', 'plate_step_17',
'7', 'plate_step_18',
'8', 'plate_step_2',
'9', 'plate_step_3',
'10', 'plate_step_4',
'11', 'plate_step_5',
'12', 'plate_step_6',
'13', 'plate_step_7',
'14', 'plate_step_8',
'15', 'plate_step_9',
'16', 'plate_step_boost',
'17', 'plate_step_warming',
'18',
'117',
'118',
'217',
]), ]),
}), }),
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
@ -464,30 +436,26 @@
'device_class': 'enum', 'device_class': 'enum',
'friendly_name': 'Hob with extraction Plate 4', 'friendly_name': 'Hob with extraction Plate 4',
'options': list([ 'options': list([
'0', 'plate_step_0',
'110', 'plate_step_1',
'220', 'plate_step_10',
'1', 'plate_step_11',
'2', 'plate_step_12',
'3', 'plate_step_13',
'4', 'plate_step_15',
'5', 'plate_step_16',
'6', 'plate_step_17',
'7', 'plate_step_18',
'8', 'plate_step_2',
'9', 'plate_step_3',
'10', 'plate_step_4',
'11', 'plate_step_5',
'12', 'plate_step_6',
'13', 'plate_step_7',
'14', 'plate_step_8',
'15', 'plate_step_9',
'16', 'plate_step_boost',
'17', 'plate_step_warming',
'18',
'117',
'118',
'217',
]), ]),
}), }),
'context': <ANY>, 'context': <ANY>,
@ -495,7 +463,7 @@
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': '15', 'state': 'plate_step_15',
}) })
# --- # ---
# name: test_hob_sensor_states[platforms0-hob.json][sensor.hob_with_extraction_plate_5-entry] # name: test_hob_sensor_states[platforms0-hob.json][sensor.hob_with_extraction_plate_5-entry]
@ -505,30 +473,26 @@
'area_id': None, 'area_id': None,
'capabilities': dict({ 'capabilities': dict({
'options': list([ 'options': list([
'0', 'plate_step_0',
'110', 'plate_step_1',
'220', 'plate_step_10',
'1', 'plate_step_11',
'2', 'plate_step_12',
'3', 'plate_step_13',
'4', 'plate_step_15',
'5', 'plate_step_16',
'6', 'plate_step_17',
'7', 'plate_step_18',
'8', 'plate_step_2',
'9', 'plate_step_3',
'10', 'plate_step_4',
'11', 'plate_step_5',
'12', 'plate_step_6',
'13', 'plate_step_7',
'14', 'plate_step_8',
'15', 'plate_step_9',
'16', 'plate_step_boost',
'17', 'plate_step_warming',
'18',
'117',
'118',
'217',
]), ]),
}), }),
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
@ -566,30 +530,26 @@
'device_class': 'enum', 'device_class': 'enum',
'friendly_name': 'Hob with extraction Plate 5', 'friendly_name': 'Hob with extraction Plate 5',
'options': list([ 'options': list([
'0', 'plate_step_0',
'110', 'plate_step_1',
'220', 'plate_step_10',
'1', 'plate_step_11',
'2', 'plate_step_12',
'3', 'plate_step_13',
'4', 'plate_step_15',
'5', 'plate_step_16',
'6', 'plate_step_17',
'7', 'plate_step_18',
'8', 'plate_step_2',
'9', 'plate_step_3',
'10', 'plate_step_4',
'11', 'plate_step_5',
'12', 'plate_step_6',
'13', 'plate_step_7',
'14', 'plate_step_8',
'15', 'plate_step_9',
'16', 'plate_step_boost',
'17', 'plate_step_warming',
'18',
'117',
'118',
'217',
]), ]),
}), }),
'context': <ANY>, 'context': <ANY>,
@ -597,7 +557,7 @@
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': '117', 'state': 'plate_step_boost',
}) })
# --- # ---
# name: test_sensor_states[platforms0][sensor.freezer-entry] # name: test_sensor_states[platforms0][sensor.freezer-entry]