Fallback to main secrets.yaml for packages (#5604)

This commit is contained in:
dentra 2023-10-27 00:16:43 +03:00 committed by GitHub
parent f6e8d97981
commit cfbf3681f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,6 +18,7 @@ from esphome.core import (
MACAddress, MACAddress,
TimePeriod, TimePeriod,
DocumentRange, DocumentRange,
CORE,
) )
from esphome.helpers import add_class_to_obj from esphome.helpers import add_class_to_obj
from esphome.util import OrderedDict, filter_yaml_files from esphome.util import OrderedDict, filter_yaml_files
@ -240,7 +241,18 @@ class ESPHomeLoader(yaml.SafeLoader):
@_add_data_ref @_add_data_ref
def construct_secret(self, node): def construct_secret(self, node):
try:
secrets = _load_yaml_internal(self._rel_path(SECRET_YAML)) secrets = _load_yaml_internal(self._rel_path(SECRET_YAML))
except EsphomeError as e:
if self.name == CORE.config_path:
raise e
try:
main_config_dir = os.path.dirname(CORE.config_path)
main_secret_yml = os.path.join(main_config_dir, SECRET_YAML)
secrets = _load_yaml_internal(main_secret_yml)
except EsphomeError as er:
raise EsphomeError(f"{e}\n{er}") from er
if node.value not in secrets: if node.value not in secrets:
raise yaml.MarkedYAMLError( raise yaml.MarkedYAMLError(
f"Secret '{node.value}' not defined", node.start_mark f"Secret '{node.value}' not defined", node.start_mark