Fix battery reading in SOMA API (#99403)
Co-authored-by: Robert Resch <robert@resch.dev>pull/99741/head
parent
2a5f8ee4a7
commit
852589f025
|
@ -43,11 +43,12 @@ class SomaSensor(SomaEntity, SensorEntity):
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Update the sensor with the latest data."""
|
"""Update the sensor with the latest data."""
|
||||||
response = await self.get_battery_level_from_api()
|
response = await self.get_battery_level_from_api()
|
||||||
|
_battery = response.get("battery_percentage")
|
||||||
# https://support.somasmarthome.com/hc/en-us/articles/360026064234-HTTP-API
|
if _battery is None:
|
||||||
# battery_level response is expected to be min = 360, max 410 for
|
# https://support.somasmarthome.com/hc/en-us/articles/360026064234-HTTP-API
|
||||||
# 0-100% levels above 410 are consider 100% and below 360, 0% as the
|
# battery_level response is expected to be min = 360, max 410 for
|
||||||
# device considers 360 the minimum to move the motor.
|
# 0-100% levels above 410 are consider 100% and below 360, 0% as the
|
||||||
_battery = round(2 * (response["battery_level"] - 360))
|
# device considers 360 the minimum to move the motor.
|
||||||
|
_battery = round(2 * (response["battery_level"] - 360))
|
||||||
battery = max(min(100, _battery), 0)
|
battery = max(min(100, _battery), 0)
|
||||||
self.battery_state = battery
|
self.battery_state = battery
|
||||||
|
|
Loading…
Reference in New Issue