Improve handling of missing miele program codes (#144093)

* Use device class transation

* Improve handling of unknown program codes

* Address review comment
This commit is contained in:
Åke Strandberg 2025-05-02 17:31:11 +02:00 committed by GitHub
parent 81444c8f4a
commit cbf4676ae4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 28 deletions

View File

@ -2,6 +2,8 @@
from enum import IntEnum
from pymiele import MieleEnum
DOMAIN = "miele"
MANUFACTURER = "Miele"
@ -325,13 +327,17 @@ STATE_PROGRAM_PHASE: dict[int, dict[int, str]] = {
MieleAppliance.ROBOT_VACUUM_CLEANER: STATE_PROGRAM_PHASE_ROBOT_VACUUM_CLEANER,
}
STATE_PROGRAM_TYPE = {
0: "normal_operation_mode",
1: "own_program",
2: "automatic_program",
3: "cleaning_care_program",
4: "maintenance_program",
}
class StateProgramType(MieleEnum):
"""Defines program types."""
normal_operation_mode = 0
own_program = 1
automatic_program = 2
cleaning_care_program = 3
maintenance_program = 4
unknown = -9999
WASHING_MACHINE_PROGRAM_ID: dict[int, str] = {
-1: "no_program", # Extrapolated from other device types.

View File

@ -30,9 +30,9 @@ from homeassistant.helpers.typing import StateType
from .const import (
STATE_PROGRAM_ID,
STATE_PROGRAM_PHASE,
STATE_PROGRAM_TYPE,
STATE_STATUS_TAGS,
MieleAppliance,
StateProgramType,
StateStatus,
)
from .coordinator import MieleConfigEntry, MieleDataUpdateCoordinator
@ -181,10 +181,10 @@ SENSOR_TYPES: Final[tuple[MieleSensorDefinition, ...]] = (
description=MieleSensorDescription(
key="state_program_type",
translation_key="program_type",
value_fn=lambda value: value.state_program_type,
value_fn=lambda value: StateProgramType(value.state_program_type).name,
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.ENUM,
options=sorted(set(STATE_PROGRAM_TYPE.values())),
options=sorted(set(StateProgramType.keys())),
),
),
MieleSensorDefinition(
@ -440,8 +440,6 @@ async def async_setup_entry(
entity_class = MieleProgramIdSensor
case "state_program_phase":
entity_class = MielePhaseSensor
case "state_program_type":
entity_class = MieleTypeSensor
case _:
entity_class = MieleSensor
if (
@ -553,22 +551,6 @@ class MielePhaseSensor(MieleSensor):
)
class MieleTypeSensor(MieleSensor):
"""Representation of the program type sensor."""
@property
def native_value(self) -> StateType:
"""Return the state of the sensor."""
ret_val = STATE_PROGRAM_TYPE.get(int(self.device.state_program_type))
if ret_val is None:
_LOGGER.debug(
"Unknown program type: %s on device type: %s",
self.device.state_program_type,
self.device.device_type,
)
return ret_val
class MieleProgramIdSensor(MieleSensor):
"""Representation of the program id sensor."""

View File

@ -788,6 +788,7 @@
'maintenance_program',
'normal_operation_mode',
'own_program',
'unknown',
]),
}),
'config_entry_id': <ANY>,
@ -829,6 +830,7 @@
'maintenance_program',
'normal_operation_mode',
'own_program',
'unknown',
]),
}),
'context': <ANY>,