From 02abef71e3b772884698f21ac7f657b5a34273ce Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 2 Nov 2022 21:54:47 +0100 Subject: [PATCH] Fixes for zigbee devices polling - Don't publish a `get` request if the device has no exposed queriable attributes. - Perform the recursive build of the `get` request payload before checking for the `access` attribute. --- platypush/backend/zigbee/mqtt/__init__.py | 10 ++++++---- platypush/plugins/zigbee/mqtt/__init__.py | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/platypush/backend/zigbee/mqtt/__init__.py b/platypush/backend/zigbee/mqtt/__init__.py index 7fca6a676..930b76b86 100644 --- a/platypush/backend/zigbee/mqtt/__init__.py +++ b/platypush/backend/zigbee/mqtt/__init__.py @@ -246,10 +246,12 @@ class ZigbeeMqttBackend(MqttBackend): self.bus.post(ZigbeeMqttDeviceConnectedEvent(device=name, **event_args)) exposes = (device.get('definition', {}) or {}).get('exposes', []) - client.publish( - self.base_topic + '/' + name + '/get', - json.dumps(self._plugin.build_device_get_request(exposes)), - ) + payload = self._plugin.build_device_get_request(exposes) + if payload: + client.publish( + self.base_topic + '/' + name + '/get', + json.dumps(payload), + ) devices_copy = [*self._devices.keys()] for name in devices_copy: diff --git a/platypush/plugins/zigbee/mqtt/__init__.py b/platypush/plugins/zigbee/mqtt/__init__.py index 3988ec23f..48087c517 100644 --- a/platypush/plugins/zigbee/mqtt/__init__.py +++ b/platypush/plugins/zigbee/mqtt/__init__.py @@ -716,6 +716,9 @@ class ZigbeeMqttPlugin(MqttPlugin): # lgtm [py/missing-call-to-init] @staticmethod def build_device_get_request(values: List[Dict[str, Any]]) -> dict: def extract_value(value: dict, root: dict): + for feature in value.get('features', []): + extract_value(feature, root) + if not value.get('access', 1) & 0x4: # Property not readable/query-able return @@ -729,9 +732,6 @@ class ZigbeeMqttPlugin(MqttPlugin): # lgtm [py/missing-call-to-init] root[value['property']] = root.get(value['property'], {}) root = root[value['property']] - for feature in value['features']: - extract_value(feature, root) - ret = {} for value in values: extract_value(value, root=ret)