Weird Jinja bug broke the web panel load when using JSON parse, had to refactor it a bit to fix it

This commit is contained in:
Fabio Manganiello 2019-01-08 13:53:21 +01:00
parent d91e494940
commit 19eab381ae
2 changed files with 7 additions and 10 deletions

View File

@ -3,14 +3,7 @@
<script type="text/javascript">
window.config = window.config || {};
window.config.snapcast_hosts = {};
hosts = JSON.parse('{{ utils.to_json(utils.get_plugin("music.snapcast").backend_hosts) | safe }}');
ports = JSON.parse('{{ utils.to_json(utils.get_plugin("music.snapcast").backend_ports) | safe }}');
for (var i=0; i < hosts.length; i++) {
window.config.snapcast_hosts[hosts[i]] = ports[i];
}
window.config.snapcast_hosts = JSON.parse('{{ utils.get_plugin("music.snapcast").backend_hosts_json | safe }}');
</script>
<div id="snapcast-host-modal" class="modal snapcast-modal">

View File

@ -36,8 +36,12 @@ class MusicSnapcastPlugin(Plugin):
self._latest_req_id_lock = threading.RLock()
backend = get_backend('music.snapcast')
self.backend_hosts = backend.hosts if backend else [self.host]
self.backend_ports = backend.ports if backend else [self.port]
backend_hosts = backend.hosts if backend else [self.host]
backend_ports = backend.ports if backend else [self.port]
self.backend_hosts_json = json.dumps({
backend_hosts[i]: backend_ports[i]
for i in range(len(backend_hosts))
})
def _get_req_id(self):
with self._latest_req_id_lock: