From f6edcc9356982a20bfa609650707359fd4ce808a Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Wed, 6 Mar 2024 08:38:15 +0000 Subject: [PATCH] WIP (#1240) --- custom_components/battery_notes/__init__.py | 2 +- custom_components/battery_notes/coordinator.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/custom_components/battery_notes/__init__.py b/custom_components/battery_notes/__init__.py index 71ba9654c..88b1c895b 100644 --- a/custom_components/battery_notes/__init__.py +++ b/custom_components/battery_notes/__init__.py @@ -379,7 +379,7 @@ async def handle_battery_low(call): ATTR_BATTERY_TYPE: device.coordinator.battery_type, ATTR_BATTERY_QUANTITY: device.coordinator.battery_quantity, ATTR_BATTERY_LEVEL: device.coordinator.rounded_battery_level, - ATTR_PREVIOUS_BATTERY_LEVEL: device.coordinator._previous_battery_level, + ATTR_PREVIOUS_BATTERY_LEVEL: device.coordinator.rounded_previous_battery_level, ATTR_BATTERY_THRESHOLD_REMINDER: True, }, ) diff --git a/custom_components/battery_notes/coordinator.py b/custom_components/battery_notes/coordinator.py index dbb0f9547..1dfa26bac 100644 --- a/custom_components/battery_notes/coordinator.py +++ b/custom_components/battery_notes/coordinator.py @@ -146,7 +146,7 @@ def current_battery_level(self, value): ATTR_BATTERY_TYPE: self.battery_type, ATTR_BATTERY_QUANTITY: self.battery_quantity, ATTR_BATTERY_LEVEL: self.rounded_battery_level, - ATTR_PREVIOUS_BATTERY_LEVEL: self._previous_battery_level, + ATTR_PREVIOUS_BATTERY_LEVEL: self.rounded_previous_battery_level, ATTR_BATTERY_THRESHOLD_REMINDER: False, }, ) @@ -178,7 +178,7 @@ def current_battery_level(self, value): ATTR_BATTERY_TYPE: self.battery_type, ATTR_BATTERY_QUANTITY: self.battery_quantity, ATTR_BATTERY_LEVEL: self.rounded_battery_level, - ATTR_PREVIOUS_BATTERY_LEVEL: self._previous_battery_level, + ATTR_PREVIOUS_BATTERY_LEVEL: self.rounded_previous_battery_level, }, ) @@ -269,6 +269,11 @@ def rounded_battery_level(self) -> float: """Return the battery level, rounded if preferred.""" return self._rounded_level(self.current_battery_level) + @property + def rounded_previous_battery_level(self) -> float: + """Return the previous battery level, rounded if preferred.""" + return self._rounded_level(self._previous_battery_level) + def _rounded_level(self, value) -> float: """Round the level, if preferred.""" if isfloat(value):