2019-04-17 12:06:00 +02:00
|
|
|
import esphome.codegen as cg
|
|
|
|
import esphome.config_validation as cv
|
|
|
|
from esphome.components import light, output
|
2021-03-07 20:03:16 +01:00
|
|
|
from esphome.const import (
|
2021-08-10 11:28:56 +02:00
|
|
|
CONF_CONSTANT_BRIGHTNESS,
|
2021-03-07 20:03:16 +01:00
|
|
|
CONF_OUTPUT_ID,
|
|
|
|
CONF_COLD_WHITE,
|
|
|
|
CONF_WARM_WHITE,
|
|
|
|
CONF_COLD_WHITE_COLOR_TEMPERATURE,
|
|
|
|
CONF_WARM_WHITE_COLOR_TEMPERATURE,
|
|
|
|
)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
cwww_ns = cg.esphome_ns.namespace("cwww")
|
|
|
|
CWWWLightOutput = cwww_ns.class_("CWWWLightOutput", light.LightOutput)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2021-06-24 00:07:27 +02:00
|
|
|
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),
|
|
|
|
cv.Required(CONF_WARM_WHITE): cv.use_id(output.FloatOutput),
|
2021-07-29 19:11:56 +02:00
|
|
|
cv.Optional(CONF_COLD_WHITE_COLOR_TEMPERATURE): cv.color_temperature,
|
|
|
|
cv.Optional(CONF_WARM_WHITE_COLOR_TEMPERATURE): cv.color_temperature,
|
2021-06-24 00:07:27 +02:00
|
|
|
cv.Optional(CONF_CONSTANT_BRIGHTNESS, default=False): cv.boolean,
|
|
|
|
}
|
|
|
|
),
|
2021-07-29 19:11:56 +02:00
|
|
|
cv.has_none_or_all_keys(
|
|
|
|
[CONF_COLD_WHITE_COLOR_TEMPERATURE, CONF_WARM_WHITE_COLOR_TEMPERATURE]
|
|
|
|
),
|
2021-06-24 00:07:27 +02:00
|
|
|
light.validate_color_temperature_channels,
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
|
2021-05-24 10:58:29 +02:00
|
|
|
async def to_code(config):
|
2019-04-22 21:56:30 +02:00
|
|
|
var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
|
2021-05-24 10:58:29 +02:00
|
|
|
await light.register_light(var, config)
|
2021-07-29 19:11:56 +02:00
|
|
|
|
2021-05-24 10:58:29 +02:00
|
|
|
cwhite = await cg.get_variable(config[CONF_COLD_WHITE])
|
2019-04-22 21:56:30 +02:00
|
|
|
cg.add(var.set_cold_white(cwhite))
|
2021-07-29 19:11:56 +02:00
|
|
|
if CONF_COLD_WHITE_COLOR_TEMPERATURE in config:
|
|
|
|
cg.add(
|
|
|
|
var.set_cold_white_temperature(config[CONF_COLD_WHITE_COLOR_TEMPERATURE])
|
|
|
|
)
|
2019-04-22 21:56:30 +02:00
|
|
|
|
2021-05-24 10:58:29 +02:00
|
|
|
wwhite = await cg.get_variable(config[CONF_WARM_WHITE])
|
2019-04-22 21:56:30 +02:00
|
|
|
cg.add(var.set_warm_white(wwhite))
|
2021-07-29 19:11:56 +02:00
|
|
|
if CONF_WARM_WHITE_COLOR_TEMPERATURE in config:
|
|
|
|
cg.add(
|
|
|
|
var.set_warm_white_temperature(config[CONF_WARM_WHITE_COLOR_TEMPERATURE])
|
|
|
|
)
|
|
|
|
|
2020-04-08 14:31:23 +02:00
|
|
|
cg.add(var.set_constant_brightness(config[CONF_CONSTANT_BRIGHTNESS]))
|