mirror of
https://github.com/esphome/esphome.git
synced 2025-09-01 19:02:18 +01:00
Add variable substitutions for !include (#3510)
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
---
|
||||
ssid: ${name}
|
2
tests/unit_tests/fixtures/yaml_util/includes/list.yaml
Normal file
2
tests/unit_tests/fixtures/yaml_util/includes/list.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
- ${var1}
|
1
tests/unit_tests/fixtures/yaml_util/includes/scalar.yaml
Normal file
1
tests/unit_tests/fixtures/yaml_util/includes/scalar.yaml
Normal file
@@ -0,0 +1 @@
|
||||
${var1}
|
17
tests/unit_tests/fixtures/yaml_util/includetest.yaml
Normal file
17
tests/unit_tests/fixtures/yaml_util/includetest.yaml
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
substitutions:
|
||||
name: original
|
||||
|
||||
wifi: !include
|
||||
file: includes/included.yaml
|
||||
vars:
|
||||
name: my_custom_ssid
|
||||
|
||||
esphome:
|
||||
# should be substituted as 'original', not overwritten by vars in the !include above
|
||||
name: ${name}
|
||||
name_add_mac_suffix: true
|
||||
platform: esp8266
|
||||
board: !include { file: includes/scalar.yaml, vars: { var1: nodemcu } }
|
||||
|
||||
libraries: !include { file: includes/list.yaml, vars: { var1: Wire } }
|
13
tests/unit_tests/test_yaml_util.py
Normal file
13
tests/unit_tests/test_yaml_util.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from esphome import yaml_util
|
||||
from esphome.components import substitutions
|
||||
|
||||
|
||||
def test_include_with_vars(fixture_path):
|
||||
yaml_file = fixture_path / "yaml_util" / "includetest.yaml"
|
||||
|
||||
actual = yaml_util.load_yaml(yaml_file)
|
||||
substitutions.do_substitution_pass(actual, None)
|
||||
assert actual["esphome"]["name"] == "original"
|
||||
assert actual["esphome"]["libraries"][0] == "Wire"
|
||||
assert actual["esphome"]["board"] == "nodemcu"
|
||||
assert actual["wifi"]["ssid"] == "my_custom_ssid"
|
Reference in New Issue
Block a user