From 3ecde49dca2baeef4acebd2d11f83c2cf248db96 Mon Sep 17 00:00:00 2001 From: generically-named <85384565+generically-named@users.noreply.github.com> Date: Mon, 19 May 2025 06:03:27 +0930 Subject: [PATCH] Add energy/water forecast for Miele integration (#144822) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * Update homeassistant/components/miele/strings.json Co-authored-by: Åke Strandberg * Fix tests --------- Co-authored-by: Åke Strandberg Co-authored-by: Joostlek --- homeassistant/components/miele/icons.json | 6 ++ homeassistant/components/miele/sensor.py | 40 ++++++++ homeassistant/components/miele/strings.json | 6 ++ .../miele/snapshots/test_sensor.ambr | 96 +++++++++++++++++++ 4 files changed, 148 insertions(+) diff --git a/homeassistant/components/miele/icons.json b/homeassistant/components/miele/icons.json index d38a2862e89..1806fe688d6 100644 --- a/homeassistant/components/miele/icons.json +++ b/homeassistant/components/miele/icons.json @@ -87,6 +87,12 @@ }, "remaining_time": { "default": "mdi:clock-end" + }, + "energy_forecast": { + "default": "mdi:lightning-bolt-outline" + }, + "water_forecast": { + "default": "mdi:water-outline" } }, "switch": { diff --git a/homeassistant/components/miele/sensor.py b/homeassistant/components/miele/sensor.py index d09f16ee9a0..d5085ae606f 100644 --- a/homeassistant/components/miele/sensor.py +++ b/homeassistant/components/miele/sensor.py @@ -16,6 +16,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.const import ( + PERCENTAGE, REVOLUTIONS_PER_MINUTE, EntityCategory, UnitOfEnergy, @@ -258,6 +259,27 @@ SENSOR_TYPES: Final[tuple[MieleSensorDefinition, ...]] = ( 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( types=( MieleAppliance.WASHING_MACHINE, @@ -274,6 +296,24 @@ SENSOR_TYPES: Final[tuple[MieleSensorDefinition, ...]] = ( 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( types=( MieleAppliance.WASHING_MACHINE, diff --git a/homeassistant/components/miele/strings.json b/homeassistant/components/miele/strings.json index d0d8e14cf10..2cbc4f2f5f4 100644 --- a/homeassistant/components/miele/strings.json +++ b/homeassistant/components/miele/strings.json @@ -910,6 +910,12 @@ }, "core_target_temperature": { "name": "Core target temperature" + }, + "energy_forecast": { + "name": "Energy forecast" + }, + "water_forecast": { + "name": "Water forecast" } }, "switch": { diff --git a/tests/components/miele/snapshots/test_sensor.ambr b/tests/components/miele/snapshots/test_sensor.ambr index 40072a8303a..aadcdb1118d 100644 --- a/tests/components/miele/snapshots/test_sensor.ambr +++ b/tests/components/miele/snapshots/test_sensor.ambr @@ -1159,6 +1159,54 @@ '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': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.washing_machine_energy_forecast', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + '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': , + 'entity_id': 'sensor.washing_machine_energy_forecast', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '10.0', + }) +# --- # name: test_sensor_states[platforms0][sensor.washing_machine_program-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ @@ -1638,3 +1686,51 @@ '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': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.washing_machine_water_forecast', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + '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': , + 'entity_id': 'sensor.washing_machine_water_forecast', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '0.0', + }) +# ---