mirror of
https://github.com/esphome/esphome.git
synced 2025-09-05 12:52:19 +01:00
Perform merges when substituting dict keys (#3062)
This commit is contained in:
@@ -23,3 +23,23 @@ def read_config_file(path):
|
||||
return data["content"]
|
||||
|
||||
return read_file(path)
|
||||
|
||||
|
||||
def merge_config(full_old, full_new):
|
||||
def merge(old, new):
|
||||
# pylint: disable=no-else-return
|
||||
if isinstance(new, dict):
|
||||
if not isinstance(old, dict):
|
||||
return new
|
||||
res = old.copy()
|
||||
for k, v in new.items():
|
||||
res[k] = merge(old[k], v) if k in old else v
|
||||
return res
|
||||
elif isinstance(new, list):
|
||||
if not isinstance(old, list):
|
||||
return new
|
||||
return old + new
|
||||
|
||||
return new
|
||||
|
||||
return merge(full_old, full_new)
|
||||
|
Reference in New Issue
Block a user