From c2f88776c759ce2430d72cfb4ae929d7bba5739b Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Mon, 19 Nov 2018 22:49:06 +0100 Subject: [PATCH] Fix SNTP servers option (#237) * Fix SNTP servers option * Lint --- esphomeyaml/components/light/__init__.py | 20 ++++++++------------ esphomeyaml/components/time/sntp.py | 6 ++++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/esphomeyaml/components/light/__init__.py b/esphomeyaml/components/light/__init__.py index c74376b2fb..cdd4f2007c 100644 --- a/esphomeyaml/components/light/__init__.py +++ b/esphomeyaml/components/light/__init__.py @@ -1,18 +1,16 @@ import voluptuous as vol -from esphomeyaml.automation import maybe_simple_id, ACTION_REGISTRY +from esphomeyaml.automation import ACTION_REGISTRY, maybe_simple_id from esphomeyaml.components import mqtt import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_ALPHA, CONF_BLUE, CONF_BRIGHTNESS, CONF_COLORS, \ - CONF_DEFAULT_TRANSITION_LENGTH, CONF_DURATION, CONF_EFFECTS, CONF_EFFECT_ID, \ - CONF_GAMMA_CORRECT, CONF_GREEN, CONF_ID, CONF_INTERNAL, CONF_LAMBDA, CONF_MQTT_ID, CONF_NAME, \ - CONF_NUM_LEDS, CONF_RANDOM, CONF_RED, CONF_SPEED, CONF_STATE, CONF_TRANSITION_LENGTH, \ - CONF_UPDATE_INTERVAL, CONF_WHITE, CONF_WIDTH, CONF_FLASH_LENGTH, CONF_COLOR_TEMPERATURE, \ - CONF_EFFECT -from esphomeyaml.helpers import Application, ArrayInitializer, Pvariable, RawExpression, \ - StructInitializer, add, add_job, esphomelib_ns, process_lambda, setup_mqtt_component, \ - get_variable, TemplateArguments, templatable, uint32, float_, std_string, Nameable, Component, \ - Action + CONF_COLOR_TEMPERATURE, CONF_DEFAULT_TRANSITION_LENGTH, CONF_DURATION, CONF_EFFECT, \ + CONF_EFFECTS, CONF_EFFECT_ID, CONF_FLASH_LENGTH, CONF_GAMMA_CORRECT, CONF_GREEN, CONF_ID, \ + CONF_INTERNAL, CONF_LAMBDA, CONF_MQTT_ID, CONF_NAME, CONF_NUM_LEDS, CONF_RANDOM, CONF_RED, \ + CONF_SPEED, CONF_STATE, CONF_TRANSITION_LENGTH, CONF_UPDATE_INTERVAL, CONF_WHITE, CONF_WIDTH +from esphomeyaml.helpers import Action, Application, ArrayInitializer, Component, Nameable, \ + Pvariable, StructInitializer, TemplateArguments, add, add_job, esphomelib_ns, float_, \ + get_variable, process_lambda, setup_mqtt_component, std_string, templatable, uint32 PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({ @@ -32,7 +30,6 @@ TurnOnAction = light_ns.class_('TurnOnAction', Action) LightColorValues = light_ns.class_('LightColorValues') - MQTTJSONLightComponent = light_ns.class_('MQTTJSONLightComponent', mqtt.MQTTComponent) # Effects @@ -354,7 +351,6 @@ def setup_light(light_obj, mqtt_obj, config): BUILD_FLAGS = '-DUSE_LIGHT' - CONF_LIGHT_TOGGLE = 'light.toggle' LIGHT_TOGGLE_ACTION_SCHEMA = maybe_simple_id({ vol.Required(CONF_ID): cv.use_variable_id(LightState), diff --git a/esphomeyaml/components/time/sntp.py b/esphomeyaml/components/time/sntp.py index 0422c8b6fa..2f63891c07 100644 --- a/esphomeyaml/components/time/sntp.py +++ b/esphomeyaml/components/time/sntp.py @@ -9,7 +9,7 @@ SNTPComponent = time_.time_ns.class_('SNTPComponent', time_.RealTimeClockCompone PLATFORM_SCHEMA = time_.TIME_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(SNTPComponent), - vol.Optional(CONF_SERVERS): vol.All(cv.ensure_list, [cv.string], vol.Length(max=3)), + vol.Optional(CONF_SERVERS): vol.All(cv.ensure_list, [cv.string], vol.Length(min=1, max=3)), vol.Optional(CONF_LAMBDA): cv.lambda_, }).extend(cv.COMPONENT_SCHEMA.schema) @@ -18,7 +18,9 @@ def to_code(config): rhs = App.make_sntp_component() sntp = Pvariable(config[CONF_ID], rhs) if CONF_SERVERS in config: - add(sntp.set_servers(*config[CONF_SERVERS])) + servers = config[CONF_SERVERS] + servers += [''] * (3 - len(servers)) + add(sntp.set_servers(*servers)) time_.setup_time(sntp, config) setup_component(sntp, config)