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.
This commit is contained in:
Fabio Manganiello 2022-11-02 21:54:47 +01:00
parent 64513be6b8
commit 02abef71e3
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 9 additions and 7 deletions

View file

@ -246,9 +246,11 @@ class ZigbeeMqttBackend(MqttBackend):
self.bus.post(ZigbeeMqttDeviceConnectedEvent(device=name, **event_args)) self.bus.post(ZigbeeMqttDeviceConnectedEvent(device=name, **event_args))
exposes = (device.get('definition', {}) or {}).get('exposes', []) exposes = (device.get('definition', {}) or {}).get('exposes', [])
payload = self._plugin.build_device_get_request(exposes)
if payload:
client.publish( client.publish(
self.base_topic + '/' + name + '/get', self.base_topic + '/' + name + '/get',
json.dumps(self._plugin.build_device_get_request(exposes)), json.dumps(payload),
) )
devices_copy = [*self._devices.keys()] devices_copy = [*self._devices.keys()]

View file

@ -716,6 +716,9 @@ class ZigbeeMqttPlugin(MqttPlugin): # lgtm [py/missing-call-to-init]
@staticmethod @staticmethod
def build_device_get_request(values: List[Dict[str, Any]]) -> dict: def build_device_get_request(values: List[Dict[str, Any]]) -> dict:
def extract_value(value: dict, root: 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: if not value.get('access', 1) & 0x4:
# Property not readable/query-able # Property not readable/query-able
return return
@ -729,9 +732,6 @@ class ZigbeeMqttPlugin(MqttPlugin): # lgtm [py/missing-call-to-init]
root[value['property']] = root.get(value['property'], {}) root[value['property']] = root.get(value['property'], {})
root = root[value['property']] root = root[value['property']]
for feature in value['features']:
extract_value(feature, root)
ret = {} ret = {}
for value in values: for value in values:
extract_value(value, root=ret) extract_value(value, root=ret)