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.

40 lines
1.0 KiB

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