Skip to content

Commit

Permalink
Upate xiaomi voltage parser, fix #23898
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielhiversen authored May 18, 2019
1 parent c483e44 commit a192135
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions homeassistant/components/xiaomi_aqara/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,16 @@ def push_data(self, data, raw_data):

def parse_voltage(self, data):
"""Parse battery level data sent by gateway."""
if 'voltage' not in data:
if 'voltage' in data:
voltage_key = 'voltage'
elif 'battery_voltage' in data:
voltage_key = 'battery_voltage'
else:
return False

max_volt = 3300
min_volt = 2800
voltage = data['voltage']
voltage = data[voltage_key]
voltage = min(voltage, max_volt)
voltage = max(voltage, min_volt)
percent = ((voltage - min_volt) / (max_volt - min_volt)) * 100
Expand Down

0 comments on commit a192135

Please sign in to comment.