mirror of
https://github.com/esphome/esphome.git
synced 2025-10-11 22:33:49 +01:00
fix prefix in expanded
This commit is contained in:
@@ -231,12 +231,28 @@ def merge_component_configs(
|
|||||||
# This allows components that use local file references to be grouped
|
# This allows components that use local file references to be grouped
|
||||||
comp_abs_dir = str(comp_dir.absolute())
|
comp_abs_dir = str(comp_dir.absolute())
|
||||||
|
|
||||||
# Prefix substitutions in component data
|
# Prefix substitutions in component data (including those in packages)
|
||||||
if "substitutions" in comp_data and comp_data["substitutions"] is not None:
|
# Must do this recursively before expanding packages
|
||||||
prefixed_subs = {}
|
def prefix_all_substitutions(data, prefix):
|
||||||
for sub_name, sub_value in comp_data["substitutions"].items():
|
"""Recursively prefix substitution definitions in data structure."""
|
||||||
prefixed_subs[f"{comp_name}_{sub_name}"] = sub_value
|
if isinstance(data, dict):
|
||||||
comp_data["substitutions"] = prefixed_subs
|
# Prefix substitutions at this level
|
||||||
|
if "substitutions" in data and data["substitutions"] is not None:
|
||||||
|
prefixed_subs = {}
|
||||||
|
for sub_name, sub_value in data["substitutions"].items():
|
||||||
|
prefixed_subs[f"{prefix}_{sub_name}"] = sub_value
|
||||||
|
data["substitutions"] = prefixed_subs
|
||||||
|
|
||||||
|
# Recursively process nested dicts (like packages)
|
||||||
|
for key, value in data.items():
|
||||||
|
if key != "substitutions": # Already handled above
|
||||||
|
data[key] = prefix_all_substitutions(value, prefix)
|
||||||
|
elif isinstance(data, list):
|
||||||
|
return [prefix_all_substitutions(item, prefix) for item in data]
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
comp_data = prefix_all_substitutions(comp_data, comp_name)
|
||||||
|
|
||||||
# Add component_dir substitution with absolute path for this component
|
# Add component_dir substitution with absolute path for this component
|
||||||
if "substitutions" not in comp_data or comp_data["substitutions"] is None:
|
if "substitutions" not in comp_data or comp_data["substitutions"] is None:
|
||||||
|
Reference in New Issue
Block a user