From 636d1ced3aa10fab684bd73348c465b4292099fa Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 2 Nov 2022 22:49:19 +0100 Subject: [PATCH] A more robust way of splitting devices provided in the format --- platypush/plugins/zigbee/mqtt/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/platypush/plugins/zigbee/mqtt/__init__.py b/platypush/plugins/zigbee/mqtt/__init__.py index 48087c517b..a7a89b3e40 100644 --- a/platypush/plugins/zigbee/mqtt/__init__.py +++ b/platypush/plugins/zigbee/mqtt/__init__.py @@ -1,4 +1,5 @@ import json +import re import threading from queue import Queue @@ -1396,6 +1397,7 @@ class ZigbeeMqttPlugin(MqttPlugin): # lgtm [py/missing-call-to-init] ) def _get_switch_info(self, device: str): + device = self._ieee_address(device) switches_info = self._get_switches_info() info = switches_info.get(device) if info: @@ -1430,11 +1432,19 @@ class ZigbeeMqttPlugin(MqttPlugin): # lgtm [py/missing-call-to-init] ) @staticmethod - def _ieee_address(device: dict) -> str: + def _ieee_address(device: Union[dict, str]) -> str: # Entity value IDs are stored in the `
:` # format. Therefore, we need to split by `:` if we want to # retrieve the original address. - return device['ieee_address'].split(':')[0] + if isinstance(device, dict): + dev = device['ieee_address'] + else: + dev = device + + # IEEE address + property format + if re.search(r'^0x[0-9a-fA-F]{16}:', dev): + return dev.split(':')[0] + return dev @classmethod def _get_switch_meta(cls, device_info: dict) -> dict: