-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
58 lines (48 loc) · 1.6 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
Run Module
Starts up the agent
"""
import datetime
import sys
from apscheduler.schedulers.blocking import BlockingScheduler # type: ignore
from loguru import logger
from env.env import Env
from sc23dci import sc23dci
def set_log_level(level):
"""
Sets the logger to the given verbosity
:param level: The verbosity
- TRACE
- DEBUG
- INFO
- SUCCESS
- WARNING
- ERROR
- CRITICAL
"""
if level not in ['TRACE', 'DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL']:
level = 'INFO'
logger.remove()
logger.add("/var/log/sc23dci.log", rotation="500 KB", level="INFO")
logger.add(sys.stderr, level=level)
if __name__ == '__main__':
set_log_level(Env.get_env('LOG_LEVEL'))
Env.check_missing()
logger.info('Creating SC23DCI instance')
ac = sc23dci.SC23DCI(Env.get_env('SC23DCI_IP'))
logger.info('Creating MqttClient instance')
ac.set_mqtt_client(Env.get_env('MQTT_BROKER_IP'), Env.get_env('MQTT_BROKER_PORT'))
ac.mqtt_enable_publish_temperature(Env.get_env('MQTT_TOPIC_TEMPERATURE'))
ac.mqtt_enable_publish_power_state(Env.get_env('MQTT_TOPIC_POWERSTATE'))
ac.mqtt_enable_publish_all(Env.get_env('MQTT_TOPIC_ALL'))
logger.info('Scheduler initialization started')
taskScheduler = scheduler = BlockingScheduler(daemon=True)
job = taskScheduler.add_job(
ac.refresh,
'interval',
seconds=int(Env.get_env('SC23DCI_POLL_INTERVAL')),
next_run_time=datetime.datetime.now()
)
logger.info('Service started successful')
logger.info('Service is running')
taskScheduler.start()