Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions homeassistant/components/binary_sensor/xiaomi_aqara.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
'dual_channel', hass, gateway))
elif model in ['cube', 'sensor_cube', 'sensor_cube.aqgl01']:
devices.append(XiaomiCube(device, hass, gateway))
elif model == 'lock.aq1':
devices.append(XiaomiLock(device, hass, gateway))
add_devices(devices)


Expand Down Expand Up @@ -381,3 +383,37 @@ def parse_data(self, data, raw_data):
self._last_action = 'rotate'

return True


class XiaomiLock(XiaomiBinarySensor):
"""Representation of a Xiaomi Lock."""

def __init__(self, device, hass, xiaomi_hub):
"""Initialize the Xiaomi Lock."""
self._hass = hass
self._last_action = None
self._state = False
XiaomiBinarySensor.__init__(self, device, 'Lock', xiaomi_hub,
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, raw_data):
"""Parse data sent by gateway."""
for action_type in ['fing_verified', 'psw_verified', 'card_verified',
'verified_wrong']:
if type in data:
self._hass.bus.fire('lock_action', {
'entity_id': self.entity_id,
'action_type': action_type,
'action_value': data[action_type]
})
self._last_action = action_type
break

return True