mirror of
https://github.com/esphome/esphome.git
synced 2025-03-15 15:18:16 +00:00
Lint
This commit is contained in:
parent
1623575129
commit
9d964dc4d0
@ -8,7 +8,7 @@ import os
|
|||||||
import random
|
import random
|
||||||
import sys
|
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.config import get_component, iter_components, read_config, strip_default_ids
|
||||||
from esphomeyaml.const import CONF_BAUD_RATE, CONF_DOMAIN, CONF_ESPHOMEYAML, \
|
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, \
|
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__)
|
_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():
|
def get_serial_ports():
|
||||||
|
@ -32,7 +32,8 @@ def validate_recursive_condition(value):
|
|||||||
path = [i] if is_list else []
|
path = [i] if is_list else []
|
||||||
item = copy.deepcopy(item)
|
item = copy.deepcopy(item)
|
||||||
if not isinstance(item, dict):
|
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)
|
key = next((x for x in item if x != CONF_CONDITION_ID), None)
|
||||||
if key is None:
|
if key is None:
|
||||||
raise vol.Invalid(u"Key missing from action! Got {}".format(item), path)
|
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]
|
validator = CONDITION_REGISTRY[key][0]
|
||||||
try:
|
try:
|
||||||
condition = validator(item[key])
|
condition = validator(item[key])
|
||||||
except vol.Invalid as e:
|
except vol.Invalid as err:
|
||||||
e.prepend(path)
|
err.prepend(path)
|
||||||
raise e
|
raise err
|
||||||
value[i] = {
|
value[i] = {
|
||||||
CONF_CONDITION_ID: cv.declare_variable_id(Condition)(item[CONF_CONDITION_ID]),
|
CONF_CONDITION_ID: cv.declare_variable_id(Condition)(item[CONF_CONDITION_ID]),
|
||||||
key: condition,
|
key: condition,
|
||||||
@ -65,7 +66,8 @@ def validate_recursive_action(value):
|
|||||||
path = [i] if is_list else []
|
path = [i] if is_list else []
|
||||||
item = copy.deepcopy(item)
|
item = copy.deepcopy(item)
|
||||||
if not isinstance(item, dict):
|
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)
|
key = next((x for x in item if x != CONF_ACTION_ID), None)
|
||||||
if key is None:
|
if key is None:
|
||||||
raise vol.Invalid(u"Key missing from action! Got {}".format(item), path)
|
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]
|
validator = ACTION_REGISTRY[key][0]
|
||||||
try:
|
try:
|
||||||
action = validator(item[key])
|
action = validator(item[key])
|
||||||
except vol.Invalid as e:
|
except vol.Invalid as err:
|
||||||
e.prepend(path)
|
err.prepend(path)
|
||||||
raise e
|
raise err
|
||||||
value[i] = {
|
value[i] = {
|
||||||
CONF_ACTION_ID: cv.declare_variable_id(Action)(item[CONF_ACTION_ID]),
|
CONF_ACTION_ID: cv.declare_variable_id(Action)(item[CONF_ACTION_ID]),
|
||||||
key: action,
|
key: action,
|
||||||
|
@ -5,7 +5,7 @@ from esphomeyaml.components import mqtt
|
|||||||
from esphomeyaml.components.mqtt import setup_mqtt_component
|
from esphomeyaml.components.mqtt import setup_mqtt_component
|
||||||
import esphomeyaml.config_validation as cv
|
import esphomeyaml.config_validation as cv
|
||||||
from esphomeyaml.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID
|
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
|
from esphomeyaml.cpp_types import Action, Nameable, esphomelib_ns
|
||||||
|
|
||||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||||
|
@ -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, \
|
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_OSCILLATION_COMMAND_TOPIC, CONF_OSCILLATION_OUTPUT, CONF_OSCILLATION_STATE_TOPIC, \
|
||||||
CONF_SPEED, CONF_SPEED_COMMAND_TOPIC, CONF_SPEED_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_
|
from esphomeyaml.cpp_types import Application, Component, Nameable, esphomelib_ns, Action, bool_
|
||||||
|
|
||||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||||
|
@ -12,7 +12,7 @@ from esphomeyaml.const import CONF_ALPHA, CONF_BLUE, CONF_BRIGHTNESS, CONF_COLOR
|
|||||||
CONF_EFFECT
|
CONF_EFFECT
|
||||||
from esphomeyaml.core import CORE
|
from esphomeyaml.core import CORE
|
||||||
from esphomeyaml.cpp_generator import process_lambda, Pvariable, add, StructInitializer, \
|
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, \
|
from esphomeyaml.cpp_types import esphomelib_ns, Application, Component, Nameable, Action, uint32, \
|
||||||
float_, std_string
|
float_, std_string
|
||||||
|
|
||||||
@ -177,22 +177,31 @@ EFFECTS_SCHEMA = vol.Schema({
|
|||||||
|
|
||||||
def validate_effects(allowed_effects):
|
def validate_effects(allowed_effects):
|
||||||
def validator(value):
|
def validator(value):
|
||||||
|
is_list = isinstance(value, list)
|
||||||
value = cv.ensure_list(value)
|
value = cv.ensure_list(value)
|
||||||
names = set()
|
names = set()
|
||||||
ret = []
|
ret = []
|
||||||
for i, effect in enumerate(value):
|
for i, effect in enumerate(value):
|
||||||
|
path = [i] if is_list else []
|
||||||
if not isinstance(effect, dict):
|
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:
|
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:
|
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()))
|
key = next(iter(effect.keys()))
|
||||||
if key not in allowed_effects:
|
if key not in allowed_effects:
|
||||||
raise vol.Invalid("The effect '{}' does not exist or is not allowed for this "
|
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 {}
|
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]
|
name = conf[key][CONF_NAME]
|
||||||
if name in names:
|
if name in names:
|
||||||
raise vol.Invalid(u"Found the effect name '{}' twice. All effects must have "
|
raise vol.Invalid(u"Found the effect name '{}' twice. All effects must have "
|
||||||
|
@ -5,7 +5,7 @@ import esphomeyaml.config_validation as cv
|
|||||||
from esphomeyaml.components.power_supply import PowerSupplyComponent
|
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.const import CONF_INVERTED, CONF_MAX_POWER, CONF_POWER_SUPPLY, CONF_ID, CONF_LEVEL
|
||||||
from esphomeyaml.core import CORE
|
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_
|
from esphomeyaml.cpp_types import esphomelib_ns, Action, float_
|
||||||
|
|
||||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||||
|
@ -5,7 +5,7 @@ import esphomeyaml.config_validation as cv
|
|||||||
from esphomeyaml.const import CONF_ACCELERATION, CONF_DECELERATION, CONF_ID, CONF_MAX_SPEED, \
|
from esphomeyaml.const import CONF_ACCELERATION, CONF_DECELERATION, CONF_ID, CONF_MAX_SPEED, \
|
||||||
CONF_POSITION, CONF_TARGET
|
CONF_POSITION, CONF_TARGET
|
||||||
from esphomeyaml.core import CORE
|
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
|
from esphomeyaml.cpp_types import Action, esphomelib_ns, int32
|
||||||
|
|
||||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||||
|
@ -125,7 +125,6 @@ def do_substitution_pass(config):
|
|||||||
substitutions[new] = substitutions[old]
|
substitutions[new] = substitutions[old]
|
||||||
del substitutions[old]
|
del substitutions[old]
|
||||||
except vol.Invalid as err:
|
except vol.Invalid as err:
|
||||||
from esphomeyaml.config import _format_vol_invalid
|
|
||||||
err.path.append(key)
|
err.path.append(key)
|
||||||
|
|
||||||
raise EsphomeyamlError(u"Error while parsing substitutions: {}".format(err))
|
raise EsphomeyamlError(u"Error while parsing substitutions: {}".format(err))
|
||||||
|
@ -6,7 +6,7 @@ from esphomeyaml.components.mqtt import setup_mqtt_component
|
|||||||
import esphomeyaml.config_validation as cv
|
import esphomeyaml.config_validation as cv
|
||||||
from esphomeyaml.const import CONF_ICON, CONF_ID, CONF_INVERTED, CONF_MQTT_ID, CONF_INTERNAL, \
|
from esphomeyaml.const import CONF_ICON, CONF_ID, CONF_INVERTED, CONF_MQTT_ID, CONF_INTERNAL, \
|
||||||
CONF_OPTIMISTIC
|
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
|
from esphomeyaml.cpp_types import esphomelib_ns, Nameable, Action, App
|
||||||
|
|
||||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||||
|
@ -6,16 +6,19 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from typing import List, Optional, Tuple, Set, Union, Any, Dict
|
|
||||||
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, ESP_PLATFORMS
|
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.helpers import color, indent
|
||||||
from esphomeyaml.util import safe_print
|
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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
_COMPONENT_CACHE = {}
|
_COMPONENT_CACHE = {}
|
||||||
@ -248,7 +251,8 @@ def validate_config(config):
|
|||||||
dependencies = getattr(component, 'DEPENDENCIES', [])
|
dependencies = getattr(component, 'DEPENDENCIES', [])
|
||||||
for dependency in dependencies:
|
for dependency in dependencies:
|
||||||
if dependency not in config:
|
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
|
success = False
|
||||||
if not success:
|
if not success:
|
||||||
skip_paths.append([domain])
|
skip_paths.append([domain])
|
||||||
@ -267,7 +271,8 @@ def validate_config(config):
|
|||||||
|
|
||||||
esp_platforms = getattr(component, 'ESP_PLATFORMS', ESP_PLATFORMS)
|
esp_platforms = getattr(component, 'ESP_PLATFORMS', ESP_PLATFORMS)
|
||||||
if CORE.esp_platform not in 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])
|
skip_paths.append([domain])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -301,8 +306,8 @@ def validate_config(config):
|
|||||||
dependencies = getattr(platform, 'DEPENDENCIES', [])
|
dependencies = getattr(platform, 'DEPENDENCIES', [])
|
||||||
for dependency in dependencies:
|
for dependency in dependencies:
|
||||||
if dependency not in config:
|
if dependency not in config:
|
||||||
result.add_error(u"Platform {} requires component {}".format(p_domain, dependency),
|
result.add_error(u"Platform {} requires component {}"
|
||||||
[domain, i])
|
u"".format(p_domain, dependency), [domain, i])
|
||||||
success = False
|
success = False
|
||||||
if not success:
|
if not success:
|
||||||
skip_paths.append([domain, i])
|
skip_paths.append([domain, i])
|
||||||
@ -321,8 +326,8 @@ def validate_config(config):
|
|||||||
|
|
||||||
esp_platforms = getattr(platform, 'ESP_PLATFORMS', ESP_PLATFORMS)
|
esp_platforms = getattr(platform, 'ESP_PLATFORMS', ESP_PLATFORMS)
|
||||||
if CORE.esp_platform not in esp_platforms:
|
if CORE.esp_platform not in esp_platforms:
|
||||||
result.add_error(u"Platform {} doesn't support {}.".format(p_domain, CORE.esp_platform),
|
result.add_error(u"Platform {} doesn't support {}."
|
||||||
[domain, i])
|
u"".format(p_domain, CORE.esp_platform), [domain, i])
|
||||||
skip_paths.append([domain, i])
|
skip_paths.append([domain, i])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -483,7 +488,7 @@ def dump_dict(config, path, at_root=True):
|
|||||||
ret += u'[]'
|
ret += u'[]'
|
||||||
multiline = False
|
multiline = False
|
||||||
|
|
||||||
for i, obj in enumerate(conf):
|
for i in range(len(conf)):
|
||||||
path_ = path + [i]
|
path_ = path + [i]
|
||||||
error = config.get_error_for_path(path_)
|
error = config.get_error_for_path(path_)
|
||||||
if error is not None:
|
if error is not None:
|
||||||
@ -506,7 +511,7 @@ def dump_dict(config, path, at_root=True):
|
|||||||
ret += u'{}'
|
ret += u'{}'
|
||||||
multiline = False
|
multiline = False
|
||||||
|
|
||||||
for k, v in conf.iteritems():
|
for k in conf.iterkeys():
|
||||||
path_ = path + [k]
|
path_ = path + [k]
|
||||||
error = config.get_error_for_path(path_)
|
error = config.get_error_for_path(path_)
|
||||||
if error is not None:
|
if error is not None:
|
||||||
@ -589,7 +594,8 @@ def read_config(verbose):
|
|||||||
if not res.is_in_error_path(path):
|
if not res.is_in_error_path(path):
|
||||||
continue
|
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]))
|
safe_print(indent(dump_dict(res, path)[0]))
|
||||||
return None
|
return None
|
||||||
return OrderedDict(res)
|
return OrderedDict(res)
|
||||||
|
@ -247,7 +247,7 @@ class CheckForUpdateThread(threading.Thread):
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
storage = EsphomeyamlStorageJSON.load(self._path) or \
|
storage = EsphomeyamlStorageJSON.load(self._path) or \
|
||||||
EsphomeyamlStorageJSON.get_default()
|
EsphomeyamlStorageJSON.get_default()
|
||||||
if not storage.should_do_esphomeyaml_update_check:
|
if not storage.should_do_esphomeyaml_update_check:
|
||||||
return storage
|
return storage
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user