clear daily energy production at midnight

This commit is contained in:
Stefan Allius
2024-04-06 00:04:25 +02:00
parent d6cc211a51
commit 8fc8a29be2
9 changed files with 327 additions and 176 deletions

View File

@@ -1,6 +1,10 @@
import logging
import json
from mqtt import Mqtt
from aiocron import crontab
from infos import ClrAtMidnight
logger_mqtt = logging.getLogger('mqtt')
class Schedule:
@@ -10,16 +14,15 @@ class Schedule:
def start(cls):
logging.info("Scheduler init")
cls.mqtt = Mqtt(None)
# json.dumps(i.db['total']) == json.dumps({'Daily_Generation': 0.0})
# json.dumps(i.db['input']) == json.dumps({"pv1": {"Daily_Generation": 0.0}, "pv2": {"Daily_Generation": 0.0}, "pv3": {"Daily_Generation": 0.0}, "pv4": {"Daily_Generation": 0.0}}) # noqa: E501
crontab('0 0 * * *', func=cls.atmidnight, start=True)
# crontab('*/5 * * * *', func=cls.atmidnight, start=True)
async def atmidnight():
logging.info("Scheduler is working")
# db = self.db.db
# if key in db and self.new_data[key]:
# data_json = json.dumps(db[key])
# node_id = self.node_id
# logger_mqtt.debug(f'{key}: {data_json}')
# await cls.mqtt.publish(f'{self.entity_prfx}{node_id}{key}', data_json) # noqa: E501
@classmethod
async def atmidnight(cls):
logging.info("Clear daily counters at midnight")
for key, data in ClrAtMidnight.elm():
logger_mqtt.debug(f'{key}: {data}')
data_json = json.dumps(data)
await cls.mqtt.publish(f"{key}", data_json)