forked from cyrils/renogy-bt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_battery.py
25 lines (20 loc) · 892 Bytes
/
example_battery.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
import logging
import configparser
import os
from renogybt import BatteryClient
from renogybt import DataLogger
logging.basicConfig(level=logging.DEBUG)
config_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'config.ini')
config = configparser.ConfigParser()
config.read(config_file)
data_logger: DataLogger = DataLogger(config)
def on_data_received(client: BatteryClient, data):
logging.debug("{} => {}".format(client.device.alias(), data))
if config['remote_logging'].getboolean('enabled'):
data_logger.log_remote(json_data=data)
if config['mqtt'].getboolean('enabled'):
data_logger.log_mqtt(json_data=data)
if not config['device'].getboolean('enable_polling'):
client.disconnect()
logging.info(f"Starting client: {config['device']['alias']} => {config['device']['mac_addr']}")
BatteryClient(config, on_data_received).connect()