ESPHome 2026.1.4
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
26 public:
27 void begin(bool include_internal = false);
28 void advance();
29 virtual bool on_begin();
30#ifdef USE_BINARY_SENSOR
31 virtual bool on_binary_sensor(binary_sensor::BinarySensor *binary_sensor) = 0;
32#endif
33#ifdef USE_COVER
34 virtual bool on_cover(cover::Cover *cover) = 0;
35#endif
36#ifdef USE_FAN
37 virtual bool on_fan(fan::Fan *fan) = 0;
38#endif
39#ifdef USE_LIGHT
40 virtual bool on_light(light::LightState *light) = 0;
41#endif
42#ifdef USE_SENSOR
43 virtual bool on_sensor(sensor::Sensor *sensor) = 0;
44#endif
45#ifdef USE_SWITCH
46 virtual bool on_switch(switch_::Switch *a_switch) = 0;
47#endif
48#ifdef USE_BUTTON
49 virtual bool on_button(button::Button *button) = 0;
50#endif
51#ifdef USE_TEXT_SENSOR
52 virtual bool on_text_sensor(text_sensor::TextSensor *text_sensor) = 0;
53#endif
54#ifdef USE_API_USER_DEFINED_ACTIONS
55 virtual bool on_service(api::UserServiceDescriptor *service);
56#endif
57#ifdef USE_CAMERA
58 virtual bool on_camera(camera::Camera *camera);
59#endif
60#ifdef USE_CLIMATE
61 virtual bool on_climate(climate::Climate *climate) = 0;
62#endif
63#ifdef USE_NUMBER
64 virtual bool on_number(number::Number *number) = 0;
65#endif
66#ifdef USE_DATETIME_DATE
67 virtual bool on_date(datetime::DateEntity *date) = 0;
68#endif
69#ifdef USE_DATETIME_TIME
70 virtual bool on_time(datetime::TimeEntity *time) = 0;
71#endif
72#ifdef USE_DATETIME_DATETIME
73 virtual bool on_datetime(datetime::DateTimeEntity *datetime) = 0;
74#endif
75#ifdef USE_TEXT
76 virtual bool on_text(text::Text *text) = 0;
77#endif
78#ifdef USE_SELECT
79 virtual bool on_select(select::Select *select) = 0;
80#endif
81#ifdef USE_LOCK
82 virtual bool on_lock(lock::Lock *a_lock) = 0;
83#endif
84#ifdef USE_VALVE
85 virtual bool on_valve(valve::Valve *valve) = 0;
86#endif
87#ifdef USE_MEDIA_PLAYER
88 virtual bool on_media_player(media_player::MediaPlayer *media_player);
89#endif
90#ifdef USE_ALARM_CONTROL_PANEL
91 virtual bool on_alarm_control_panel(alarm_control_panel::AlarmControlPanel *a_alarm_control_panel) = 0;
92#endif
93#ifdef USE_WATER_HEATER
94 virtual bool on_water_heater(water_heater::WaterHeater *water_heater) = 0;
95#endif
96#ifdef USE_INFRARED
97 virtual bool on_infrared(infrared::Infrared *infrared) = 0;
98#endif
99#ifdef USE_EVENT
100 virtual bool on_event(event::Event *event) = 0;
101#endif
102#ifdef USE_UPDATE
103 virtual bool on_update(update::UpdateEntity *update) = 0;
104#endif
105 virtual bool on_end();
106
107 protected:
108 // Iterates over all ESPHome entities (sensors, switches, lights, etc.)
109 // Supports up to 256 entity types and up to 65,535 entities of each type
110 enum class IteratorState : uint8_t {
111 NONE = 0,
112 BEGIN,
113#ifdef USE_BINARY_SENSOR
115#endif
116#ifdef USE_COVER
117 COVER,
118#endif
119#ifdef USE_FAN
120 FAN,
121#endif
122#ifdef USE_LIGHT
123 LIGHT,
124#endif
125#ifdef USE_SENSOR
126 SENSOR,
127#endif
128#ifdef USE_SWITCH
129 SWITCH,
130#endif
131#ifdef USE_BUTTON
132 BUTTON,
133#endif
134#ifdef USE_TEXT_SENSOR
136#endif
137#ifdef USE_API_USER_DEFINED_ACTIONS
138 SERVICE,
139#endif
140#ifdef USE_CAMERA
141 CAMERA,
142#endif
143#ifdef USE_CLIMATE
144 CLIMATE,
145#endif
146#ifdef USE_NUMBER
147 NUMBER,
148#endif
149#ifdef USE_DATETIME_DATE
151#endif
152#ifdef USE_DATETIME_TIME
154#endif
155#ifdef USE_DATETIME_DATETIME
157#endif
158#ifdef USE_TEXT
159 TEXT,
160#endif
161#ifdef USE_SELECT
162 SELECT,
163#endif
164#ifdef USE_LOCK
165 LOCK,
166#endif
167#ifdef USE_VALVE
168 VALVE,
169#endif
170#ifdef USE_MEDIA_PLAYER
172#endif
173#ifdef USE_ALARM_CONTROL_PANEL
175#endif
176#ifdef USE_WATER_HEATER
178#endif
179#ifdef USE_INFRARED
180 INFRARED,
181#endif
182#ifdef USE_EVENT
183 EVENT,
184#endif
185#ifdef USE_UPDATE
186 UPDATE,
187#endif
188 MAX,
189 };
190 uint16_t at_{0}; // Supports up to 65,535 entities per type
192 bool include_internal_{false};
193
194 template<typename Container>
195 void process_platform_item_(const Container &items,
196 bool (ComponentIterator::*on_item)(typename Container::value_type)) {
197 if (this->at_ >= items.size()) {
198 this->advance_platform_();
199 } else {
200 typename Container::value_type item = items[this->at_];
201 if ((item->is_internal() && !this->include_internal_) || (this->*on_item)(item)) {
202 this->at_++;
203 }
204 }
205 }
206
207 void advance_platform_();
208};
209
210} // namespace esphome
virtual bool on_text(text::Text *text)=0
virtual bool on_media_player(media_player::MediaPlayer *media_player)
void process_platform_item_(const Container &items, bool(ComponentIterator::*on_item)(typename Container::value_type))
virtual bool on_alarm_control_panel(alarm_control_panel::AlarmControlPanel *a_alarm_control_panel)=0
virtual bool on_date(datetime::DateEntity *date)=0
virtual bool on_cover(cover::Cover *cover)=0
virtual bool on_datetime(datetime::DateTimeEntity *datetime)=0
virtual bool on_select(select::Select *select)=0
void begin(bool include_internal=false)
virtual bool on_button(button::Button *button)=0
virtual bool on_water_heater(water_heater::WaterHeater *water_heater)=0
virtual bool on_sensor(sensor::Sensor *sensor)=0
virtual bool on_text_sensor(text_sensor::TextSensor *text_sensor)=0
virtual bool on_valve(valve::Valve *valve)=0
virtual bool on_service(api::UserServiceDescriptor *service)
virtual bool on_fan(fan::Fan *fan)=0
virtual bool on_number(number::Number *number)=0
virtual bool on_infrared(infrared::Infrared *infrared)=0
virtual bool on_switch(switch_::Switch *a_switch)=0
virtual bool on_camera(camera::Camera *camera)
virtual bool on_climate(climate::Climate *climate)=0
virtual bool on_time(datetime::TimeEntity *time)=0
virtual bool on_light(light::LightState *light)=0
virtual bool on_event(event::Event *event)=0
virtual bool on_lock(lock::Lock *a_lock)=0
virtual bool on_update(update::UpdateEntity *update)=0
virtual bool on_binary_sensor(binary_sensor::BinarySensor *binary_sensor)=0
Base class for all binary_sensor-type classes.
Base class for all buttons.
Definition button.h:25
Abstract camera base class.
Definition camera.h:115
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:182
Base class for all cover devices.
Definition cover.h:112
Infrared - Base class for infrared remote control implementations.
Definition infrared.h:85
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:91
Base class for all locks.
Definition lock.h:111
Base-class for all numbers.
Definition number.h:29
Base-class for all selects.
Definition select.h:31
Base-class for all sensors.
Definition sensor.h:42
Base class for all switches.
Definition switch.h:39
Base-class for all text inputs.
Definition text.h:24
Base class for all valve devices.
Definition valve.h:106
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7