You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.6 KiB

  1. import esphome.codegen as cg
  2. import esphome.config_validation as cv
  3. from esphome.components import light, output, gpio
  4. from esphome.const import CONF_RED, CONF_GREEN, CONF_BLUE, CONF_WHITE, CONF_OUTPUT_ID
  5. CONF_MASTER1 = "master1"
  6. CONF_MASTER2 = "master2"
  7. rgbww_ns = cg.esphome_ns.namespace("rgbww")
  8. YeelightBS2LightOutput = rgbww_ns.class_("YeelightBS2LightOutput", light.LightOutput)
  9. CONFIG_SCHEMA = light.RGB_LIGHT_SCHEMA.extend(
  10. {
  11. cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(YeelightBS2LightOutput),
  12. cv.Required(CONF_RED): cv.use_id(output.FloatOutput),
  13. cv.Required(CONF_GREEN): cv.use_id(output.FloatOutput),
  14. cv.Required(CONF_BLUE): cv.use_id(output.FloatOutput),
  15. cv.Required(CONF_WHITE): cv.use_id(output.FloatOutput),
  16. cv.Required(CONF_WHITE): cv.use_id(output.FloatOutput),
  17. cv.Required(CONF_MASTER1): cv.use_id(gpio.output.GPIOBinaryOutput),
  18. cv.Required(CONF_MASTER2): cv.use_id(gpio.output.GPIOBinaryOutput),
  19. }
  20. )
  21. def to_code(config):
  22. var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
  23. yield light.register_light(var, config)
  24. red = yield cg.get_variable(config[CONF_RED])
  25. cg.add(var.set_red(red))
  26. green = yield cg.get_variable(config[CONF_GREEN])
  27. cg.add(var.set_green(green))
  28. blue = yield cg.get_variable(config[CONF_BLUE])
  29. cg.add(var.set_blue(blue))
  30. white = yield cg.get_variable(config[CONF_WHITE])
  31. cg.add(var.set_white(white))
  32. master1 = yield cg.get_variable(config[CONF_MASTER1])
  33. cg.add(var.set_master1(master1))
  34. master2 = yield cg.get_variable(config[CONF_MASTER2])
  35. cg.add(var.set_master2(master2))