1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-15 15:18:16 +00:00
This commit is contained in:
Otto Winter 2018-12-03 22:14:10 +01:00
parent 7618a0267c
commit ba9b1edc72
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E

View File

@ -5,12 +5,13 @@ import importlib
import json import json
import logging import logging
from typing import List, Optional, Tuple
import voluptuous as vol import voluptuous as vol
from esphomeyaml import core, core_config, yaml_util from esphomeyaml import core, core_config, yaml_util
from esphomeyaml.components import substitutions from esphomeyaml.components import substitutions
from esphomeyaml.const import CONF_ESPHOMEYAML, CONF_PLATFORM, CONF_WIFI, ESP_PLATFORMS from esphomeyaml.const import CONF_ESPHOMEYAML, CONF_PLATFORM, CONF_WIFI, ESP_PLATFORMS
from esphomeyaml.core import CORE, EsphomeyamlError from esphomeyaml.core import CORE, EsphomeyamlError, ConfigType
from esphomeyaml.helpers import color from esphomeyaml.helpers import color
from esphomeyaml.util import safe_print from esphomeyaml.util import safe_print
@ -67,10 +68,11 @@ class Config(OrderedDict):
super(Config, self).__init__() super(Config, self).__init__()
self.errors = [] self.errors = []
def add_error(self, message, domain=None, config=None): def add_error(self, message, domain=None, config=None, path=None):
# type: (basestring, Optional[basestring], Optional[ConfigType], Optional[List[basestring]]) -> None
if not isinstance(message, unicode): if not isinstance(message, unicode):
message = unicode(message) message = unicode(message)
self.errors.append((message, domain, config)) self.errors.append((message, domain, config, path))
def iter_ids(config, prefix=None, parent=None): def iter_ids(config, prefix=None, parent=None):
@ -148,27 +150,27 @@ def validate_config(config):
result = Config() result = Config()
def _comp_error(ex, domain, config): def _comp_error(ex, domain, config, path):
result.add_error(_format_config_error(ex, domain, config), domain, config) result.add_error(_format_config_error(ex, domain, config), domain, config, path)
# Step 1: Load everything # Step 1: Load everything
for domain, conf in config.iteritems(): for domain, conf in config.iteritems():
domain = str(domain) domain = str(domain)
if domain == CONF_ESPHOMEYAML or domain.startswith('.'): if domain == CONF_ESPHOMEYAML or domain.startswith(u'.'):
continue continue
if conf is None: if conf is None:
conf = {} conf = {}
component = get_component(domain) component = get_component(domain)
if component is None: if component is None:
result.add_error(u"Component not found: {}".format(domain), domain, conf) result.add_error(u"Component not found: {}".format(domain), domain, conf, None)
continue continue
if not hasattr(component, 'PLATFORM_SCHEMA'): if not hasattr(component, 'PLATFORM_SCHEMA'):
continue continue
for p_config in conf: for i, p_config in enumerate(conf):
if not isinstance(p_config, dict): if not isinstance(p_config, dict):
result.add_error(u"Platform schemas must have 'platform:' key", ) result.add_error(u"Platform schemas must have 'platform:' key", None, p_config, [])
continue continue
p_name = p_config.get(u'platform') p_name = p_config.get(u'platform')
if p_name is None: if p_name is None: