fix config override bug

This commit is contained in:
joBr99
2022-04-16 09:02:25 +02:00
parent f0b2d087fb
commit 1e34eda1ac
2 changed files with 63 additions and 65 deletions

View File

@@ -1,5 +1,3 @@
from helper import dict_recursive_update
class Entity(object): class Entity(object):
def __init__(self, entity_input_config): def __init__(self, entity_input_config):
if type(entity_input_config) is not dict: if type(entity_input_config) is not dict:
@@ -47,7 +45,22 @@ class Card(object):
class LuiBackendConfig(object): class LuiBackendConfig(object):
_DEFAULT_CONFIG = { def dict_recursive_update(self, source: dict, target: dict) -> dict:
for sk, sv in source.items():
if sk in target and isinstance(target[sk], dict):
target[sk] = self.dict_recursive_update(sv, target[sk])
else:
target[sk] = sv
return target
def __init__(self, ha_api, config_in):
self._ha_api = ha_api
self._config = {}
self._config_cards = []
self._config_screensaver = None
self._config_hidden_cards = []
self._DEFAULT_CONFIG = {
'panelRecvTopic': "tele/tasmota_your_mqtt_topic/RESULT", 'panelRecvTopic': "tele/tasmota_your_mqtt_topic/RESULT",
'panelSendTopic': "cmnd/tasmota_your_mqtt_topic/CustomSend", 'panelSendTopic': "cmnd/tasmota_your_mqtt_topic/CustomSend",
'updateMode': "auto-notify", 'updateMode': "auto-notify",
@@ -99,19 +112,12 @@ class LuiBackendConfig(object):
'hiddenCards': [] 'hiddenCards': []
} }
def __init__(self, ha_api, config_in):
self._ha_api = ha_api
self._config = {}
self._config_cards = []
self._config_screensaver = None
self._config_hidden_cards = []
self.load(config_in) self.load(config_in)
def load(self, inconfig): def load(self, inconfig):
self._ha_api.log(f"Input config: {inconfig}") self._ha_api.log("Input config: %s", inconfig)
self._config = dict_recursive_update(inconfig, self._DEFAULT_CONFIG) self._config = self.dict_recursive_update(inconfig, self._DEFAULT_CONFIG)
self._ha_api.log(f"Loaded config: {self._config}") self._ha_api.log("Loaded config: %s", self._config)
# parse cards displayed on panel # parse cards displayed on panel
pos = 0 pos = 0

View File

@@ -55,11 +55,3 @@ def get_attr_safe(entity, attr, default):
if res is None: if res is None:
res = default res = default
return res return res
def dict_recursive_update(source: dict, target: dict) -> dict:
for sk, sv in source.items():
if sk in target and isinstance(target[sk], dict):
target[sk] = dict_recursive_update(sv, target[sk])
else:
target[sk] = sv
return target