From ff4204244b28361aba0aa0c1a827cd40fd7b2425 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Mon, 8 Oct 2018 10:37:27 +0200 Subject: [PATCH] Fix data_key and power_consumed attribute of the Aqara Wall Switch (Closes: #16457) (#17235) --- homeassistant/components/switch/xiaomi_aqara.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/switch/xiaomi_aqara.py b/homeassistant/components/switch/xiaomi_aqara.py index 17265d5dfa2..2d2ba244ba0 100644 --- a/homeassistant/components/switch/xiaomi_aqara.py +++ b/homeassistant/components/switch/xiaomi_aqara.py @@ -16,6 +16,7 @@ ATTR_IN_USE = 'in_use' LOAD_POWER = 'load_power' POWER_CONSUMED = 'power_consumed' +ENERGY_CONSUMED = 'energy_consumed' IN_USE = 'inuse' @@ -57,8 +58,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None): 'channel_1', False, gateway)) elif model in ['86plug', 'ctrl_86plug', 'ctrl_86plug.aq1']: + if 'proto' not in device or int(device['proto'][0:1]) == 1: + data_key = 'status' + else: + data_key = 'channel_0' devices.append(XiaomiGenericSwitch(device, 'Wall Plug', - 'status', True, gateway)) + data_key, True, gateway)) add_entities(devices) @@ -122,8 +127,12 @@ class XiaomiGenericSwitch(XiaomiDevice, SwitchDevice): self._in_use = int(data[IN_USE]) if not self._in_use: self._load_power = 0 - if POWER_CONSUMED in data: - self._power_consumed = round(float(data[POWER_CONSUMED]), 2) + + for key in [POWER_CONSUMED, ENERGY_CONSUMED]: + if key in data: + self._power_consumed = round(float(data[key]), 2) + break + if LOAD_POWER in data: self._load_power = round(float(data[LOAD_POWER]), 2)