From d1a60010f8723d23527e4457009fda712053ad8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20RAMAGE?= Date: Thu, 16 Jul 2020 22:37:51 +0200 Subject: [PATCH 1/2] handle xiaomi special attribute --- tests/test_devices.py | 2 +- zigate/core.py | 8 +++++++- zigate/version.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_devices.py b/tests/test_devices.py index 00ac7296..ae1378e9 100644 --- a/tests/test_devices.py +++ b/tests/test_devices.py @@ -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, diff --git a/zigate/core.py b/zigate/core.py index 12dd7d3f..5e01bfcb 100644 --- a/zigate/core.py +++ b/zigate/core.py @@ -3070,8 +3070,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): ''' diff --git a/zigate/version.py b/zigate/version.py index c081481d..a1948701 100644 --- a/zigate/version.py +++ b/zigate/version.py @@ -6,4 +6,4 @@ # -__version__ = '0.40.2' +__version__ = '0.40.3' From 6fab7763531e8313cc8f8403e37f70e3e808df88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20RAMAGE?= Date: Sat, 18 Jul 2020 08:04:58 +0200 Subject: [PATCH 2/2] Fix xiaomi vibration sensor --- tests/test_devices.py | 5 +++++ zigate/core.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_devices.py b/tests/test_devices.py index ae1378e9..5bccdc04 100644 --- a/tests/test_devices.py +++ b/tests/test_devices.py @@ -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__': diff --git a/zigate/core.py b/zigate/core.py index 5e01bfcb..0bececfc 100644 --- a/zigate/core.py +++ b/zigate/core.py @@ -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)