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
|
|
|
|
from esphome.const import CONF_OUTPUT_ID, CONF_OUTPUT
|
|
|
|
|
2021-03-07 16:03:16 -03:00
|
|
|
monochromatic_ns = cg.esphome_ns.namespace("monochromatic")
|
|
|
|
MonochromaticLightOutput = monochromatic_ns.class_(
|
|
|
|
"MonochromaticLightOutput", light.LightOutput
|
|
|
|
)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2021-03-07 16:03:16 -03:00
|
|
|
CONFIG_SCHEMA = light.BRIGHTNESS_ONLY_LIGHT_SCHEMA.extend(
|
|
|
|
{
|
|
|
|
cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(MonochromaticLightOutput),
|
|
|
|
cv.Required(CONF_OUTPUT): cv.use_id(output.FloatOutput),
|
|
|
|
}
|
|
|
|
)
|
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)
|
2019-04-22 21:56:30 +02:00
|
|
|
|
2021-05-24 10:58:29 +02:00
|
|
|
out = await cg.get_variable(config[CONF_OUTPUT])
|
2019-04-22 21:56:30 +02:00
|
|
|
cg.add(var.set_output(out))
|