From 5904aaec73d7e1414d100f99dc80f9618a345124 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sat, 20 Oct 2018 12:24:21 +0200 Subject: [PATCH] Add FastLED color correction option --- esphomeyaml/components/light/fastled_clockless.py | 7 ++++++- esphomeyaml/components/light/fastled_spi.py | 9 +++++++-- esphomeyaml/const.py | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/esphomeyaml/components/light/fastled_clockless.py b/esphomeyaml/components/light/fastled_clockless.py index 1326853bd5..767703c152 100644 --- a/esphomeyaml/components/light/fastled_clockless.py +++ b/esphomeyaml/components/light/fastled_clockless.py @@ -6,7 +6,7 @@ from esphomeyaml.components import light from esphomeyaml.components.power_supply import PowerSupplyComponent from esphomeyaml.const import CONF_CHIPSET, CONF_DEFAULT_TRANSITION_LENGTH, CONF_GAMMA_CORRECT, \ CONF_MAKE_ID, CONF_MAX_REFRESH_RATE, CONF_NAME, CONF_NUM_LEDS, CONF_PIN, CONF_POWER_SUPPLY, \ - CONF_RGB_ORDER, CONF_EFFECTS + CONF_RGB_ORDER, CONF_EFFECTS, CONF_COLOR_CORRECT from esphomeyaml.helpers import App, Application, RawExpression, TemplateArguments, add, \ get_variable, variable @@ -66,6 +66,7 @@ PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({ vol.Optional(CONF_RGB_ORDER): vol.All(vol.Upper, cv.one_of(*RGB_ORDERS)), vol.Optional(CONF_GAMMA_CORRECT): cv.positive_float, + vol.Optional(CONF_COLOR_CORRECT): vol.All([cv.percentage], vol.Length(min=3, max=3)), vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH): cv.positive_time_period_milliseconds, vol.Optional(CONF_POWER_SUPPLY): cv.use_variable_id(PowerSupplyComponent), vol.Optional(CONF_EFFECTS): light.validate_effects(light.FASTLED_EFFECTS), @@ -93,6 +94,10 @@ def to_code(config): yield add(fast_led.set_power_supply(power_supply)) + if CONF_COLOR_CORRECT in config: + r, g, b = config[CONF_COLOR_CORRECT] + add(fast_led.set_correction(r, g, b)) + light.setup_light(make.Pstate, make.Pmqtt, config) diff --git a/esphomeyaml/components/light/fastled_spi.py b/esphomeyaml/components/light/fastled_spi.py index ec1ccb3509..a74a435d5b 100644 --- a/esphomeyaml/components/light/fastled_spi.py +++ b/esphomeyaml/components/light/fastled_spi.py @@ -6,7 +6,7 @@ from esphomeyaml.components import light from esphomeyaml.components.power_supply import PowerSupplyComponent from esphomeyaml.const import CONF_CHIPSET, CONF_CLOCK_PIN, CONF_DATA_PIN, \ CONF_DEFAULT_TRANSITION_LENGTH, CONF_GAMMA_CORRECT, CONF_MAKE_ID, CONF_MAX_REFRESH_RATE, \ - CONF_NAME, CONF_NUM_LEDS, CONF_POWER_SUPPLY, CONF_RGB_ORDER, CONF_EFFECTS + CONF_NAME, CONF_NUM_LEDS, CONF_POWER_SUPPLY, CONF_RGB_ORDER, CONF_EFFECTS, CONF_COLOR_CORRECT from esphomeyaml.helpers import App, Application, RawExpression, TemplateArguments, add, \ get_variable, variable @@ -44,6 +44,7 @@ PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({ vol.Optional(CONF_MAX_REFRESH_RATE): cv.positive_time_period_microseconds, vol.Optional(CONF_GAMMA_CORRECT): cv.positive_float, + vol.Optional(CONF_COLOR_CORRECT): vol.All([cv.percentage], vol.Length(min=3, max=3)), vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH): cv.positive_time_period_milliseconds, vol.Optional(CONF_POWER_SUPPLY): cv.use_variable_id(PowerSupplyComponent), vol.Optional(CONF_EFFECTS): light.validate_effects(light.FASTLED_EFFECTS), @@ -73,7 +74,11 @@ def to_code(config): yield add(fast_led.set_power_supply(power_supply)) - light.setup_light(make.Pstate, make.Pmqtt, config) + if CONF_COLOR_CORRECT in config: + r, g, b = config[CONF_COLOR_CORRECT] + add(fast_led.set_correction(r, g, b)) + + light.setup_light(make.Pstate, make.Pmqtt, config) BUILD_FLAGS = '-DUSE_FAST_LED_LIGHT' diff --git a/esphomeyaml/const.py b/esphomeyaml/const.py index bad9a04c65..50171e69e8 100644 --- a/esphomeyaml/const.py +++ b/esphomeyaml/const.py @@ -342,6 +342,7 @@ CONF_CRON = 'cron' CONF_POWER_SAVE_MODE = 'power_save_mode' CONF_POWER_ON_VALUE = 'power_on_value' CONF_ON_TAG = 'on_tag' +CONF_COLOR_CORRECT = 'color_correct' CONF_ON_JSON_MESSAGE = 'on_json_message' ALLOWED_NAME_CHARS = u'abcdefghijklmnopqrstuvwxyz0123456789_'