mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2025-12-20 14:37:01 +01:00
added first implementation of date/time
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import datetime
|
||||||
|
import locale
|
||||||
import appdaemon.plugins.hass.hassapi as hass
|
import appdaemon.plugins.hass.hassapi as hass
|
||||||
|
|
||||||
class NsPanelLovelanceUIManager(hass.Hass):
|
class NsPanelLovelanceUIManager(hass.Hass):
|
||||||
@@ -30,14 +32,22 @@ class NsPanelLovelanceUI:
|
|||||||
self.config = config
|
self.config = config
|
||||||
self.current_page_nr = 0
|
self.current_page_nr = 0
|
||||||
|
|
||||||
#Setup, mqtt subscription and callbacks
|
# Setup, mqtt subscription and callback
|
||||||
self.mqtt = self.api.get_plugin_api("MQTT")
|
self.mqtt = self.api.get_plugin_api("MQTT")
|
||||||
self.mqtt.mqtt_subscribe(topic=self.config["panelRecvTopic"])
|
self.mqtt.mqtt_subscribe(topic=self.config["panelRecvTopic"])
|
||||||
self.mqtt.listen_event(self.handle_mqtt_incoming_message, "MQTT_MESSAGE", topic=self.config["panelRecvTopic"], namespace='mqtt')
|
self.mqtt.listen_event(self.handle_mqtt_incoming_message, "MQTT_MESSAGE", topic=self.config["panelRecvTopic"], namespace='mqtt')
|
||||||
|
|
||||||
|
# Setup time callback
|
||||||
|
time = datetime.time(0, 0, 0)
|
||||||
|
self.api.run_minutely(self.update_time, time)
|
||||||
|
|
||||||
|
# Setup date callback
|
||||||
|
time = datetime.time(0, 0, 0)
|
||||||
|
self.api.run_daily(self.update_date, time)
|
||||||
|
self.update_date("")
|
||||||
|
|
||||||
def handle_mqtt_incoming_message(self, event_name, data, kwargs):
|
def handle_mqtt_incoming_message(self, event_name, data, kwargs):
|
||||||
#Parse Json Message from Tasmota and strip out message from nextion display
|
# Parse Json Message from Tasmota and strip out message from nextion display
|
||||||
msg = json.loads(data["payload"])["CustomRecv"]
|
msg = json.loads(data["payload"])["CustomRecv"]
|
||||||
self.api.log("Recived Message from Tasmota: %s", msg)
|
self.api.log("Recived Message from Tasmota: %s", msg)
|
||||||
|
|
||||||
@@ -47,6 +57,11 @@ class NsPanelLovelanceUI:
|
|||||||
# run action based on received command
|
# run action based on received command
|
||||||
# TODO: replace with match case after appdeamon container swiched to python 3.10 - https://pakstech.com/blog/python-switch-case/ - https://www.python.org/dev/peps/pep-0636/
|
# TODO: replace with match case after appdeamon container swiched to python 3.10 - https://pakstech.com/blog/python-switch-case/ - https://www.python.org/dev/peps/pep-0636/
|
||||||
if msg[0] == "event":
|
if msg[0] == "event":
|
||||||
|
|
||||||
|
if msg[1] == "startup":
|
||||||
|
self.api.log("received startup command")
|
||||||
|
# TODO: implement startup actions
|
||||||
|
|
||||||
if msg[1] == "pageOpen":
|
if msg[1] == "pageOpen":
|
||||||
# Calculate current page
|
# Calculate current page
|
||||||
recv_page = int(msg[2])
|
recv_page = int(msg[2])
|
||||||
@@ -70,6 +85,13 @@ class NsPanelLovelanceUI:
|
|||||||
def send_mqtt_msg(self,msg):
|
def send_mqtt_msg(self,msg):
|
||||||
self.mqtt.mqtt_publish(self.config["panelSendTopic"], msg)
|
self.mqtt.mqtt_publish(self.config["panelSendTopic"], msg)
|
||||||
|
|
||||||
|
def update_time(self, kwargs):
|
||||||
|
time = datetime.datetime.now().strftime(self.config["timeFormat"])
|
||||||
|
self.send_mqtt_msg("time,{0}".format(time))
|
||||||
|
|
||||||
|
def update_date(self, kwargs):
|
||||||
|
date = datetime.datetime.now().strftime(self.config["dateFormat"])
|
||||||
|
self.send_mqtt_msg("date,?{0}".format(date))
|
||||||
|
|
||||||
def generate_entities_item(self, item, item_nr, item_type):
|
def generate_entities_item(self, item, item_nr, item_type):
|
||||||
self.api.log("generating item command for %s with type %s", item, item_type)
|
self.api.log("generating item command for %s with type %s", item, item_type)
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
{
|
{
|
||||||
"panelRecvTopic": "tele/tasmota_NsPanelTerrasse/RESULT",
|
"panelRecvTopic": "tele/tasmota_NsPanelTerrasse/RESULT",
|
||||||
"panelSendTopic": "cmnd/tasmota_NsPanelTerrasse/CustomSend",
|
"panelSendTopic": "cmnd/tasmota_NsPanelTerrasse/CustomSend",
|
||||||
|
"locale": "de_DE",
|
||||||
|
"timeFormat": "%H : %M",
|
||||||
|
"dateFormat": "%A, %d. %B %Y",
|
||||||
"pages": [{
|
"pages": [{
|
||||||
"type": "cardEntities",
|
"type": "cardEntities",
|
||||||
"heading": "Rolladen",
|
"heading": "Rolladen",
|
||||||
|
|||||||
Reference in New Issue
Block a user