mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Validate color temperature values for RGBWW/CWWW lights (#1957)
Check if the color temperature of the cold white channel is colder (less) than the warm white channel.
This commit is contained in:
parent
2cb3015a28
commit
7051f897bc
3 changed files with 42 additions and 22 deletions
|
@ -14,7 +14,8 @@ CWWWLightOutput = cwww_ns.class_("CWWWLightOutput", light.LightOutput)
|
|||
|
||||
CONF_CONSTANT_BRIGHTNESS = "constant_brightness"
|
||||
|
||||
CONFIG_SCHEMA = light.RGB_LIGHT_SCHEMA.extend(
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
light.RGB_LIGHT_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(CWWWLightOutput),
|
||||
cv.Required(CONF_COLD_WHITE): cv.use_id(output.FloatOutput),
|
||||
|
@ -23,6 +24,8 @@ CONFIG_SCHEMA = light.RGB_LIGHT_SCHEMA.extend(
|
|||
cv.Required(CONF_WARM_WHITE_COLOR_TEMPERATURE): cv.color_temperature,
|
||||
cv.Optional(CONF_CONSTANT_BRIGHTNESS, default=False): cv.boolean,
|
||||
}
|
||||
),
|
||||
light.validate_color_temperature_channels,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ from esphome.const import (
|
|||
CONF_ON_TURN_OFF,
|
||||
CONF_ON_TURN_ON,
|
||||
CONF_TRIGGER_ID,
|
||||
CONF_COLD_WHITE_COLOR_TEMPERATURE,
|
||||
CONF_WARM_WHITE_COLOR_TEMPERATURE,
|
||||
)
|
||||
from esphome.core import coroutine_with_priority
|
||||
from .automation import light_control_to_code # noqa
|
||||
|
@ -104,6 +106,18 @@ ADDRESSABLE_LIGHT_SCHEMA = RGB_LIGHT_SCHEMA.extend(
|
|||
)
|
||||
|
||||
|
||||
def validate_color_temperature_channels(value):
|
||||
if (
|
||||
value[CONF_COLD_WHITE_COLOR_TEMPERATURE]
|
||||
>= value[CONF_WARM_WHITE_COLOR_TEMPERATURE]
|
||||
):
|
||||
raise cv.Invalid(
|
||||
"Color temperature of the cold white channel must be colder than that of the warm white channel.",
|
||||
path=[CONF_COLD_WHITE_COLOR_TEMPERATURE],
|
||||
)
|
||||
return value
|
||||
|
||||
|
||||
async def setup_light_core_(light_var, output_var, config):
|
||||
cg.add(light_var.set_restore_mode(config[CONF_RESTORE_MODE]))
|
||||
if CONF_INTERNAL in config:
|
||||
|
|
|
@ -18,7 +18,8 @@ RGBWWLightOutput = rgbww_ns.class_("RGBWWLightOutput", light.LightOutput)
|
|||
CONF_CONSTANT_BRIGHTNESS = "constant_brightness"
|
||||
CONF_COLOR_INTERLOCK = "color_interlock"
|
||||
|
||||
CONFIG_SCHEMA = light.RGB_LIGHT_SCHEMA.extend(
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
light.RGB_LIGHT_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(RGBWWLightOutput),
|
||||
cv.Required(CONF_RED): cv.use_id(output.FloatOutput),
|
||||
|
@ -31,6 +32,8 @@ CONFIG_SCHEMA = light.RGB_LIGHT_SCHEMA.extend(
|
|||
cv.Optional(CONF_CONSTANT_BRIGHTNESS, default=False): cv.boolean,
|
||||
cv.Optional(CONF_COLOR_INTERLOCK, default=False): cv.boolean,
|
||||
}
|
||||
),
|
||||
light.validate_color_temperature_channels,
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue