2019-04-22 21:56:30 +02:00
|
|
|
import json
|
2019-05-11 11:41:09 +02:00
|
|
|
import os
|
2019-04-22 21:56:30 +02:00
|
|
|
|
2019-10-24 21:53:42 +02:00
|
|
|
from esphome.core import CORE
|
|
|
|
from esphome.helpers import read_file
|
2019-04-22 21:56:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
def read_config_file(path):
|
2019-12-07 18:28:55 +01:00
|
|
|
# type: (str) -> str
|
2021-03-07 20:03:16 +01:00
|
|
|
if CORE.vscode and (
|
|
|
|
not CORE.ace or os.path.abspath(path) == os.path.abspath(CORE.config_path)
|
|
|
|
):
|
|
|
|
print(
|
|
|
|
json.dumps(
|
|
|
|
{
|
|
|
|
"type": "read_file",
|
|
|
|
"path": path,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
2019-12-07 18:28:55 +01:00
|
|
|
data = json.loads(input())
|
2021-03-07 20:03:16 +01:00
|
|
|
assert data["type"] == "file_response"
|
|
|
|
return data["content"]
|
2019-04-22 21:56:30 +02:00
|
|
|
|
2019-10-24 21:53:42 +02:00
|
|
|
return read_file(path)
|
2022-01-24 23:46:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2022-01-25 09:24:59 +01:00
|
|
|
elif new is None:
|
|
|
|
return old
|
2022-01-24 23:46:42 +01:00
|
|
|
|
|
|
|
return new
|
|
|
|
|
|
|
|
return merge(full_old, full_new)
|