diff --git a/custom_components/bhyve/sensor.py b/custom_components/bhyve/sensor.py index 45b3082..f0bb8f0 100644 --- a/custom_components/bhyve/sensor.py +++ b/custom_components/bhyve/sensor.py @@ -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)