Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
fix xiaomi vibration sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
doudz committed Jul 18, 2020
2 parents 384f72b + 6fab776 commit 1d3f29a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 6 additions & 1 deletion tests/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def test_fast_change(self):
self.assertEqual(device.get_property_value('onoff'), False)

def test_quirks(self):
device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'})
device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}, self.zigate)
device.set_attribute(1, 0x0000, {'attribute': 0xff01, 'lqi': 255,
'data': '0121130b0421a84305211300062401000000006429ed0965219513662be18201000a210000'})
self.assertEqual(device.get_property_value('xiaomi'), {1: 2835,
Expand All @@ -242,6 +242,11 @@ def test_quirks(self):
102: 99041,
10: 0})
self.assertEqual(device.get_property_value('battery_voltage'), 2.835)

def test_available_actions(self):
device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}, self.zigate)
device.set_attribute(1, 0, {'attribute': 5, 'lqi': 255, 'data': 'lumi.vibration.aq1'})
self.assertEqual(device.available_actions(), {1: []})


if __name__ == '__main__':
Expand Down
11 changes: 9 additions & 2 deletions zigate/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2512,7 +2512,8 @@ def available_actions(self, endpoint_id=None):
# except device 0x010a because Tradfri Outlet don't have level control
# but still have endpoint 8...
actions[ep_id].append(ACTIONS_LEVEL)
if 0x0101 in endpoint['in_clusters']:
if 0x0101 in endpoint['in_clusters'] and self.receiver_on_when_idle():
# because of xiaomi vibration sensor
actions[ep_id].append(ACTIONS_LOCK)
if 0x0102 in endpoint['in_clusters']:
actions[ep_id].append(ACTIONS_COVER)
Expand Down Expand Up @@ -3070,8 +3071,14 @@ def _handle_quirks(self, attribute):
LOGGER.debug('Handle special xiaomi attribute %s', attribute)
values = attribute['value']
# Battery voltage
self.set_attribute(0x0001, 0x0001, {'attribute': 0x0020, 'data': values[1] / 100.})
data_map = [(0x01, 0x0001, 0x0020, values[1] / 100.),]
# TODO: Handle more special attribute
if self.get_type(False) == 'lumi.sensor_motion.aq2':
data_map += [(0x01, 0x0406, 0x0000, values[100]),
(0x01, 0x0400, 0x0000, values[11])
]
for endpoint_id, cluster_id, attribute_id, value in data_map:
self.set_attribute(endpoint_id, cluster_id, {'attribute': attribute_id, 'data': value})

def _delay_change(self, endpoint_id, cluster_id, data):
'''
Expand Down
2 changes: 1 addition & 1 deletion zigate/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
#


__version__ = '0.40.2'
__version__ = '0.40.3'

0 comments on commit 1d3f29a

Please sign in to comment.