Skip to content

Commit

Permalink
#230: Log a warning if the battery type is not an object (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebr authored Apr 23, 2024
1 parent 856a554 commit faa2d89
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions custom_components/bhyve/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ def parse_battery_level(battery_data):
Returns:
float: The battery level as a percentage.
"""

if not isinstance(battery_data, dict):
_LOGGER.warning("Unexpected battery data, returning 0: %s", battery_data)
return 0

battery_level = battery_data.get("percent", 0)
if "mv" in battery_data and "percent" not in battery_data:
battery_level = min(battery_data.get("mv", 0) / 3000 * 100, 100)
Expand Down

0 comments on commit faa2d89

Please sign in to comment.