mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add 3 duration sensors to miele (#143160)
* Add 3 duration sensors * Update snapshot * Address review comments * Cleanup * Adjust type hint
This commit is contained in:
parent
62a7139f4d
commit
5da57271b2
@ -20,6 +20,7 @@ from homeassistant.const import (
|
|||||||
EntityCategory,
|
EntityCategory,
|
||||||
UnitOfEnergy,
|
UnitOfEnergy,
|
||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
|
UnitOfTime,
|
||||||
UnitOfVolume,
|
UnitOfVolume,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -42,6 +43,11 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
DISABLED_TEMPERATURE = -32768
|
DISABLED_TEMPERATURE = -32768
|
||||||
|
|
||||||
|
|
||||||
|
def _convert_duration(value_list: list[int]) -> int | None:
|
||||||
|
"""Convert duration to minutes."""
|
||||||
|
return value_list[0] * 60 + value_list[1] if value_list else None
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, kw_only=True)
|
@dataclass(frozen=True, kw_only=True)
|
||||||
class MieleSensorDescription(SensorEntityDescription):
|
class MieleSensorDescription(SensorEntityDescription):
|
||||||
"""Class describing Miele sensor entities."""
|
"""Class describing Miele sensor entities."""
|
||||||
@ -230,6 +236,87 @@ SENSOR_TYPES: Final[tuple[MieleSensorDefinition, ...]] = (
|
|||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
MieleSensorDefinition(
|
||||||
|
types=(
|
||||||
|
MieleAppliance.WASHING_MACHINE,
|
||||||
|
MieleAppliance.WASHING_MACHINE_SEMI_PROFESSIONAL,
|
||||||
|
MieleAppliance.TUMBLE_DRYER,
|
||||||
|
MieleAppliance.TUMBLE_DRYER_SEMI_PROFESSIONAL,
|
||||||
|
MieleAppliance.DISHWASHER,
|
||||||
|
MieleAppliance.OVEN,
|
||||||
|
MieleAppliance.OVEN_MICROWAVE,
|
||||||
|
MieleAppliance.STEAM_OVEN,
|
||||||
|
MieleAppliance.MICROWAVE,
|
||||||
|
MieleAppliance.ROBOT_VACUUM_CLEANER,
|
||||||
|
MieleAppliance.WASHER_DRYER,
|
||||||
|
MieleAppliance.STEAM_OVEN_COMBI,
|
||||||
|
MieleAppliance.STEAM_OVEN_MICRO,
|
||||||
|
MieleAppliance.DIALOG_OVEN,
|
||||||
|
MieleAppliance.STEAM_OVEN_MK2,
|
||||||
|
),
|
||||||
|
description=MieleSensorDescription(
|
||||||
|
key="state_remaining_time",
|
||||||
|
translation_key="remaining_time",
|
||||||
|
value_fn=lambda value: _convert_duration(value.state_remaining_time),
|
||||||
|
device_class=SensorDeviceClass.DURATION,
|
||||||
|
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
MieleSensorDefinition(
|
||||||
|
types=(
|
||||||
|
MieleAppliance.WASHING_MACHINE,
|
||||||
|
MieleAppliance.TUMBLE_DRYER,
|
||||||
|
MieleAppliance.DISHWASHER,
|
||||||
|
MieleAppliance.OVEN,
|
||||||
|
MieleAppliance.OVEN_MICROWAVE,
|
||||||
|
MieleAppliance.STEAM_OVEN,
|
||||||
|
MieleAppliance.MICROWAVE,
|
||||||
|
MieleAppliance.WASHER_DRYER,
|
||||||
|
MieleAppliance.STEAM_OVEN_COMBI,
|
||||||
|
MieleAppliance.STEAM_OVEN_MICRO,
|
||||||
|
MieleAppliance.DIALOG_OVEN,
|
||||||
|
MieleAppliance.ROBOT_VACUUM_CLEANER,
|
||||||
|
MieleAppliance.STEAM_OVEN_MK2,
|
||||||
|
),
|
||||||
|
description=MieleSensorDescription(
|
||||||
|
key="state_elapsed_time",
|
||||||
|
translation_key="elapsed_time",
|
||||||
|
value_fn=lambda value: _convert_duration(value.state_elapsed_time),
|
||||||
|
device_class=SensorDeviceClass.DURATION,
|
||||||
|
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
MieleSensorDefinition(
|
||||||
|
types=(
|
||||||
|
MieleAppliance.WASHING_MACHINE,
|
||||||
|
MieleAppliance.WASHING_MACHINE_SEMI_PROFESSIONAL,
|
||||||
|
MieleAppliance.TUMBLE_DRYER,
|
||||||
|
MieleAppliance.TUMBLE_DRYER_SEMI_PROFESSIONAL,
|
||||||
|
MieleAppliance.DISHWASHER,
|
||||||
|
MieleAppliance.DISH_WARMER,
|
||||||
|
MieleAppliance.OVEN,
|
||||||
|
MieleAppliance.OVEN_MICROWAVE,
|
||||||
|
MieleAppliance.STEAM_OVEN,
|
||||||
|
MieleAppliance.MICROWAVE,
|
||||||
|
MieleAppliance.WASHER_DRYER,
|
||||||
|
MieleAppliance.STEAM_OVEN_COMBI,
|
||||||
|
MieleAppliance.STEAM_OVEN_MICRO,
|
||||||
|
MieleAppliance.DIALOG_OVEN,
|
||||||
|
MieleAppliance.STEAM_OVEN_MK2,
|
||||||
|
),
|
||||||
|
description=MieleSensorDescription(
|
||||||
|
key="state_start_time",
|
||||||
|
translation_key="start_time",
|
||||||
|
value_fn=lambda value: _convert_duration(value.state_start_time),
|
||||||
|
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||||
|
device_class=SensorDeviceClass.DURATION,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
suggested_display_precision=2,
|
||||||
|
suggested_unit_of_measurement=UnitOfTime.HOURS,
|
||||||
|
),
|
||||||
|
),
|
||||||
MieleSensorDefinition(
|
MieleSensorDefinition(
|
||||||
types=(
|
types=(
|
||||||
MieleAppliance.TUMBLE_DRYER_SEMI_PROFESSIONAL,
|
MieleAppliance.TUMBLE_DRYER_SEMI_PROFESSIONAL,
|
||||||
|
@ -182,6 +182,15 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
"elapsed_time": {
|
||||||
|
"name": "Elapsed time"
|
||||||
|
},
|
||||||
|
"remaining_time": {
|
||||||
|
"name": "Remaining time"
|
||||||
|
},
|
||||||
|
"start_time": {
|
||||||
|
"name": "Start in"
|
||||||
|
},
|
||||||
"energy_consumption": {
|
"energy_consumption": {
|
||||||
"name": "Energy consumption"
|
"name": "Energy consumption"
|
||||||
},
|
},
|
||||||
|
@ -463,6 +463,55 @@
|
|||||||
'state': 'off',
|
'state': 'off',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
# name: test_sensor_states[platforms0][sensor.washing_machine_elapsed_time-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'sensor',
|
||||||
|
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||||
|
'entity_id': 'sensor.washing_machine_elapsed_time',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <SensorDeviceClass.DURATION: 'duration'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Elapsed time',
|
||||||
|
'platform': 'miele',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'elapsed_time',
|
||||||
|
'unique_id': 'Dummy_Appliance_3-state_elapsed_time',
|
||||||
|
'unit_of_measurement': <UnitOfTime.MINUTES: 'min'>,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensor_states[platforms0][sensor.washing_machine_elapsed_time-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'duration',
|
||||||
|
'friendly_name': 'Washing machine Elapsed time',
|
||||||
|
'unit_of_measurement': <UnitOfTime.MINUTES: 'min'>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.washing_machine_elapsed_time',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '0',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
# name: test_sensor_states[platforms0][sensor.washing_machine_energy_consumption-entry]
|
# name: test_sensor_states[platforms0][sensor.washing_machine_energy_consumption-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
@ -790,6 +839,55 @@
|
|||||||
'state': 'normal_operation_mode',
|
'state': 'normal_operation_mode',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
# name: test_sensor_states[platforms0][sensor.washing_machine_remaining_time-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'sensor',
|
||||||
|
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||||
|
'entity_id': 'sensor.washing_machine_remaining_time',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <SensorDeviceClass.DURATION: 'duration'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Remaining time',
|
||||||
|
'platform': 'miele',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'remaining_time',
|
||||||
|
'unique_id': 'Dummy_Appliance_3-state_remaining_time',
|
||||||
|
'unit_of_measurement': <UnitOfTime.MINUTES: 'min'>,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensor_states[platforms0][sensor.washing_machine_remaining_time-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'duration',
|
||||||
|
'friendly_name': 'Washing machine Remaining time',
|
||||||
|
'unit_of_measurement': <UnitOfTime.MINUTES: 'min'>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.washing_machine_remaining_time',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '0',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
# name: test_sensor_states[platforms0][sensor.washing_machine_spin_speed-entry]
|
# name: test_sensor_states[platforms0][sensor.washing_machine_spin_speed-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
@ -838,6 +936,61 @@
|
|||||||
'state': 'unknown',
|
'state': 'unknown',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
# name: test_sensor_states[platforms0][sensor.washing_machine_start_in-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'sensor',
|
||||||
|
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||||
|
'entity_id': 'sensor.washing_machine_start_in',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
'sensor': dict({
|
||||||
|
'suggested_display_precision': 2,
|
||||||
|
}),
|
||||||
|
'sensor.private': dict({
|
||||||
|
'suggested_unit_of_measurement': <UnitOfTime.HOURS: 'h'>,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
'original_device_class': <SensorDeviceClass.DURATION: 'duration'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Start in',
|
||||||
|
'platform': 'miele',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'start_time',
|
||||||
|
'unique_id': 'Dummy_Appliance_3-state_start_time',
|
||||||
|
'unit_of_measurement': <UnitOfTime.HOURS: 'h'>,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensor_states[platforms0][sensor.washing_machine_start_in-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'duration',
|
||||||
|
'friendly_name': 'Washing machine Start in',
|
||||||
|
'unit_of_measurement': <UnitOfTime.HOURS: 'h'>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.washing_machine_start_in',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '0.0',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
# name: test_sensor_states[platforms0][sensor.washing_machine_water_consumption-entry]
|
# name: test_sensor_states[platforms0][sensor.washing_machine_water_consumption-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user