ESPHome  2022.6.3
list_entities.cpp
Go to the documentation of this file.
1 #ifdef USE_ARDUINO
2 
3 #include "list_entities.h"
5 #include "esphome/core/log.h"
6 #include "esphome/core/util.h"
7 
8 #include "web_server.h"
9 
10 namespace esphome {
11 namespace web_server {
12 
13 ListEntitiesIterator::ListEntitiesIterator(WebServer *web_server) : web_server_(web_server) {}
14 
15 #ifdef USE_BINARY_SENSOR
17  this->web_server_->events_.send(
18  this->web_server_->binary_sensor_json(binary_sensor, binary_sensor->state, DETAIL_ALL).c_str(), "state");
19  return true;
20 }
21 #endif
22 #ifdef USE_COVER
24  this->web_server_->events_.send(this->web_server_->cover_json(cover, DETAIL_ALL).c_str(), "state");
25  return true;
26 }
27 #endif
28 #ifdef USE_FAN
30  this->web_server_->events_.send(this->web_server_->fan_json(fan, DETAIL_ALL).c_str(), "state");
31  return true;
32 }
33 #endif
34 #ifdef USE_LIGHT
36  this->web_server_->events_.send(this->web_server_->light_json(light, DETAIL_ALL).c_str(), "state");
37  return true;
38 }
39 #endif
40 #ifdef USE_SENSOR
42  this->web_server_->events_.send(this->web_server_->sensor_json(sensor, sensor->state, DETAIL_ALL).c_str(), "state");
43  return true;
44 }
45 #endif
46 #ifdef USE_SWITCH
48  this->web_server_->events_.send(this->web_server_->switch_json(a_switch, a_switch->state, DETAIL_ALL).c_str(),
49  "state");
50  return true;
51 }
52 #endif
53 #ifdef USE_BUTTON
55  this->web_server_->events_.send(this->web_server_->button_json(button, DETAIL_ALL).c_str(), "state");
56  return true;
57 }
58 #endif
59 #ifdef USE_TEXT_SENSOR
61  this->web_server_->events_.send(
62  this->web_server_->text_sensor_json(text_sensor, text_sensor->state, DETAIL_ALL).c_str(), "state");
63  return true;
64 }
65 #endif
66 #ifdef USE_LOCK
68  this->web_server_->events_.send(this->web_server_->lock_json(a_lock, a_lock->state, DETAIL_ALL).c_str(), "state");
69  return true;
70 }
71 #endif
72 
73 #ifdef USE_CLIMATE
75  this->web_server_->events_.send(this->web_server_->climate_json(climate, DETAIL_ALL).c_str(), "state");
76  return true;
77 }
78 #endif
79 
80 #ifdef USE_NUMBER
82  this->web_server_->events_.send(this->web_server_->number_json(number, number->state, DETAIL_ALL).c_str(), "state");
83  return true;
84 }
85 #endif
86 
87 #ifdef USE_SELECT
89  this->web_server_->events_.send(this->web_server_->select_json(select, select->state, DETAIL_ALL).c_str(), "state");
90  return true;
91 }
92 #endif
93 
94 } // namespace web_server
95 } // namespace esphome
96 
97 #endif // USE_ARDUINO
Base class for all switches.
Definition: switch.h:33
bool on_sensor(sensor::Sensor *sensor) override
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition: light_state.h:32
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:713
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:361
Base class for all cover devices.
Definition: cover.h:111
This class allows users to create a web server with their ESP nodes.
Definition: web_server.h:35
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:766
LockState state
The current reported state of the lock.
Definition: lock.h:123
bool on_button(button::Button *button) override
Base class for all buttons.
Definition: button.h:22
bool on_lock(lock::Lock *a_lock) override
bool on_climate(climate::Climate *climate) override
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:385
float state
This member variable stores the last state that has passed through all filters.
Definition: sensor.h:132
Base-class for all numbers.
Definition: number.h:29
bool on_select(select::Select *select) override
bool state
The current reported state of the binary sensor.
Definition: binary_sensor.h:50
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:397
std::string light_json(light::LightState *obj, JsonDetail start_config)
Dump the light state as a JSON string.
Definition: web_server.cpp:605
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:429
bool on_cover(cover::Cover *cover) override
std::string state
Definition: select.h:26
bool on_fan(fan::Fan *fan) override
Base-class for all selects.
Definition: select.h:24
Definition: a4988.cpp:4
std::string fan_json(fan::Fan *obj, JsonDetail start_config)
Dump the fan state as a JSON string.
Definition: web_server.cpp:474
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:26
bool on_text_sensor(text_sensor::TextSensor *text_sensor) override
Base-class for all sensors.
Definition: sensor.h:47
bool state
The current reported state of the binary sensor.
Definition: switch.h:48
std::string lock_json(lock::Lock *obj, lock::LockState value, JsonDetail start_config)
Dump the lock state with its value as a JSON string.
Definition: web_server.cpp:916
bool on_light(light::LightState *light) override
std::string climate_json(climate::Climate *obj, JsonDetail start_config)
Dump the climate details.
Definition: web_server.cpp:838
Base class for all locks.
Definition: lock.h:103
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:167
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:455
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:667