* accept DCU serial number starting with '410' * determine sensor-list by serial number * adapt unit test for DCU support * send first batterie measurements to home assistant * add test case for sensor-list==3036 * add more registers for batteries * improve error logging (Monitoring SN) * update the add-on repro only for one stage * add configuration for energie storages * add License and Readme file to the add-on * addon: add date and time to dev and debug docker container tag * disable duplicate code check for config.py * cleanup unit test, remove trailing whitespaces * update changelog * fix example config for batteries * cleanup config.jinja template * fix comments * improve help texts
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
'''Config Reader module which handles *.json config files'''
|
|
|
|
import json
|
|
from cnf.config import ConfigIfc
|
|
|
|
|
|
class ConfigReadJson(ConfigIfc):
|
|
'''Reader for json config files'''
|
|
def __init__(self, cnf_file='/data/options.json'):
|
|
'''Read a json file and add the settings to the config'''
|
|
if not isinstance(cnf_file, str):
|
|
return
|
|
self.cnf_file = cnf_file
|
|
super().__init__()
|
|
|
|
def convert_inv(self, conf, inv):
|
|
if 'serial' in inv:
|
|
snr = inv['serial']
|
|
del inv['serial']
|
|
conf[snr] = {}
|
|
|
|
for key, val in inv.items():
|
|
self._extend_key(conf[snr], key, val)
|
|
|
|
def convert_inv_arr(self, conf, key, val: list):
|
|
if key not in conf:
|
|
conf[key] = {}
|
|
for elm in val:
|
|
self.convert_inv(conf[key], elm)
|
|
|
|
def convert_to_obj(self, data):
|
|
conf = {}
|
|
for key, val in data.items():
|
|
if (key == 'inverters' or key == 'batteries') and \
|
|
isinstance(val, list):
|
|
self.convert_inv_arr(conf, key, val)
|
|
else:
|
|
self._extend_key(conf, key, val)
|
|
return conf
|
|
|
|
def get_config(self) -> dict:
|
|
with open(self.cnf_file) as f:
|
|
data = json.load(f)
|
|
return self.convert_to_obj(data)
|
|
|
|
def descr(self):
|
|
return self.cnf_file
|