mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
add last_action for xiaomi cube (#9897)
This commit is contained in:
parent
9be7763144
commit
82c7195484
@ -12,6 +12,7 @@ ATTR_OPEN_SINCE = 'Open since'
|
|||||||
|
|
||||||
MOTION = 'motion'
|
MOTION = 'motion'
|
||||||
NO_MOTION = 'no_motion'
|
NO_MOTION = 'no_motion'
|
||||||
|
ATTR_LAST_ACTION = 'last_action'
|
||||||
ATTR_NO_MOTION_SINCE = 'No motion since'
|
ATTR_NO_MOTION_SINCE = 'No motion since'
|
||||||
|
|
||||||
DENSITY = 'density'
|
DENSITY = 'density'
|
||||||
@ -327,10 +328,18 @@ class XiaomiCube(XiaomiBinarySensor):
|
|||||||
def __init__(self, device, hass, xiaomi_hub):
|
def __init__(self, device, hass, xiaomi_hub):
|
||||||
"""Initialize the Xiaomi Cube."""
|
"""Initialize the Xiaomi Cube."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
|
self._last_action = None
|
||||||
self._state = False
|
self._state = False
|
||||||
XiaomiBinarySensor.__init__(self, device, 'Cube', xiaomi_hub,
|
XiaomiBinarySensor.__init__(self, device, 'Cube', xiaomi_hub,
|
||||||
None, None)
|
None, 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."""
|
||||||
if 'status' in data:
|
if 'status' in data:
|
||||||
@ -338,6 +347,7 @@ class XiaomiCube(XiaomiBinarySensor):
|
|||||||
'entity_id': self.entity_id,
|
'entity_id': self.entity_id,
|
||||||
'action_type': data['status']
|
'action_type': data['status']
|
||||||
})
|
})
|
||||||
|
self._last_action = data['status']
|
||||||
|
|
||||||
if 'rotate' in data:
|
if 'rotate' in data:
|
||||||
self._hass.bus.fire('cube_action', {
|
self._hass.bus.fire('cube_action', {
|
||||||
@ -345,4 +355,6 @@ class XiaomiCube(XiaomiBinarySensor):
|
|||||||
'action_type': 'rotate',
|
'action_type': 'rotate',
|
||||||
'action_value': float(data['rotate'].replace(",", "."))
|
'action_value': float(data['rotate'].replace(",", "."))
|
||||||
})
|
})
|
||||||
return False
|
self._last_action = 'rotate'
|
||||||
|
|
||||||
|
return True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user