Skip to content

Commit

Permalink
check and log battery voltage limits
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG committed Jul 21, 2022
1 parent 5be7d75 commit 270a03e
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions motionblinds/motion_blinds.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,11 +1036,14 @@ def _calculate_battery_level(self, voltage):
# 3 cel battery pack (12.6V)
return round((voltage - 10.4) * 100 / (12.6 - 10.4), 0)

if voltage > 13.6:
if voltage > 13.6 and voltage <= 19.0:
# 4 cel battery pack (16.8V)
return round((voltage - 14.6) * 100 / (16.8 - 14.6), 0)

return 0.0
if voltage <= 0.0:
return 0.0

return 200.0

def _parse_response_common(self, response):
"""Parse the common part of a response form the blind."""
Expand Down Expand Up @@ -1165,6 +1168,13 @@ def _parse_response(self, response):
self._battery_voltage = None
else:
self._battery_level = self._calculate_battery_level(self._battery_voltage)
if self._battery_level <= 0.0 or self._battery_level >= 200.0:
_LOGGER.warning(
"Device with mac '%s' reported voltage '%s' outside of expected limits, got raw voltage: '%s'",
self.mac,
self._battery_voltage,
response["data"]["batteryLevel"],
)

if self._wireless_mode == WirelessMode.BiDirectionLimits:
return
Expand Down Expand Up @@ -1581,6 +1591,14 @@ def _parse_response(self, response):
"T": self._calculate_battery_level(self._battery_voltage["T"]),
"B": self._calculate_battery_level(self._battery_voltage["B"]),
}
if self._battery_level["T"] <= 0.0 or self._battery_level["T"] >= 200.0 or self._battery_level["B"] <= 0.0 or self._battery_level["B"] >= 200.0:
_LOGGER.warning(
"Device with mac '%s' reported voltage '%s' outside of expected limits, got raw voltages: '%s', '%s'",
self.mac,
self._battery_voltage,
response["data"]["batteryLevel_T"],
response["data"]["batteryLevel_B"],
)

except (KeyError, ValueError) as ex:
_LOGGER.exception(
Expand Down

0 comments on commit 270a03e

Please sign in to comment.