From 2561efe45d117e5f15aaa611488c06b40f301e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B8yer=20Iversen?= Date: Thu, 26 Oct 2017 18:46:29 +0200 Subject: [PATCH] Add last action to xiaomi aqara button (#10131) --- homeassistant/components/binary_sensor/xiaomi_aqara.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/homeassistant/components/binary_sensor/xiaomi_aqara.py b/homeassistant/components/binary_sensor/xiaomi_aqara.py index 1ff432a937f..eee24b8ad1c 100644 --- a/homeassistant/components/binary_sensor/xiaomi_aqara.py +++ b/homeassistant/components/binary_sensor/xiaomi_aqara.py @@ -282,9 +282,17 @@ class XiaomiButton(XiaomiBinarySensor): def __init__(self, device, name, data_key, hass, xiaomi_hub): """Initialize the XiaomiButton.""" self._hass = hass + self._last_action = None XiaomiBinarySensor.__init__(self, device, name, xiaomi_hub, data_key, None) + @property + def device_state_attributes(self): + """Return the state attributes.""" + attrs = {ATTR_LAST_ACTION: self._last_action} + attrs.update(super().device_state_attributes) + return attrs + def parse_data(self, data): """Parse data sent by gateway.""" value = data.get(self._data_key) @@ -310,6 +318,8 @@ class XiaomiButton(XiaomiBinarySensor): 'entity_id': self.entity_id, 'click_type': click_type }) + self._last_action = click_type + if value in ['long_click_press', 'long_click_release']: return True return False