Fixed handling of possible null device definition in zigbee.mqtt

This commit is contained in:
Fabio Manganiello 2022-04-05 00:31:04 +02:00
parent 28b3672432
commit 0dac2c0e92
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -160,6 +160,10 @@ class ZigbeeMqttPlugin(MqttPlugin, SwitchPlugin): # lgtm [py/missing-call-to-in
compatible_entities = [] compatible_entities = []
for dev in devices: for dev in devices:
if not dev:
continue
dev_def = dev.get("definition") or {}
dev_info = { dev_info = {
"type": dev.get("type"), "type": dev.get("type"),
"date_code": dev.get("date_code"), "date_code": dev.get("date_code"),
@ -168,10 +172,10 @@ class ZigbeeMqttPlugin(MqttPlugin, SwitchPlugin): # lgtm [py/missing-call-to-in
"power_source": dev.get("power_source"), "power_source": dev.get("power_source"),
"software_build_id": dev.get("software_build_id"), "software_build_id": dev.get("software_build_id"),
"model_id": dev.get("model_id"), "model_id": dev.get("model_id"),
"model": dev.get("definition", {}).get("model"), "model": dev_def.get("model"),
"vendor": dev.get("definition", {}).get("vendor"), "vendor": dev_def.get("vendor"),
"supported": dev.get("supported"), "supported": dev.get("supported"),
"description": dev.get("definition", {}).get("description"), "description": dev_def.get("description"),
} }
switch_info = self._get_switch_info(dev) switch_info = self._get_switch_info(dev)
@ -185,7 +189,7 @@ class ZigbeeMqttPlugin(MqttPlugin, SwitchPlugin): # lgtm [py/missing-call-to-in
) )
) )
return compatible_entities return super().transform_entities(compatible_entities) # type: ignore
def _get_network_info(self, **kwargs): def _get_network_info(self, **kwargs):
self.logger.info('Fetching Zigbee network information') self.logger.info('Fetching Zigbee network information')
@ -738,10 +742,8 @@ class ZigbeeMqttPlugin(MqttPlugin, SwitchPlugin): # lgtm [py/missing-call-to-in
if not devices: if not devices:
devices = { devices = {
[
device['friendly_name'] or device['ieee_address'] device['friendly_name'] or device['ieee_address']
for device in self.devices(**kwargs).output for device in self.devices(**kwargs).output
]
} }
def worker(device: str, q: Queue): def worker(device: str, q: Queue):