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: blacklight
GPG Key ID: D90FBA7F76362774
2 changed files with 9 additions and 7 deletions

View File

@ -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:

View File

@ -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)