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.

49 lines
1.8 KiB

  1. import esphome.codegen as cg
  2. import esphome.config_validation as cv
  3. import esphome.components.gpio.output as gpio_output
  4. from esphome.components import light, gpio, ledc
  5. from esphome.const import CONF_RED, CONF_GREEN, CONF_BLUE, CONF_WHITE, CONF_OUTPUT_ID
  6. CONF_MASTER1 = "master1"
  7. CONF_MASTER2 = "master2"
  8. CODEOWNERS = ["@mmakaay"]
  9. yeelight_ns = cg.esphome_ns.namespace("yeelight")
  10. bs2_ns = yeelight_ns.namespace("bs2")
  11. light_state = bs2_ns.class_("YeelightBS2LightState", cg.Nameable, cg.Component)
  12. light_output = bs2_ns.class_("YeelightBS2LightOutput", light.LightOutput)
  13. CONFIG_SCHEMA = light.RGB_LIGHT_SCHEMA.extend({
  14. cv.GenerateID(): cv.declare_id(light_state),
  15. cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(light_output),
  16. cv.Required(CONF_RED): cv.use_id(ledc),
  17. cv.Required(CONF_GREEN): cv.use_id(ledc),
  18. cv.Required(CONF_BLUE): cv.use_id(ledc),
  19. cv.Required(CONF_WHITE): cv.use_id(ledc),
  20. cv.Required(CONF_WHITE): cv.use_id(ledc),
  21. cv.Required(CONF_MASTER1): cv.use_id(gpio_output.GPIOBinaryOutput),
  22. cv.Required(CONF_MASTER2): cv.use_id(gpio_output.GPIOBinaryOutput),
  23. })
  24. import json;
  25. def to_code(config):
  26. var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
  27. yield light.register_light(var, config)
  28. led_white = yield cg.get_variable(config[CONF_WHITE])
  29. cg.add(var.set_white_output(led_white))
  30. led_red = yield cg.get_variable(config[CONF_RED])
  31. cg.add(var.set_red_output(led_red))
  32. led_green = yield cg.get_variable(config[CONF_GREEN])
  33. cg.add(var.set_green_output(led_green))
  34. led_blue = yield cg.get_variable(config[CONF_BLUE])
  35. cg.add(var.set_blue_output(led_blue))
  36. master1 = yield cg.get_variable(config[CONF_MASTER1])
  37. cg.add(var.set_master1_output(master1))
  38. master2 = yield cg.get_variable(config[CONF_MASTER2])
  39. cg.add(var.set_master2_output(master2))