Skip to content

Commit

Permalink
WIP (#1240)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codechimp authored Mar 6, 2024
1 parent c72770e commit f6edcc9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/battery_notes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)
Expand Down
9 changes: 7 additions & 2 deletions custom_components/battery_notes/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)
Expand Down Expand Up @@ -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,
},
)

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit f6edcc9

Please sign in to comment.