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-05 10:53:28 +01:00
parent 1623575129
commit 9d964dc4d0
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E
11 changed files with 50 additions and 34 deletions

View File

@ -8,7 +8,7 @@ import os
import random
import sys
from esphomeyaml import const, core, core_config, mqtt, platformio_api, wizard, writer, yaml_util
from esphomeyaml import const, core_config, mqtt, platformio_api, wizard, writer, yaml_util
from esphomeyaml.config import get_component, iter_components, read_config, strip_default_ids
from esphomeyaml.const import CONF_BAUD_RATE, CONF_DOMAIN, CONF_ESPHOMEYAML, \
CONF_HOSTNAME, CONF_LOGGER, CONF_MANUAL_IP, CONF_NAME, CONF_STATIC_IP, CONF_USE_CUSTOM_CODE, \
@ -22,7 +22,7 @@ from esphomeyaml.util import run_external_command, safe_print
_LOGGER = logging.getLogger(__name__)
PRE_INITIALIZE = ['esphomeyaml', 'logger', 'wifi', 'ethernet', 'ota', 'mqtt', 'web_server', 'i2c']
PRE_INITIALIZE = ['esphomeyaml', 'logger', 'wifi', 'ota', 'mqtt', 'web_server', 'i2c']
def get_serial_ports():

View File

@ -32,7 +32,8 @@ def validate_recursive_condition(value):
path = [i] if is_list else []
item = copy.deepcopy(item)
if not isinstance(item, dict):
raise vol.Invalid(u"Condition must consist of key-value mapping! Got {}".format(item), path)
raise vol.Invalid(u"Condition must consist of key-value mapping! Got {}".format(item),
path)
key = next((x for x in item if x != CONF_CONDITION_ID), None)
if key is None:
raise vol.Invalid(u"Key missing from action! Got {}".format(item), path)
@ -48,9 +49,9 @@ def validate_recursive_condition(value):
validator = CONDITION_REGISTRY[key][0]
try:
condition = validator(item[key])
except vol.Invalid as e:
e.prepend(path)
raise e
except vol.Invalid as err:
err.prepend(path)
raise err
value[i] = {
CONF_CONDITION_ID: cv.declare_variable_id(Condition)(item[CONF_CONDITION_ID]),
key: condition,
@ -65,7 +66,8 @@ def validate_recursive_action(value):
path = [i] if is_list else []
item = copy.deepcopy(item)
if not isinstance(item, dict):
raise vol.Invalid(u"Action must consist of key-value mapping! Got {}".format(item), path)
raise vol.Invalid(u"Action must consist of key-value mapping! Got {}".format(item),
path)
key = next((x for x in item if x != CONF_ACTION_ID), None)
if key is None:
raise vol.Invalid(u"Key missing from action! Got {}".format(item), path)
@ -81,9 +83,9 @@ def validate_recursive_action(value):
validator = ACTION_REGISTRY[key][0]
try:
action = validator(item[key])
except vol.Invalid as e:
e.prepend(path)
raise e
except vol.Invalid as err:
err.prepend(path)
raise err
value[i] = {
CONF_ACTION_ID: cv.declare_variable_id(Action)(item[CONF_ACTION_ID]),
key: action,

View File

@ -5,7 +5,7 @@ from esphomeyaml.components import mqtt
from esphomeyaml.components.mqtt import setup_mqtt_component
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID
from esphomeyaml.cpp_generator import Pvariable, TemplateArguments, add, get_variable
from esphomeyaml.cpp_generator import Pvariable, add, get_variable
from esphomeyaml.cpp_types import Action, Nameable, esphomelib_ns
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({

View File

@ -7,7 +7,7 @@ import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID, CONF_NAME, CONF_OSCILLATING, \
CONF_OSCILLATION_COMMAND_TOPIC, CONF_OSCILLATION_OUTPUT, CONF_OSCILLATION_STATE_TOPIC, \
CONF_SPEED, CONF_SPEED_COMMAND_TOPIC, CONF_SPEED_STATE_TOPIC
from esphomeyaml.cpp_generator import add, Pvariable, get_variable, TemplateArguments, templatable
from esphomeyaml.cpp_generator import add, Pvariable, get_variable, templatable
from esphomeyaml.cpp_types import Application, Component, Nameable, esphomelib_ns, Action, bool_
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({

View File

@ -12,7 +12,7 @@ from esphomeyaml.const import CONF_ALPHA, CONF_BLUE, CONF_BRIGHTNESS, CONF_COLOR
CONF_EFFECT
from esphomeyaml.core import CORE
from esphomeyaml.cpp_generator import process_lambda, Pvariable, add, StructInitializer, \
ArrayInitializer, TemplateArguments, get_variable, templatable
ArrayInitializer, get_variable, templatable
from esphomeyaml.cpp_types import esphomelib_ns, Application, Component, Nameable, Action, uint32, \
float_, std_string
@ -177,22 +177,31 @@ EFFECTS_SCHEMA = vol.Schema({
def validate_effects(allowed_effects):
def validator(value):
is_list = isinstance(value, list)
value = cv.ensure_list(value)
names = set()
ret = []
for i, effect in enumerate(value):
path = [i] if is_list else []
if not isinstance(effect, dict):
raise vol.Invalid("Each effect must be a dictionary, not {}".format(type(value)), [i])
raise vol.Invalid("Each effect must be a dictionary, not {}".format(type(value)),
path)
if len(effect) > 1:
raise vol.Invalid("Each entry in the 'effects:' option must be a single effect.", [i])
raise vol.Invalid("Each entry in the 'effects:' option must be a single effect.",
path)
if not effect:
raise vol.Invalid("Found no effect for the {}th entry in 'effects:'!".format(i), [i])
raise vol.Invalid("Found no effect for the {}th entry in 'effects:'!".format(i),
path)
key = next(iter(effect.keys()))
if key not in allowed_effects:
raise vol.Invalid("The effect '{}' does not exist or is not allowed for this "
"light type".format(key), [i])
"light type".format(key), path)
effect[key] = effect[key] or {}
conf = EFFECTS_SCHEMA(effect)
try:
conf = EFFECTS_SCHEMA(effect)
except vol.Invalid as err:
err.prepend(path)
raise err
name = conf[key][CONF_NAME]
if name in names:
raise vol.Invalid(u"Found the effect name '{}' twice. All effects must have "

View File

@ -5,7 +5,7 @@ import esphomeyaml.config_validation as cv
from esphomeyaml.components.power_supply import PowerSupplyComponent
from esphomeyaml.const import CONF_INVERTED, CONF_MAX_POWER, CONF_POWER_SUPPLY, CONF_ID, CONF_LEVEL
from esphomeyaml.core import CORE
from esphomeyaml.cpp_generator import add, get_variable, Pvariable, TemplateArguments, templatable
from esphomeyaml.cpp_generator import add, get_variable, Pvariable, templatable
from esphomeyaml.cpp_types import esphomelib_ns, Action, float_
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({

View File

@ -5,7 +5,7 @@ import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ACCELERATION, CONF_DECELERATION, CONF_ID, CONF_MAX_SPEED, \
CONF_POSITION, CONF_TARGET
from esphomeyaml.core import CORE
from esphomeyaml.cpp_generator import Pvariable, TemplateArguments, add, get_variable, templatable
from esphomeyaml.cpp_generator import Pvariable, add, get_variable, templatable
from esphomeyaml.cpp_types import Action, esphomelib_ns, int32
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({

View File

@ -125,7 +125,6 @@ def do_substitution_pass(config):
substitutions[new] = substitutions[old]
del substitutions[old]
except vol.Invalid as err:
from esphomeyaml.config import _format_vol_invalid
err.path.append(key)
raise EsphomeyamlError(u"Error while parsing substitutions: {}".format(err))

View File

@ -6,7 +6,7 @@ from esphomeyaml.components.mqtt import setup_mqtt_component
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ICON, CONF_ID, CONF_INVERTED, CONF_MQTT_ID, CONF_INTERNAL, \
CONF_OPTIMISTIC
from esphomeyaml.cpp_generator import add, Pvariable, TemplateArguments, get_variable
from esphomeyaml.cpp_generator import add, Pvariable, get_variable
from esphomeyaml.cpp_types import esphomelib_ns, Nameable, Action, App
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({

View File

@ -6,16 +6,19 @@ import json
import logging
import re
from typing import List, Optional, Tuple, Set, Union, Any, Dict
import voluptuous as vol
from esphomeyaml import core, core_config, yaml_util
from esphomeyaml.components import substitutions
from esphomeyaml.const import CONF_ESPHOMEYAML, CONF_PLATFORM, ESP_PLATFORMS
from esphomeyaml.core import CORE, EsphomeyamlError, ConfigType
from esphomeyaml.core import CORE, EsphomeyamlError
from esphomeyaml.helpers import color, indent
from esphomeyaml.util import safe_print
# pylint: disable=unused-import, wrong-import-order
from typing import List, Optional, Tuple, Union # noqa
from esphomeyaml.core import ConfigType # noqa
_LOGGER = logging.getLogger(__name__)
_COMPONENT_CACHE = {}
@ -248,7 +251,8 @@ def validate_config(config):
dependencies = getattr(component, 'DEPENDENCIES', [])
for dependency in dependencies:
if dependency not in config:
result.add_error(u"Component {} requires component {}".format(domain, dependency), [domain])
result.add_error(u"Component {} requires component {}".format(domain, dependency),
[domain])
success = False
if not success:
skip_paths.append([domain])
@ -267,7 +271,8 @@ def validate_config(config):
esp_platforms = getattr(component, 'ESP_PLATFORMS', ESP_PLATFORMS)
if CORE.esp_platform not in esp_platforms:
result.add_error(u"Component {} doesn't support {}.".format(domain, CORE.esp_platform), [domain])
result.add_error(u"Component {} doesn't support {}.".format(domain, CORE.esp_platform),
[domain])
skip_paths.append([domain])
continue
@ -301,8 +306,8 @@ def validate_config(config):
dependencies = getattr(platform, 'DEPENDENCIES', [])
for dependency in dependencies:
if dependency not in config:
result.add_error(u"Platform {} requires component {}".format(p_domain, dependency),
[domain, i])
result.add_error(u"Platform {} requires component {}"
u"".format(p_domain, dependency), [domain, i])
success = False
if not success:
skip_paths.append([domain, i])
@ -321,8 +326,8 @@ def validate_config(config):
esp_platforms = getattr(platform, 'ESP_PLATFORMS', ESP_PLATFORMS)
if CORE.esp_platform not in esp_platforms:
result.add_error(u"Platform {} doesn't support {}.".format(p_domain, CORE.esp_platform),
[domain, i])
result.add_error(u"Platform {} doesn't support {}."
u"".format(p_domain, CORE.esp_platform), [domain, i])
skip_paths.append([domain, i])
continue
@ -483,7 +488,7 @@ def dump_dict(config, path, at_root=True):
ret += u'[]'
multiline = False
for i, obj in enumerate(conf):
for i in range(len(conf)):
path_ = path + [i]
error = config.get_error_for_path(path_)
if error is not None:
@ -506,7 +511,7 @@ def dump_dict(config, path, at_root=True):
ret += u'{}'
multiline = False
for k, v in conf.iteritems():
for k in conf.iterkeys():
path_ = path + [k]
error = config.get_error_for_path(path_)
if error is not None:
@ -589,7 +594,8 @@ def read_config(verbose):
if not res.is_in_error_path(path):
continue
safe_print(color('bold_red', u'{}:'.format(domain)) + u' ' + (line_info(res.nested_item(path)) or u''))
safe_print(color('bold_red', u'{}:'.format(domain)) + u' ' +
(line_info(res.nested_item(path)) or u''))
safe_print(indent(dump_dict(res, path)[0]))
return None
return OrderedDict(res)

View File

@ -247,7 +247,7 @@ class CheckForUpdateThread(threading.Thread):
import requests
storage = EsphomeyamlStorageJSON.load(self._path) or \
EsphomeyamlStorageJSON.get_default()
EsphomeyamlStorageJSON.get_default()
if not storage.should_do_esphomeyaml_update_check:
return storage