mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-04 03:48:29 +02:00
Allow substitutions to be valid names (#4726)
This commit is contained in:
@@ -1,19 +1,14 @@
|
||||
import logging
|
||||
import re
|
||||
|
||||
import esphome.config_validation as cv
|
||||
from esphome import core
|
||||
from esphome.const import CONF_SUBSTITUTIONS
|
||||
from esphome.const import CONF_SUBSTITUTIONS, VALID_SUBSTITUTIONS_CHARACTERS
|
||||
from esphome.yaml_util import ESPHomeDataBase, make_data_base
|
||||
from esphome.config_helpers import merge_config
|
||||
|
||||
CODEOWNERS = ["@esphome/core"]
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
VALID_SUBSTITUTIONS_CHARACTERS = (
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
||||
)
|
||||
|
||||
|
||||
def validate_substitution_key(value):
|
||||
value = cv.string(value)
|
||||
@@ -42,12 +37,6 @@ async def to_code(config):
|
||||
pass
|
||||
|
||||
|
||||
# pylint: disable=consider-using-f-string
|
||||
VARIABLE_PROG = re.compile(
|
||||
"\\$([{0}]+|\\{{[{0}]*\\}})".format(VALID_SUBSTITUTIONS_CHARACTERS)
|
||||
)
|
||||
|
||||
|
||||
def _expand_substitutions(substitutions, value, path, ignore_missing):
|
||||
if "$" not in value:
|
||||
return value
|
||||
@@ -56,7 +45,7 @@ def _expand_substitutions(substitutions, value, path, ignore_missing):
|
||||
|
||||
i = 0
|
||||
while True:
|
||||
m = VARIABLE_PROG.search(value, i)
|
||||
m = cv.VARIABLE_PROG.search(value, i)
|
||||
if not m:
|
||||
# Nothing more to match. Done
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user