1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-02 00:20:30 +01:00

Clamp surepetcare battery percentage to 0-100 (#166824)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Florian
2026-03-30 12:34:38 +02:00
committed by GitHub
parent be3d65538d
commit c6ad6da6ae

View File

@@ -73,8 +73,8 @@ class SureBattery(SurePetcareEntity, SensorEntity):
try:
per_battery_voltage = state["battery"] / 4
voltage_diff = per_battery_voltage - SURE_BATT_VOLTAGE_LOW
self._attr_native_value = min(
int(voltage_diff / SURE_BATT_VOLTAGE_DIFF * 100), 100
self._attr_native_value = max(
0, min(int(voltage_diff / SURE_BATT_VOLTAGE_DIFF * 100), 100)
)
except KeyError, TypeError:
self._attr_native_value = None