Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the new zigbee2mqtt api #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions custom_components/zigbee2mqtt_networkmap/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand All @@ -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