From 925831006bfbd511261ff5c647f7d59585556249 Mon Sep 17 00:00:00 2001 From: Mat Berchtold Date: Fri, 13 Aug 2021 22:49:25 +0200 Subject: [PATCH] Use the new zigbee2mqtt api to request a network map as documented here: https://www.zigbee2mqtt.io/information/mqtt_topics_and_message_structure.html With this change it is possible to use this integration when zigbee2mqtt is configured with: advanced: legacy_api: false --- custom_components/zigbee2mqtt_networkmap/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/custom_components/zigbee2mqtt_networkmap/__init__.py b/custom_components/zigbee2mqtt_networkmap/__init__.py index 4ab6858..626bf58 100644 --- a/custom_components/zigbee2mqtt_networkmap/__init__.py +++ b/custom_components/zigbee2mqtt_networkmap/__init__.py @@ -1,5 +1,6 @@ import homeassistant.loader as loader import os +import json from distutils.dir_util import copy_tree from datetime import datetime from aiohttp import web @@ -60,7 +61,9 @@ async def handle_webhook_check_update(hass, webhook_id, request): async def message_received(msg): """Handle new MQTT messages.""" # Save Response as JS variable in source.js - payload = msg.payload.replace('\n', ' ').replace( + jsonMessage = json.loads(msg.payload) + graphValue = jsonMessage["data"]["value"] + payload = graphValue.replace('\n', ' ').replace( '\r', '').replace("'", r"\'") last_update = datetime.now() f = open(hass.config.path( @@ -74,7 +77,7 @@ async def message_received(msg): tmpVar.last_update = last_update.strftime('%Y/%m/%d %H:%M:%S') # Subscribe our listener to the networkmap topic. - await mqtt.async_subscribe(topic+'/bridge/networkmap/graphviz', message_received) + await mqtt.async_subscribe(topic+'/bridge/response/networkmap', message_received) # Set the initial state. hass.states.async_set(entity_id, None) @@ -88,7 +91,7 @@ async def update_service(call): tmpVar.received_update = False tmpVar.update_data = None tmpVar.last_update = None - mqtt.async_publish(topic+'/bridge/networkmap/routes', 'graphviz') + mqtt.async_publish(topic+'/bridge/request/networkmap', '{"type": "graphviz", "routes": true}') hass.services.async_register(DOMAIN, 'update', update_service) return True