util.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma once
  2. #include "esphome/core/helpers.h"
  3. #include "esphome/core/component.h"
  4. #include "esphome/core/controller.h"
  5. #ifdef USE_ESP32_CAMERA
  6. #include "esphome/components/esp32_camera/esp32_camera.h"
  7. #endif
  8. namespace esphome {
  9. namespace api {
  10. class APIServer;
  11. class UserServiceDescriptor;
  12. class ComponentIterator {
  13. public:
  14. ComponentIterator(APIServer *server);
  15. void begin();
  16. void advance();
  17. virtual bool on_begin();
  18. #ifdef USE_BINARY_SENSOR
  19. virtual bool on_binary_sensor(binary_sensor::BinarySensor *binary_sensor) = 0;
  20. #endif
  21. #ifdef USE_COVER
  22. virtual bool on_cover(cover::Cover *cover) = 0;
  23. #endif
  24. #ifdef USE_FAN
  25. virtual bool on_fan(fan::FanState *fan) = 0;
  26. #endif
  27. #ifdef USE_LIGHT
  28. virtual bool on_light(light::LightState *light) = 0;
  29. #endif
  30. #ifdef USE_SENSOR
  31. virtual bool on_sensor(sensor::Sensor *sensor) = 0;
  32. #endif
  33. #ifdef USE_SWITCH
  34. virtual bool on_switch(switch_::Switch *a_switch) = 0;
  35. #endif
  36. #ifdef USE_TEXT_SENSOR
  37. virtual bool on_text_sensor(text_sensor::TextSensor *text_sensor) = 0;
  38. #endif
  39. virtual bool on_service(UserServiceDescriptor *service);
  40. #ifdef USE_ESP32_CAMERA
  41. virtual bool on_camera(esp32_camera::ESP32Camera *camera);
  42. #endif
  43. #ifdef USE_CLIMATE
  44. virtual bool on_climate(climate::Climate *climate) = 0;
  45. #endif
  46. virtual bool on_end();
  47. protected:
  48. enum class IteratorState {
  49. NONE = 0,
  50. BEGIN,
  51. #ifdef USE_BINARY_SENSOR
  52. BINARY_SENSOR,
  53. #endif
  54. #ifdef USE_COVER
  55. COVER,
  56. #endif
  57. #ifdef USE_FAN
  58. FAN,
  59. #endif
  60. #ifdef USE_LIGHT
  61. LIGHT,
  62. #endif
  63. #ifdef USE_SENSOR
  64. SENSOR,
  65. #endif
  66. #ifdef USE_SWITCH
  67. SWITCH,
  68. #endif
  69. #ifdef USE_TEXT_SENSOR
  70. TEXT_SENSOR,
  71. #endif
  72. SERVICE,
  73. #ifdef USE_ESP32_CAMERA
  74. CAMERA,
  75. #endif
  76. #ifdef USE_CLIMATE
  77. CLIMATE,
  78. #endif
  79. MAX,
  80. } state_{IteratorState::NONE};
  81. size_t at_{0};
  82. APIServer *server_;
  83. };
  84. } // namespace api
  85. } // namespace esphome