rgruebel / ha_zigbee2mqtt_networkmap

Custom Component for Homeassistant to show zigbee2mqtt Networkmap
169 stars 43 forks source link

Python script does not properly escape source.js #5

Closed mercballs closed 5 years ago

mercballs commented 5 years ago

I ran into an issue where I had apostrophes in a few of my entry names. This caused javascript errors when loading source.js because the python script does not properly escape the string when writing source.js to file. I am not very familiar with python, but i have provided a little hack to fix this issues. I;m sure there is probably a proper module to escape the string properly, but this works for me.

I changed line 32 of zigbee2mqtt_networkmap.py to this:

new_payload = payload.replace('\n', ' ').replace('\r', '').replace("'", r"\'")
f.write("var webhook = '"+webhook_url+"';\nvar last_update = new Date('"+last_update.strftime('%Y/%m/%d %H:%M:%S')+"');\nvar graph = \'"+new_payload+"\'")
rgruebel commented 5 years ago

Thank you, I've integrated your solution.