clear daily energy production at midnight
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user