Skip to content

Commit

Permalink
Fix battery reading in SOMA API (home-assistant#99403)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Resch <[email protected]>
  • Loading branch information
ratsept and edenhaus authored Sep 4, 2023
1 parent de1de92 commit b953673
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions homeassistant/components/soma/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ def native_value(self):
async def async_update(self) -> None:
"""Update the sensor with the latest data."""
response = await self.get_battery_level_from_api()

# https://support.somasmarthome.com/hc/en-us/articles/360026064234-HTTP-API
# battery_level response is expected to be min = 360, max 410 for
# 0-100% levels above 410 are consider 100% and below 360, 0% as the
# device considers 360 the minimum to move the motor.
_battery = round(2 * (response["battery_level"] - 360))
_battery = response.get("battery_percentage")
if _battery is None:
# https://support.somasmarthome.com/hc/en-us/articles/360026064234-HTTP-API
# battery_level response is expected to be min = 360, max 410 for
# 0-100% levels above 410 are consider 100% and below 360, 0% as the
# device considers 360 the minimum to move the motor.
_battery = round(2 * (response["battery_level"] - 360))
battery = max(min(100, _battery), 0)
self.battery_state = battery

0 comments on commit b953673

Please sign in to comment.