mirror of
https://github.com/esphome/esphome.git
synced 2025-09-06 13:22:19 +01:00
Add config validator location (#1490)
* show validation source location for id * show validation source location for lambda * refactor lambda #line position * account content offset on made lambdas * lint * remove redundant check
This commit is contained in:
committed by
GitHub
parent
de3377132d
commit
28e39f7f76
@@ -17,10 +17,10 @@ from esphome.const import ALLOWED_NAME_CHARS, CONF_AVAILABILITY, CONF_COMMAND_TO
|
||||
CONF_HOUR, CONF_MINUTE, CONF_SECOND, CONF_VALUE, CONF_UPDATE_INTERVAL, CONF_TYPE_ID, \
|
||||
CONF_TYPE, CONF_PACKAGES
|
||||
from esphome.core import CORE, HexInt, IPAddress, Lambda, TimePeriod, TimePeriodMicroseconds, \
|
||||
TimePeriodMilliseconds, TimePeriodSeconds, TimePeriodMinutes, DocumentLocation
|
||||
TimePeriodMilliseconds, TimePeriodSeconds, TimePeriodMinutes
|
||||
from esphome.helpers import list_starts_with, add_class_to_obj
|
||||
from esphome.voluptuous_schema import _Schema
|
||||
from esphome.yaml_util import ESPHomeDataBase
|
||||
from esphome.yaml_util import make_data_base
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -983,11 +983,7 @@ LAMBDA_ENTITY_ID_PROG = re.compile(r'id\(\s*([a-zA-Z0-9_]+\.[.a-zA-Z0-9_]+)\s*\)
|
||||
def lambda_(value):
|
||||
"""Coerce this configuration option to a lambda."""
|
||||
if not isinstance(value, Lambda):
|
||||
start_mark = None
|
||||
if isinstance(value, ESPHomeDataBase) and value.esp_range is not None:
|
||||
start_mark = DocumentLocation.copy(value.esp_range.start_mark)
|
||||
start_mark.line += value.content_offset
|
||||
value = Lambda(string_strict(value), start_mark)
|
||||
value = make_data_base(Lambda(string_strict(value)), value)
|
||||
entity_id_parts = re.split(LAMBDA_ENTITY_ID_PROG, value.value)
|
||||
if len(entity_id_parts) != 1:
|
||||
entity_ids = ' '.join("'{}'".format(entity_id_parts[i])
|
||||
@@ -1182,8 +1178,8 @@ class OnlyWith(Optional):
|
||||
# pylint: disable=unsupported-membership-test
|
||||
if (self._component in CORE.raw_config or
|
||||
(CONF_PACKAGES in CORE.raw_config and
|
||||
self._component in
|
||||
{list(x.keys())[0] for x in CORE.raw_config[CONF_PACKAGES].values()})):
|
||||
self._component in
|
||||
{list(x.keys())[0] for x in CORE.raw_config[CONF_PACKAGES].values()})):
|
||||
return self._default
|
||||
return vol.UNDEFINED
|
||||
|
||||
|
Reference in New Issue
Block a user