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
960 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 bslamp2_ns, CODEOWNERS
  6. from ..light import XiaomiBslamp2LightOutput
  7. DEPENDENCIES = ["xiaomi_bslamp2"]
  8. CONF_LIGHT_ID = "light_id"
  9. XiaomiBslamp2LightModeTextSensor = bslamp2_ns.class_(
  10. "XiaomiBslamp2LightModeTextSensor", text_sensor.TextSensor, cg.Component
  11. )
  12. CONFIG_SCHEMA = text_sensor.TEXT_SENSOR_SCHEMA.extend(
  13. {
  14. cv.GenerateID(): cv.declare_id(XiaomiBslamp2LightModeTextSensor),
  15. cv.GenerateID(CONF_OUTPUT_ID): cv.use_id(XiaomiBslamp2LightOutput),
  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))