Add last action to xiaomi aqara button (#10131)
This commit is contained in:
parent
c191c13f3a
commit
2561efe45d
1 changed files with 10 additions and 0 deletions
|
@ -282,9 +282,17 @@ class XiaomiButton(XiaomiBinarySensor):
|
||||||
def __init__(self, device, name, data_key, hass, xiaomi_hub):
|
def __init__(self, device, name, data_key, hass, xiaomi_hub):
|
||||||
"""Initialize the XiaomiButton."""
|
"""Initialize the XiaomiButton."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
|
self._last_action = None
|
||||||
XiaomiBinarySensor.__init__(self, device, name, xiaomi_hub,
|
XiaomiBinarySensor.__init__(self, device, name, xiaomi_hub,
|
||||||
data_key, None)
|
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):
|
def parse_data(self, data):
|
||||||
"""Parse data sent by gateway."""
|
"""Parse data sent by gateway."""
|
||||||
value = data.get(self._data_key)
|
value = data.get(self._data_key)
|
||||||
|
@ -310,6 +318,8 @@ class XiaomiButton(XiaomiBinarySensor):
|
||||||
'entity_id': self.entity_id,
|
'entity_id': self.entity_id,
|
||||||
'click_type': click_type
|
'click_type': click_type
|
||||||
})
|
})
|
||||||
|
self._last_action = click_type
|
||||||
|
|
||||||
if value in ['long_click_press', 'long_click_release']:
|
if value in ['long_click_press', 'long_click_release']:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue