mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
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:
parent
81444c8f4a
commit
cbf4676ae4
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
|
|
||||||
|
from pymiele import MieleEnum
|
||||||
|
|
||||||
DOMAIN = "miele"
|
DOMAIN = "miele"
|
||||||
MANUFACTURER = "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,
|
MieleAppliance.ROBOT_VACUUM_CLEANER: STATE_PROGRAM_PHASE_ROBOT_VACUUM_CLEANER,
|
||||||
}
|
}
|
||||||
|
|
||||||
STATE_PROGRAM_TYPE = {
|
|
||||||
0: "normal_operation_mode",
|
class StateProgramType(MieleEnum):
|
||||||
1: "own_program",
|
"""Defines program types."""
|
||||||
2: "automatic_program",
|
|
||||||
3: "cleaning_care_program",
|
normal_operation_mode = 0
|
||||||
4: "maintenance_program",
|
own_program = 1
|
||||||
}
|
automatic_program = 2
|
||||||
|
cleaning_care_program = 3
|
||||||
|
maintenance_program = 4
|
||||||
|
unknown = -9999
|
||||||
|
|
||||||
|
|
||||||
WASHING_MACHINE_PROGRAM_ID: dict[int, str] = {
|
WASHING_MACHINE_PROGRAM_ID: dict[int, str] = {
|
||||||
-1: "no_program", # Extrapolated from other device types.
|
-1: "no_program", # Extrapolated from other device types.
|
||||||
|
@ -30,9 +30,9 @@ from homeassistant.helpers.typing import StateType
|
|||||||
from .const import (
|
from .const import (
|
||||||
STATE_PROGRAM_ID,
|
STATE_PROGRAM_ID,
|
||||||
STATE_PROGRAM_PHASE,
|
STATE_PROGRAM_PHASE,
|
||||||
STATE_PROGRAM_TYPE,
|
|
||||||
STATE_STATUS_TAGS,
|
STATE_STATUS_TAGS,
|
||||||
MieleAppliance,
|
MieleAppliance,
|
||||||
|
StateProgramType,
|
||||||
StateStatus,
|
StateStatus,
|
||||||
)
|
)
|
||||||
from .coordinator import MieleConfigEntry, MieleDataUpdateCoordinator
|
from .coordinator import MieleConfigEntry, MieleDataUpdateCoordinator
|
||||||
@ -181,10 +181,10 @@ SENSOR_TYPES: Final[tuple[MieleSensorDefinition, ...]] = (
|
|||||||
description=MieleSensorDescription(
|
description=MieleSensorDescription(
|
||||||
key="state_program_type",
|
key="state_program_type",
|
||||||
translation_key="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,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
device_class=SensorDeviceClass.ENUM,
|
device_class=SensorDeviceClass.ENUM,
|
||||||
options=sorted(set(STATE_PROGRAM_TYPE.values())),
|
options=sorted(set(StateProgramType.keys())),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
MieleSensorDefinition(
|
MieleSensorDefinition(
|
||||||
@ -440,8 +440,6 @@ async def async_setup_entry(
|
|||||||
entity_class = MieleProgramIdSensor
|
entity_class = MieleProgramIdSensor
|
||||||
case "state_program_phase":
|
case "state_program_phase":
|
||||||
entity_class = MielePhaseSensor
|
entity_class = MielePhaseSensor
|
||||||
case "state_program_type":
|
|
||||||
entity_class = MieleTypeSensor
|
|
||||||
case _:
|
case _:
|
||||||
entity_class = MieleSensor
|
entity_class = MieleSensor
|
||||||
if (
|
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):
|
class MieleProgramIdSensor(MieleSensor):
|
||||||
"""Representation of the program id sensor."""
|
"""Representation of the program id sensor."""
|
||||||
|
|
||||||
|
@ -788,6 +788,7 @@
|
|||||||
'maintenance_program',
|
'maintenance_program',
|
||||||
'normal_operation_mode',
|
'normal_operation_mode',
|
||||||
'own_program',
|
'own_program',
|
||||||
|
'unknown',
|
||||||
]),
|
]),
|
||||||
}),
|
}),
|
||||||
'config_entry_id': <ANY>,
|
'config_entry_id': <ANY>,
|
||||||
@ -829,6 +830,7 @@
|
|||||||
'maintenance_program',
|
'maintenance_program',
|
||||||
'normal_operation_mode',
|
'normal_operation_mode',
|
||||||
'own_program',
|
'own_program',
|
||||||
|
'unknown',
|
||||||
]),
|
]),
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user