mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
parent
05146badf1
commit
a8286535eb
@ -294,11 +294,16 @@ class XiaomiDevice(Entity):
|
|||||||
|
|
||||||
def parse_voltage(self, data):
|
def parse_voltage(self, data):
|
||||||
"""Parse battery level data sent by gateway."""
|
"""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
|
return False
|
||||||
|
|
||||||
max_volt = 3300
|
max_volt = 3300
|
||||||
min_volt = 2800
|
min_volt = 2800
|
||||||
voltage = data['voltage']
|
voltage = data[voltage_key]
|
||||||
voltage = min(voltage, max_volt)
|
voltage = min(voltage, max_volt)
|
||||||
voltage = max(voltage, min_volt)
|
voltage = max(voltage, min_volt)
|
||||||
percent = ((voltage - min_volt) / (max_volt - min_volt)) * 100
|
percent = ((voltage - min_volt) / (max_volt - min_volt)) * 100
|
||||||
|
Loading…
x
Reference in New Issue
Block a user