mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2026-02-26 06:02:14 +01:00
.
This commit is contained in:
@@ -11,6 +11,10 @@ from uuid import getnode as get_mac
|
|||||||
from panel import LovelaceUIPanel
|
from panel import LovelaceUIPanel
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from watchdog.observers import Observer
|
||||||
|
from watchdog.events import FileSystemEventHandler
|
||||||
|
|
||||||
|
|
||||||
settings = {}
|
settings = {}
|
||||||
panels = {}
|
panels = {}
|
||||||
last_settings_file_mtime = 0
|
last_settings_file_mtime = 0
|
||||||
@@ -60,13 +64,10 @@ def on_message(client, userdata, msg):
|
|||||||
"Something went wrong when processing the exception message, couldn't decode payload to utf-8.")
|
"Something went wrong when processing the exception message, couldn't decode payload to utf-8.")
|
||||||
|
|
||||||
|
|
||||||
def get_config():
|
def get_config(file):
|
||||||
global settings
|
global settings
|
||||||
|
|
||||||
CONFIG_FILE = os.getenv('CONFIG_FILE')
|
with open(file, 'r', encoding="utf8") as file:
|
||||||
if not CONFIG_FILE:
|
|
||||||
CONFIG_FILE = 'config.yml'
|
|
||||||
with open(CONFIG_FILE, 'r', encoding="utf8") as file:
|
|
||||||
settings = yaml.safe_load(file)
|
settings = yaml.safe_load(file)
|
||||||
|
|
||||||
if not settings.get("mqtt_username"):
|
if not settings.get("mqtt_username"):
|
||||||
@@ -92,8 +93,8 @@ def get_config():
|
|||||||
print(settings["home_assistant_address"])
|
print(settings["home_assistant_address"])
|
||||||
print(settings["is_addon"])
|
print(settings["is_addon"])
|
||||||
|
|
||||||
def connect_and_loop():
|
def connect():
|
||||||
global settings, home_assistant, panels
|
global settings, home_assistant, client
|
||||||
client.on_connect = on_connect
|
client.on_connect = on_connect
|
||||||
client.on_message = on_message
|
client.on_message = on_message
|
||||||
client.username_pw_set(
|
client.username_pw_set(
|
||||||
@@ -122,6 +123,15 @@ def connect_and_loop():
|
|||||||
|
|
||||||
libs.panel_cmd.init(client)
|
libs.panel_cmd.init(client)
|
||||||
|
|
||||||
|
setup_panels()
|
||||||
|
|
||||||
|
def loop():
|
||||||
|
global client
|
||||||
|
# Loop MQTT
|
||||||
|
client.loop_forever()
|
||||||
|
|
||||||
|
def setup_panels():
|
||||||
|
global settings, panels
|
||||||
# Create NsPanel object
|
# Create NsPanel object
|
||||||
for name, settings_panel in settings["nspanels"].items():
|
for name, settings_panel in settings["nspanels"].items():
|
||||||
if "timeZone" not in settings_panel:
|
if "timeZone" not in settings_panel:
|
||||||
@@ -133,10 +143,11 @@ def connect_and_loop():
|
|||||||
libs.panel_cmd.page_type(
|
libs.panel_cmd.page_type(
|
||||||
settings_panel["panelSendTopic"], "pageStartup")
|
settings_panel["panelSendTopic"], "pageStartup")
|
||||||
|
|
||||||
# Loop MQTT
|
|
||||||
client.loop_forever()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
get_config()
|
CONFIG_FILE = os.getenv('CONFIG_FILE')
|
||||||
# print(settings)
|
if not CONFIG_FILE:
|
||||||
connect_and_loop()
|
CONFIG_FILE = 'config.yml'
|
||||||
|
get_config(CONFIG_FILE)
|
||||||
|
|
||||||
|
connect()
|
||||||
|
loop()
|
||||||
|
|||||||
Reference in New Issue
Block a user