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.

35 lines
918 B

  1. #pragma once
  2. #include "esphome/components/text_sensor/text_sensor.h"
  3. namespace esphome {
  4. namespace yeelight {
  5. namespace bs2 {
  6. /**
  7. * A text sensor, used for propagating the active light mode on the
  8. * Yeelight Bedside Lamp 2.
  9. *
  10. * The possible light modes are "off", "rgb", "white" and "night".
  11. */
  12. class YeelightBS2LightModeTextSensor : public text_sensor::TextSensor, public Component {
  13. public:
  14. void set_parent(YeelightBS2LightOutput *light) { light_ = light; }
  15. void setup() {
  16. light_->add_on_light_mode_callback([this](std::string light_mode) {
  17. if (last_light_mode_ != light_mode) {
  18. publish_state(light_mode);
  19. last_light_mode_ = light_mode;
  20. }
  21. });
  22. }
  23. protected:
  24. YeelightBS2LightOutput *light_;
  25. std::string last_light_mode_ = LIGHT_MODE_UNKNOWN;
  26. };
  27. } // namespace bs2
  28. } // namespace yeelight
  29. } // namespace esphome