From a8286535ebddad9ef16befd9384773ff4a3b70d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B8yer=20Iversen?= Date: Sat, 18 May 2019 11:01:31 +0200 Subject: [PATCH] Upate xiaomi voltage parser, fix #23898 (#23962) --- homeassistant/components/xiaomi_aqara/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/xiaomi_aqara/__init__.py b/homeassistant/components/xiaomi_aqara/__init__.py index 22a8ec95c33fd..2ae69e3b58c0b 100644 --- a/homeassistant/components/xiaomi_aqara/__init__.py +++ b/homeassistant/components/xiaomi_aqara/__init__.py @@ -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