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.

29 lines
957 B

  1. import esphome.codegen as cg
  2. import esphome.config_validation as cv
  3. from esphome.components import sensor
  4. from esphome.const import CONF_ID, CONF_FORCE_UPDATE
  5. from .. import (
  6. bs2_ns, CODEOWNERS,
  7. CONF_FRONT_PANEL_HAL_ID, FrontPanelHAL
  8. )
  9. AUTO_LOAD = ["yeelight_bs2"]
  10. YeelightBS2SliderSensor = bs2_ns.class_(
  11. "YeelightBS2SliderSensor", sensor.Sensor, cg.Component)
  12. CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend(
  13. {
  14. cv.GenerateID(): cv.declare_id(YeelightBS2SliderSensor),
  15. cv.GenerateID(CONF_FRONT_PANEL_HAL_ID): cv.use_id(FrontPanelHAL),
  16. cv.Optional(CONF_FORCE_UPDATE, default=True): cv.boolean,
  17. }
  18. ).extend(cv.COMPONENT_SCHEMA)
  19. def to_code(config):
  20. var = cg.new_Pvariable(config[CONF_ID])
  21. yield cg.register_component(var, config)
  22. yield sensor.register_sensor(var, config)
  23. front_panel_hal_var = yield cg.get_variable(config[CONF_FRONT_PANEL_HAL_ID])
  24. cg.add(var.set_parent(front_panel_hal_var))