mirror of
https://github.com/esphome/esphome.git
synced 2025-04-16 07:40:29 +01:00
26 lines
1.1 KiB
Python
26 lines
1.1 KiB
Python
import voluptuous as vol
|
|
|
|
from esphome.components import light, output
|
|
import esphome.config_validation as cv
|
|
from esphome.const import CONF_BLUE, CONF_GREEN, CONF_MAKE_ID, CONF_NAME, CONF_RED
|
|
from esphome.cpp_generator import get_variable, variable
|
|
from esphome.cpp_helpers import setup_component
|
|
from esphome.cpp_types import App
|
|
|
|
PLATFORM_SCHEMA = cv.nameable(light.PLATFORM_SCHEMA.extend({
|
|
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight),
|
|
vol.Required(CONF_RED): cv.use_variable_id(output.FloatOutput),
|
|
vol.Required(CONF_GREEN): cv.use_variable_id(output.FloatOutput),
|
|
vol.Required(CONF_BLUE): cv.use_variable_id(output.FloatOutput),
|
|
}).extend(light.RGB_LIGHT_SCHEMA.schema).extend(cv.COMPONENT_SCHEMA.schema))
|
|
|
|
|
|
def to_code(config):
|
|
red = yield get_variable(config[CONF_RED])
|
|
green = yield get_variable(config[CONF_GREEN])
|
|
blue = yield get_variable(config[CONF_BLUE])
|
|
rhs = App.make_rgb_light(config[CONF_NAME], red, green, blue)
|
|
light_struct = variable(config[CONF_MAKE_ID], rhs)
|
|
light.setup_light(light_struct.Pstate, light_struct.Poutput, config)
|
|
setup_component(light_struct.Pstate, config)
|