ESPHome  2024.2.1
list_entities.cpp
Go to the documentation of this file.
1 #include "list_entities.h"
3 #include "esphome/core/log.h"
4 #include "esphome/core/util.h"
5 
6 #include "web_server.h"
7 
8 namespace esphome {
9 namespace web_server {
10 
11 ListEntitiesIterator::ListEntitiesIterator(WebServer *web_server) : web_server_(web_server) {}
12 
13 #ifdef USE_BINARY_SENSOR
15  this->web_server_->events_.send(
16  this->web_server_->binary_sensor_json(binary_sensor, binary_sensor->state, DETAIL_ALL).c_str(), "state");
17  return true;
18 }
19 #endif
20 #ifdef USE_COVER
22  this->web_server_->events_.send(this->web_server_->cover_json(cover, DETAIL_ALL).c_str(), "state");
23  return true;
24 }
25 #endif
26 #ifdef USE_FAN
28  this->web_server_->events_.send(this->web_server_->fan_json(fan, DETAIL_ALL).c_str(), "state");
29  return true;
30 }
31 #endif
32 #ifdef USE_LIGHT
34  this->web_server_->events_.send(this->web_server_->light_json(light, DETAIL_ALL).c_str(), "state");
35  return true;
36 }
37 #endif
38 #ifdef USE_SENSOR
40  this->web_server_->events_.send(this->web_server_->sensor_json(sensor, sensor->state, DETAIL_ALL).c_str(), "state");
41  return true;
42 }
43 #endif
44 #ifdef USE_SWITCH
46  this->web_server_->events_.send(this->web_server_->switch_json(a_switch, a_switch->state, DETAIL_ALL).c_str(),
47  "state");
48  return true;
49 }
50 #endif
51 #ifdef USE_BUTTON
53  this->web_server_->events_.send(this->web_server_->button_json(button, DETAIL_ALL).c_str(), "state");
54  return true;
55 }
56 #endif
57 #ifdef USE_TEXT_SENSOR
59  this->web_server_->events_.send(
60  this->web_server_->text_sensor_json(text_sensor, text_sensor->state, DETAIL_ALL).c_str(), "state");
61  return true;
62 }
63 #endif
64 #ifdef USE_LOCK
66  this->web_server_->events_.send(this->web_server_->lock_json(a_lock, a_lock->state, DETAIL_ALL).c_str(), "state");
67  return true;
68 }
69 #endif
70 
71 #ifdef USE_CLIMATE
73  this->web_server_->events_.send(this->web_server_->climate_json(climate, DETAIL_ALL).c_str(), "state");
74  return true;
75 }
76 #endif
77 
78 #ifdef USE_NUMBER
80  this->web_server_->events_.send(this->web_server_->number_json(number, number->state, DETAIL_ALL).c_str(), "state");
81  return true;
82 }
83 #endif
84 
85 #ifdef USE_TEXT
87  this->web_server_->events_.send(this->web_server_->text_json(text, text->state, DETAIL_ALL).c_str(), "state");
88  return true;
89 }
90 #endif
91 
92 #ifdef USE_SELECT
94  this->web_server_->events_.send(this->web_server_->select_json(select, select->state, DETAIL_ALL).c_str(), "state");
95  return true;
96 }
97 #endif
98 
99 #ifdef USE_ALARM_CONTROL_PANEL
101  this->web_server_->events_.send(
102  this->web_server_->alarm_control_panel_json(a_alarm_control_panel, a_alarm_control_panel->get_state(), DETAIL_ALL)
103  .c_str(),
104  "state");
105  return true;
106 }
107 #endif
108 
109 } // namespace web_server
110 } // namespace esphome
Base class for all switches.
Definition: switch.h:39
bool on_sensor(sensor::Sensor *sensor) override
AlarmControlPanelState get_state() const
Get the state.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition: light_state.h:34
bool on_binary_sensor(binary_sensor::BinarySensor *binary_sensor) override
std::string number_json(number::Number *obj, float value, JsonDetail start_config)
Dump the number state with its value as a JSON string.
Definition: web_server.cpp:829
std::string sensor_json(sensor::Sensor *obj, float value, JsonDetail start_config)
Dump the sensor state with its value as a JSON string.
Definition: web_server.cpp:430
Base class for all cover devices.
Definition: cover.h:111
std::string state
Definition: text.h:26
This class allows users to create a web server with their ESP nodes.
Definition: web_server.h:53
std::string select_json(select::Select *obj, const std::string &value, JsonDetail start_config)
Dump the select state with its value as a JSON string.
Definition: web_server.cpp:943
LockState state
The current reported state of the lock.
Definition: lock.h:122
bool on_button(button::Button *button) override
Base class for all buttons.
Definition: button.h:29
bool on_lock(lock::Lock *a_lock) override
bool on_alarm_control_panel(alarm_control_panel::AlarmControlPanel *a_alarm_control_panel) override
bool on_climate(climate::Climate *climate) override
bool on_text(text::Text *text) override
Base-class for all text inputs.
Definition: text.h:24
bool on_switch(switch_::Switch *a_switch) override
std::string text_sensor_json(text_sensor::TextSensor *obj, const std::string &value, JsonDetail start_config)
Dump the text sensor state with its value as a JSON string.
Definition: web_server.cpp:463
std::string text_json(text::Text *obj, const std::string &value, JsonDetail start_config)
Dump the text state with its value as a JSON string.
Definition: web_server.cpp:886
float state
This member variable stores the last state that has passed through all filters.
Definition: sensor.h:131
Base-class for all numbers.
Definition: number.h:39
bool on_select(select::Select *select) override
bool state
The current reported state of the binary sensor.
Definition: binary_sensor.h:61
std::string switch_json(switch_::Switch *obj, bool value, JsonDetail start_config)
Dump the switch state with its value as a JSON string.
Definition: web_server.cpp:475
std::string light_json(light::LightState *obj, JsonDetail start_config)
Dump the light state as a JSON string.
Definition: web_server.cpp:712
std::string button_json(button::Button *obj, JsonDetail start_config)
Dump the button details with its value as a JSON string.
Definition: web_server.cpp:510
bool on_cover(cover::Cover *cover) override
std::string state
Definition: select.h:33
bool on_fan(fan::Fan *fan) override
Base-class for all selects.
Definition: select.h:31
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
std::string fan_json(fan::Fan *obj, JsonDetail start_config)
Dump the fan state as a JSON string.
Definition: web_server.cpp:556
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:37
bool on_text_sensor(text_sensor::TextSensor *text_sensor) override
Base-class for all sensors.
Definition: sensor.h:57
std::string alarm_control_panel_json(alarm_control_panel::AlarmControlPanel *obj, alarm_control_panel::AlarmControlPanelState value, JsonDetail start_config)
Dump the alarm_control_panel state with its value as a JSON string.
bool state
The current reported state of the binary sensor.
Definition: switch.h:53
std::string lock_json(lock::Lock *obj, lock::LockState value, JsonDetail start_config)
Dump the lock state with its value as a JSON string.
bool on_light(light::LightState *light) override
std::string climate_json(climate::Climate *obj, JsonDetail start_config)
Dump the climate details.
Base class for all locks.
Definition: lock.h:103
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:168
std::string binary_sensor_json(binary_sensor::BinarySensor *obj, bool value, JsonDetail start_config)
Dump the binary sensor state with its value as a JSON string.
Definition: web_server.cpp:536
bool on_number(number::Number *number) override
std::string cover_json(cover::Cover *obj, JsonDetail start_config)
Dump the cover state as a JSON string.
Definition: web_server.cpp:782