Add energy/water forecast for Miele integration (#144822)

* Add energy/water forecast & fix drying_step error

Adding the energy forecast and water forecast entities that are present in the HACS version of this integration but absent in the HA Core implantation. 

Also fixed the state_drying_step sensor which wasn't handling casting of the API value to an int correctly due to the API sometimes giving a None value.

* Fix formatting issues from previous commit

* Fix missing translation_key line 202

* Remove icon entries

* Update icons.json

* Update strings.json

* Update strings.json (correcting mixed up energy/water forecast names)

* Update homeassistant/components/miele/strings.json

Co-authored-by: Åke Strandberg <ake@strandberg.eu>

* Update homeassistant/components/miele/strings.json

Co-authored-by: Åke Strandberg <ake@strandberg.eu>

* Fix tests

---------

Co-authored-by: Åke Strandberg <ake@strandberg.eu>
Co-authored-by: Joostlek <joostlek@outlook.com>
This commit is contained in:
generically-named 2025-05-19 06:03:27 +09:30 committed by GitHub
parent c1fcd8ea7f
commit 3ecde49dca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 148 additions and 0 deletions

View File

@ -87,6 +87,12 @@
}, },
"remaining_time": { "remaining_time": {
"default": "mdi:clock-end" "default": "mdi:clock-end"
},
"energy_forecast": {
"default": "mdi:lightning-bolt-outline"
},
"water_forecast": {
"default": "mdi:water-outline"
} }
}, },
"switch": { "switch": {

View File

@ -16,6 +16,7 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.const import ( from homeassistant.const import (
PERCENTAGE,
REVOLUTIONS_PER_MINUTE, REVOLUTIONS_PER_MINUTE,
EntityCategory, EntityCategory,
UnitOfEnergy, UnitOfEnergy,
@ -258,6 +259,27 @@ 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.WASHER_DRYER,
),
description=MieleSensorDescription(
key="energy_forecast",
translation_key="energy_forecast",
value_fn=(
lambda value: value.energy_forecast * 100
if value.energy_forecast is not None
else None
),
native_unit_of_measurement=PERCENTAGE,
entity_category=EntityCategory.DIAGNOSTIC,
),
),
MieleSensorDefinition( MieleSensorDefinition(
types=( types=(
MieleAppliance.WASHING_MACHINE, MieleAppliance.WASHING_MACHINE,
@ -274,6 +296,24 @@ SENSOR_TYPES: Final[tuple[MieleSensorDefinition, ...]] = (
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
), ),
MieleSensorDefinition(
types=(
MieleAppliance.WASHING_MACHINE,
MieleAppliance.DISHWASHER,
MieleAppliance.WASHER_DRYER,
),
description=MieleSensorDescription(
key="water_forecast",
translation_key="water_forecast",
value_fn=(
lambda value: value.water_forecast * 100
if value.water_forecast is not None
else None
),
native_unit_of_measurement=PERCENTAGE,
entity_category=EntityCategory.DIAGNOSTIC,
),
),
MieleSensorDefinition( MieleSensorDefinition(
types=( types=(
MieleAppliance.WASHING_MACHINE, MieleAppliance.WASHING_MACHINE,

View File

@ -910,6 +910,12 @@
}, },
"core_target_temperature": { "core_target_temperature": {
"name": "Core target temperature" "name": "Core target temperature"
},
"energy_forecast": {
"name": "Energy forecast"
},
"water_forecast": {
"name": "Water forecast"
} }
}, },
"switch": { "switch": {

View File

@ -1159,6 +1159,54 @@
'state': '0.0', 'state': '0.0',
}) })
# --- # ---
# name: test_sensor_states[platforms0][sensor.washing_machine_energy_forecast-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_energy_forecast',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Energy forecast',
'platform': 'miele',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'energy_forecast',
'unique_id': 'Dummy_Appliance_3-energy_forecast',
'unit_of_measurement': '%',
})
# ---
# name: test_sensor_states[platforms0][sensor.washing_machine_energy_forecast-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Washing machine Energy forecast',
'unit_of_measurement': '%',
}),
'context': <ANY>,
'entity_id': 'sensor.washing_machine_energy_forecast',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '10.0',
})
# ---
# name: test_sensor_states[platforms0][sensor.washing_machine_program-entry] # name: test_sensor_states[platforms0][sensor.washing_machine_program-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({
@ -1638,3 +1686,51 @@
'state': '0.0', 'state': '0.0',
}) })
# --- # ---
# name: test_sensor_states[platforms0][sensor.washing_machine_water_forecast-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_water_forecast',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Water forecast',
'platform': 'miele',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'water_forecast',
'unique_id': 'Dummy_Appliance_3-water_forecast',
'unit_of_measurement': '%',
})
# ---
# name: test_sensor_states[platforms0][sensor.washing_machine_water_forecast-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Washing machine Water forecast',
'unit_of_measurement': '%',
}),
'context': <ANY>,
'entity_id': 'sensor.washing_machine_water_forecast',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '0.0',
})
# ---