controller.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "controller.h"
  2. #include "esphome/core/log.h"
  3. #include "esphome/core/application.h"
  4. namespace esphome {
  5. void Controller::setup_controller() {
  6. #ifdef USE_BINARY_SENSOR
  7. for (auto *obj : App.get_binary_sensors()) {
  8. if (!obj->is_internal())
  9. obj->add_on_state_callback([this, obj](bool state) { this->on_binary_sensor_update(obj, state); });
  10. }
  11. #endif
  12. #ifdef USE_FAN
  13. for (auto *obj : App.get_fans()) {
  14. if (!obj->is_internal())
  15. obj->add_on_state_callback([this, obj]() { this->on_fan_update(obj); });
  16. }
  17. #endif
  18. #ifdef USE_LIGHT
  19. for (auto *obj : App.get_lights()) {
  20. if (!obj->is_internal())
  21. obj->add_new_remote_values_callback([this, obj]() { this->on_light_update(obj); });
  22. }
  23. #endif
  24. #ifdef USE_SENSOR
  25. for (auto *obj : App.get_sensors()) {
  26. if (!obj->is_internal())
  27. obj->add_on_state_callback([this, obj](float state) { this->on_sensor_update(obj, state); });
  28. }
  29. #endif
  30. #ifdef USE_SWITCH
  31. for (auto *obj : App.get_switches()) {
  32. if (!obj->is_internal())
  33. obj->add_on_state_callback([this, obj](bool state) { this->on_switch_update(obj, state); });
  34. }
  35. #endif
  36. #ifdef USE_COVER
  37. for (auto *obj : App.get_covers()) {
  38. if (!obj->is_internal())
  39. obj->add_on_state_callback([this, obj]() { this->on_cover_update(obj); });
  40. }
  41. #endif
  42. #ifdef USE_TEXT_SENSOR
  43. for (auto *obj : App.get_text_sensors()) {
  44. if (!obj->is_internal())
  45. obj->add_on_state_callback([this, obj](std::string state) { this->on_text_sensor_update(obj, state); });
  46. }
  47. #endif
  48. #ifdef USE_CLIMATE
  49. for (auto *obj : App.get_climates()) {
  50. if (!obj->is_internal())
  51. obj->add_on_state_callback([this, obj]() { this->on_climate_update(obj); });
  52. }
  53. #endif
  54. }
  55. } // namespace esphome