From 3a92bf59ca28c68794fe501c91a4d0a3cbeee967 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 4 Dec 2022 20:48:42 +0100 Subject: [PATCH] Support for the new way of reporting events on ZWaveJS-UI. The most recent versions of ZwaveJS-UI don't send the `hexId` of the node on node change events. We have therefore to infer it from the reported `dbLink`. --- platypush/plugins/zwave/mqtt/__init__.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/platypush/plugins/zwave/mqtt/__init__.py b/platypush/plugins/zwave/mqtt/__init__.py index e401e444..ef76717d 100644 --- a/platypush/plugins/zwave/mqtt/__init__.py +++ b/platypush/plugins/zwave/mqtt/__init__.py @@ -17,6 +17,7 @@ from typing import ( Type, Union, ) +from urllib.parse import parse_qs, urlparse from platypush.entities import Entity from platypush.entities.batteries import Battery @@ -345,9 +346,21 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin): if node.get('zwavePlusVersion'): capabilities += ['zwave_plus'] + db_link = node.get('dbLink', node.get('db_link', '')) + device_id = node.get('hexId') + if not device_id: + if db_link: + device_id = ':'.join( + parse_qs(urlparse(db_link).query) + .get('jumpTo', '')[0] + .split(':')[:-1] + ) + else: + device_id = str(node['id']) + return { 'node_id': node['id'], - 'device_id': node['hexId'].replace('0x', ''), + 'device_id': device_id.replace('0x', ''), 'name': node.get('name'), 'capabilities': capabilities, 'manufacturer_id': '0x{:04x}'.format(node['manufacturerId'])