From 9d964dc4d066afe9e00897522f3f43de243cdd38 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Wed, 5 Dec 2018 10:53:28 +0100 Subject: [PATCH] Lint --- esphomeyaml/__main__.py | 4 ++-- esphomeyaml/automation.py | 18 +++++++------- esphomeyaml/components/cover/__init__.py | 2 +- esphomeyaml/components/fan/__init__.py | 2 +- esphomeyaml/components/light/__init__.py | 21 +++++++++++----- esphomeyaml/components/output/__init__.py | 2 +- esphomeyaml/components/stepper/__init__.py | 2 +- esphomeyaml/components/substitutions.py | 1 - esphomeyaml/components/switch/__init__.py | 2 +- esphomeyaml/config.py | 28 +++++++++++++--------- esphomeyaml/storage_json.py | 2 +- 11 files changed, 50 insertions(+), 34 deletions(-) diff --git a/esphomeyaml/__main__.py b/esphomeyaml/__main__.py index 719c77f3a4..9a95d4cfbe 100644 --- a/esphomeyaml/__main__.py +++ b/esphomeyaml/__main__.py @@ -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(): diff --git a/esphomeyaml/automation.py b/esphomeyaml/automation.py index 6d3ad379af..74442d78ce 100644 --- a/esphomeyaml/automation.py +++ b/esphomeyaml/automation.py @@ -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, diff --git a/esphomeyaml/components/cover/__init__.py b/esphomeyaml/components/cover/__init__.py index f042f0ab45..1ff00054e6 100644 --- a/esphomeyaml/components/cover/__init__.py +++ b/esphomeyaml/components/cover/__init__.py @@ -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({ diff --git a/esphomeyaml/components/fan/__init__.py b/esphomeyaml/components/fan/__init__.py index a386c22e97..344bf8b115 100644 --- a/esphomeyaml/components/fan/__init__.py +++ b/esphomeyaml/components/fan/__init__.py @@ -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({ diff --git a/esphomeyaml/components/light/__init__.py b/esphomeyaml/components/light/__init__.py index a59f7273f2..c4d492bbf4 100644 --- a/esphomeyaml/components/light/__init__.py +++ b/esphomeyaml/components/light/__init__.py @@ -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 " diff --git a/esphomeyaml/components/output/__init__.py b/esphomeyaml/components/output/__init__.py index cbe5d34cd4..b5a575c6f2 100644 --- a/esphomeyaml/components/output/__init__.py +++ b/esphomeyaml/components/output/__init__.py @@ -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({ diff --git a/esphomeyaml/components/stepper/__init__.py b/esphomeyaml/components/stepper/__init__.py index b97f35864f..fe9ec064cc 100644 --- a/esphomeyaml/components/stepper/__init__.py +++ b/esphomeyaml/components/stepper/__init__.py @@ -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({ diff --git a/esphomeyaml/components/substitutions.py b/esphomeyaml/components/substitutions.py index 117d388449..a5cf9010e7 100644 --- a/esphomeyaml/components/substitutions.py +++ b/esphomeyaml/components/substitutions.py @@ -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)) diff --git a/esphomeyaml/components/switch/__init__.py b/esphomeyaml/components/switch/__init__.py index 89aa1a5a3f..3febc06966 100644 --- a/esphomeyaml/components/switch/__init__.py +++ b/esphomeyaml/components/switch/__init__.py @@ -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({ diff --git a/esphomeyaml/config.py b/esphomeyaml/config.py index cb3b9a78b2..7eb5740208 100644 --- a/esphomeyaml/config.py +++ b/esphomeyaml/config.py @@ -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) diff --git a/esphomeyaml/storage_json.py b/esphomeyaml/storage_json.py index d9b83170e2..9bc095908e 100644 --- a/esphomeyaml/storage_json.py +++ b/esphomeyaml/storage_json.py @@ -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