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.

30 lines
940 B

  1. import esphome.codegen as cg
  2. import esphome.config_validation as cv
  3. from esphome.components import text_sensor
  4. from esphome.const import CONF_ID, CONF_OUTPUT_ID
  5. from .. import bs2_ns, CODEOWNERS
  6. from ..light import YeelightBS2LightOutput
  7. DEPENDENCIES = ["yeelight_bs2"]
  8. CONF_LIGHT_ID = "light_id"
  9. YeelightBS2LightModeTextSensor = bs2_ns.class_(
  10. "YeelightBS2LightModeTextSensor", text_sensor.TextSensor, cg.Component
  11. )
  12. CONFIG_SCHEMA = text_sensor.TEXT_SENSOR_SCHEMA.extend(
  13. {
  14. cv.GenerateID(): cv.declare_id(YeelightBS2LightModeTextSensor),
  15. cv.GenerateID(CONF_OUTPUT_ID): cv.use_id(YeelightBS2LightOutput),
  16. }
  17. ).extend(cv.COMPONENT_SCHEMA)
  18. def to_code(config):
  19. var = cg.new_Pvariable(config[CONF_ID])
  20. yield cg.register_component(var, config)
  21. yield text_sensor.register_text_sensor(var, config)
  22. parent_var = yield cg.get_variable(config[CONF_OUTPUT_ID])
  23. cg.add(var.set_parent(parent_var))