1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-27 23:52:28 +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:
Guillermo Ruffino
2021-02-06 12:09:15 -03:00
committed by GitHub
parent de3377132d
commit 28e39f7f76
5 changed files with 30 additions and 31 deletions

View File

@@ -12,7 +12,7 @@ import yaml.constructor
from esphome import core
from esphome.config_helpers import read_config_file
from esphome.core import EsphomeError, IPAddress, Lambda, MACAddress, TimePeriod, \
DocumentRange, DocumentLocation
DocumentRange
from esphome.helpers import add_class_to_obj
from esphome.util import OrderedDict, filter_yaml_files
@@ -42,14 +42,22 @@ class ESPHomeDataBase:
if node.style is not None and node.style in '|>':
self._content_offset = 1
def from_database(self, database):
# pylint: disable=attribute-defined-outside-init
self._esp_range = database.esp_range
self._content_offset = database.content_offset
class ESPForceValue:
pass
def make_data_base(value):
def make_data_base(value, from_database: ESPHomeDataBase = None):
try:
return add_class_to_obj(value, ESPHomeDataBase)
value = add_class_to_obj(value, ESPHomeDataBase)
if from_database is not None:
value.from_database(from_database)
return value
except TypeError:
# Adding class failed, ignore error
return value
@@ -265,10 +273,7 @@ class ESPHomeLoader(yaml.SafeLoader): # pylint: disable=too-many-ancestors
@_add_data_ref
def construct_lambda(self, node):
start_mark = DocumentLocation.from_mark(node.start_mark)
if node.style is not None and node.style in '|>':
start_mark.line += 1
return Lambda(str(node.value), start_mark)
return Lambda(str(node.value))
@_add_data_ref
def construct_force(self, node):