Skip to content

Commit 46979b8

Browse files
astrandbfrenck
authored andcommitted
Fix for corrupt restored state in miele consumption sensors (home-assistant#155966)
1 parent 1718a11 commit 46979b8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

homeassistant/components/miele/sensor.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,13 +943,19 @@ def _update_native_value(self) -> None:
943943
"""Update the last value of the sensor."""
944944
current_value = self.entity_description.value_fn(self.device)
945945
current_status = StateStatus(self.device.state_status)
946+
# Guard for corrupt restored value
947+
restored_value = (
948+
self._attr_native_value
949+
if isinstance(self._attr_native_value, (int, float))
950+
else 0
951+
)
946952
last_value = (
947-
float(cast(str, self._attr_native_value))
953+
float(cast(str, restored_value))
948954
if self._attr_native_value is not None
949955
else 0
950956
)
951957

952-
# force unknown when appliance is not able to report consumption
958+
# Force unknown when appliance is not able to report consumption
953959
if current_status in (
954960
StateStatus.ON,
955961
StateStatus.OFF,

0 commit comments

Comments
 (0)