ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
component_iterator.h
Go to the documentation of this file.
1#pragma once
2
6
7#ifdef USE_CAMERA
9#endif
10
11namespace esphome {
12
13#ifdef USE_API_USER_DEFINED_ACTIONS
14namespace api {
15class UserServiceDescriptor;
16} // namespace api
17#endif
18
19#ifdef USE_INFRARED
20namespace infrared {
21class Infrared;
22} // namespace infrared
23#endif
24#ifdef USE_RADIO_FREQUENCY
25namespace radio_frequency {
26class RadioFrequency;
27} // namespace radio_frequency
28#endif
29
31 public:
32 void begin(bool include_internal = false);
33 void advance();
34 bool completed() const { return this->state_ == IteratorState::NONE; }
35 virtual bool on_begin();
36// Pure virtual entity callbacks (generated from entity_types.h)
37// NOLINTBEGIN(bugprone-macro-parentheses)
38#define ENTITY_TYPE_(type, singular, plural, count, upper) virtual bool on_##singular(type *obj) = 0;
39#define ENTITY_CONTROLLER_TYPE_(type, singular, plural, count, upper, callback) \
40 ENTITY_TYPE_(type, singular, plural, count, upper)
42#undef ENTITY_TYPE_
43#undef ENTITY_CONTROLLER_TYPE_
44// NOLINTEND(bugprone-macro-parentheses)
45// Non-entity and non-pure-virtual callbacks (have default implementations)
46#ifdef USE_API_USER_DEFINED_ACTIONS
47 virtual bool on_service(api::UserServiceDescriptor *service);
48#endif
49#ifdef USE_CAMERA
50 virtual bool on_camera(camera::Camera *camera);
51#endif
52 virtual bool on_end();
53
54 protected:
55 // Iterates over all ESPHome entities (sensors, switches, lights, etc.)
56 // Supports up to 256 entity types and up to 65,535 entities of each type
57 enum class IteratorState : uint8_t {
58 NONE = 0,
59 BEGIN,
60// Entity iterator states (generated from entity_types.h)
61// NOLINTBEGIN(bugprone-macro-parentheses)
62#define ENTITY_TYPE_(type, singular, plural, count, upper) upper,
63#define ENTITY_CONTROLLER_TYPE_(type, singular, plural, count, upper, callback) upper,
65#undef ENTITY_TYPE_
66#undef ENTITY_CONTROLLER_TYPE_
67// NOLINTEND(bugprone-macro-parentheses)
68#ifdef USE_API_USER_DEFINED_ACTIONS
69 SERVICE,
70#endif
71#ifdef USE_CAMERA
72 CAMERA,
73#endif
74 MAX,
75 };
76 uint16_t at_{0}; // Supports up to 65,535 entities per type
78 bool include_internal_{false};
79
80 template<typename Container>
81 void process_platform_item_(const Container &items,
82 bool (ComponentIterator::*on_item)(typename Container::value_type)) {
83 if (this->at_ >= items.size()) {
84 this->advance_platform_();
85 } else {
86 typename Container::value_type item = items[this->at_];
87 if ((item->is_internal() && !this->include_internal_) || (this->*on_item)(item)) {
88 this->at_++;
89 }
90 }
91 }
92
93 void advance_platform_();
94};
95
96} // namespace esphome
void process_platform_item_(const Container &items, bool(ComponentIterator::*on_item)(typename Container::value_type))
void begin(bool include_internal=false)
virtual bool on_service(api::UserServiceDescriptor *service)
virtual bool on_camera(camera::Camera *camera)
Abstract camera base class.
Definition camera.h:114