12 #include "StreamString.h" 28 #ifdef USE_WEBSERVER_LOCAL 33 namespace web_server {
35 static const char *
const TAG =
"web_server";
37 #if USE_WEBSERVER_VERSION == 1 38 void write_row(AsyncResponseStream *stream,
EntityBase *obj,
const std::string &klass,
const std::string &action,
39 const std::function<
void(AsyncResponseStream &stream,
EntityBase *obj)> &action_func =
nullptr) {
40 stream->print(
"<tr class=\"");
41 stream->print(klass.c_str());
43 stream->print(
" internal");
44 stream->print(
"\" id=\"");
45 stream->print(klass.c_str());
48 stream->print(
"\"><td>");
50 stream->print(
"</td><td></td><td>");
51 stream->print(action.c_str());
53 action_func(*stream, obj);
55 stream->print(
"</td>");
56 stream->print(
"</tr>");
63 size_t domain_end = url.find(
'/', 1);
64 if (domain_end == std::string::npos)
66 match.
domain = url.substr(1, domain_end - 1);
71 if (url.length() == domain_end - 1)
73 size_t id_begin = domain_end + 1;
74 size_t id_end = url.find(
'/', id_begin);
76 if (id_end == std::string::npos) {
77 match.
id = url.substr(id_begin, url.length() - id_begin);
80 match.
id = url.substr(id_begin, id_end - id_begin);
81 size_t method_begin = id_end + 1;
82 match.
method = url.substr(method_begin, url.length() - method_begin);
99 ESP_LOGCONFIG(TAG,
"Setting up web server...");
103 this->
events_.onConnect([
this](AsyncEventSourceClient *client) {
120 [
this](
int level,
const char *tag,
const char *message) { this->
events_.send(message,
"log",
millis()); });
134 std::function<void()> fn;
151 ESP_LOGCONFIG(TAG,
"Web Server:");
156 #ifdef USE_WEBSERVER_LOCAL 158 AsyncWebServerResponse *response = request->beginResponse_P(200,
"text/html", INDEX_GZ,
sizeof(INDEX_GZ));
159 response->addHeader(
"Content-Encoding",
"gzip");
160 request->send(response);
164 AsyncResponseStream *stream = request->beginResponseStream(
"text/html");
166 stream->addHeader(
"Access-Control-Allow-Origin",
"*");
167 #if USE_WEBSERVER_VERSION == 1 169 stream->print(F(
"<!DOCTYPE html><html lang=\"en\"><head><meta charset=UTF-8><meta " 170 "name=viewport content=\"width=device-width, initial-scale=1,user-scalable=no\"><title>"));
171 stream->print(title.c_str());
172 stream->print(F(
"</title>"));
174 stream->print(F(
"<!DOCTYPE html><html><head><meta charset=UTF-8><link rel=icon href=data:>"));
176 #ifdef USE_WEBSERVER_CSS_INCLUDE 177 stream->print(F(
"<link rel=\"stylesheet\" href=\"/0.css\">"));
180 stream->print(F(
"<link rel=\"stylesheet\" href=\""));
182 stream->print(F(
"\">"));
184 stream->print(F(
"</head><body>"));
185 #if USE_WEBSERVER_VERSION == 1 186 stream->print(F(
"<article class=\"markdown-body\"><h1>"));
187 stream->print(title.c_str());
188 stream->print(F(
"</h1>"));
189 stream->print(F(
"<h2>States</h2><table id=\"states\"><thead><tr><th>Name<th>State<th>Actions<tbody>"));
201 write_row(stream, obj,
"switch",
"<button>Toggle</button>");
207 write_row(stream, obj,
"button",
"<button>Press</button>");
210 #ifdef USE_BINARY_SENSOR 213 write_row(stream, obj,
"binary_sensor",
"");
220 write_row(stream, obj,
"fan",
"<button>Toggle</button>");
227 write_row(stream, obj,
"light",
"<button>Toggle</button>");
231 #ifdef USE_TEXT_SENSOR 234 write_row(stream, obj,
"text_sensor",
"");
241 write_row(stream, obj,
"cover",
"<button>Open</button><button>Close</button>");
250 stream.print(R
"(<input type="number" min=")"); 252 stream.print(R"(" max=")"); 254 stream.print(R"(" step=")"); 256 stream.print(R"(" value=")"); 257 stream.print(number->state); 258 stream.print(R"("/>)"); 269 stream.print(
"<select>");
270 stream.print(
"<option></option>");
272 stream.print(
"<option>");
273 stream.print(option.c_str());
274 stream.print(
"</option>");
276 stream.print(
"</select>");
287 stream.print(
"<button>Lock</button><button>Unlock</button>");
289 stream.print(
"<button>Open</button>");
303 stream->print(F(
"</tbody></table><p>See <a href=\"https://esphome.io/web-api/index.html\">ESPHome Web API</a> for " 304 "REST API documentation.</p>"));
307 F(
"<h2>OTA Update</h2><form method=\"POST\" action=\"/update\" enctype=\"multipart/form-data\"><input " 308 "type=\"file\" name=\"update\"><input type=\"submit\" value=\"Update\"></form>"));
310 stream->print(F(
"<h2>Debug Log</h2><pre id=\"log\"></pre>"));
312 #ifdef USE_WEBSERVER_JS_INCLUDE 314 stream->print(F(
"<script type=\"module\" src=\"/0.js\"></script>"));
317 #if USE_WEBSERVER_VERSION == 2 318 stream->print(F(
"<esp-app></esp-app>"));
320 if (strlen(this->
js_url_) > 0) {
321 stream->print(F(
"<script src=\""));
323 stream->print(F(
"\"></script>"));
325 #if USE_WEBSERVER_VERSION == 1 326 stream->print(F(
"</article></body></html>"));
328 stream->print(F(
"</body></html>"));
331 request->send(stream);
334 #ifdef USE_WEBSERVER_CSS_INCLUDE 336 AsyncResponseStream *stream = request->beginResponseStream(
"text/css");
341 request->send(stream);
345 #ifdef USE_WEBSERVER_JS_INCLUDE 347 AsyncResponseStream *stream = request->beginResponseStream(
"text/javascript");
349 stream->addHeader(
"Access-Control-Allow-Origin",
"*");
353 request->send(stream);
357 #define set_json_id(root, obj, sensor, start_config) \ 358 (root)["id"] = sensor; \ 359 if (((start_config) == DETAIL_ALL)) \ 360 (root)["name"] = (obj)->get_name(); 362 #define set_json_value(root, obj, sensor, value, start_config) \ 363 set_json_id((root), (obj), sensor, start_config)(root)["value"] = value; 365 #define set_json_state_value(root, obj, sensor, state, value, start_config) \ 366 set_json_value(root, obj, sensor, value, start_config)(root)["state"] = state; 368 #define set_json_icon_state_value(root, obj, sensor, state, value, start_config) \ 369 set_json_value(root, obj, sensor, value, start_config)(root)["state"] = state; \ 370 if (((start_config) == DETAIL_ALL)) \ 371 (root)["icon"] = (obj)->get_icon(); 382 request->send(200,
"application/json", data.c_str());
397 set_json_icon_state_value(root, obj,
"sensor-" + obj->
get_object_id(),
state, value, start_config);
402 #ifdef USE_TEXT_SENSOR 411 request->send(200,
"application/json", data.c_str());
419 set_json_icon_state_value(root, obj,
"text_sensor-" + obj->
get_object_id(), value, value, start_config);
430 set_json_icon_state_value(root, obj,
"switch-" + obj->
get_object_id(), value ?
"ON" :
"OFF", value, start_config);
441 if (request->method() == HTTP_GET) {
443 request->send(200,
"application/json", data.c_str());
444 }
else if (match.
method ==
"toggle") {
445 this->
schedule_([obj]() { obj->toggle(); });
447 }
else if (match.
method ==
"turn_on") {
448 this->
schedule_([obj]() { obj->turn_on(); });
450 }
else if (match.
method ==
"turn_off") {
451 this->
schedule_([obj]() { obj->turn_off(); });
465 [obj, start_config](JsonObject root) { set_json_id(root, obj,
"button-" + obj->
get_object_id(), start_config); });
472 if (request->method() == HTTP_POST && match.
method ==
"press") {
473 this->
schedule_([obj]() { obj->press(); });
485 #ifdef USE_BINARY_SENSOR 491 set_json_state_value(root, obj,
"binary_sensor-" + obj->
get_object_id(), value ?
"ON" :
"OFF", value, start_config);
499 request->send(200,
"application/json", data.c_str());
510 set_json_state_value(root, obj,
"fan-" + obj->
get_object_id(), obj->
state ?
"ON" :
"OFF", obj->
state, start_config);
512 if (traits.supports_speed()) {
513 root[
"speed_level"] = obj->
speed;
514 root[
"speed_count"] = traits.supported_speed_count();
525 if (request->method() == HTTP_GET) {
527 request->send(200,
"application/json", data.c_str());
528 }
else if (match.
method ==
"toggle") {
529 this->
schedule_([obj]() { obj->toggle().perform(); });
531 }
else if (match.
method ==
"turn_on") {
532 auto call = obj->turn_on();
533 if (request->hasParam(
"speed")) {
534 String
speed = request->getParam(
"speed")->value();
536 if (request->hasParam(
"speed_level")) {
537 String speed_level = request->getParam(
"speed_level")->value();
538 auto val = parse_number<int>(speed_level.c_str());
539 if (!
val.has_value()) {
540 ESP_LOGW(TAG,
"Can't convert '%s' to number!", speed_level.c_str());
545 if (request->hasParam(
"oscillation")) {
546 String
speed = request->getParam(
"oscillation")->value();
550 call.set_oscillating(
true);
553 call.set_oscillating(
false);
556 call.set_oscillating(!obj->oscillating);
565 }
else if (match.
method ==
"turn_off") {
566 this->
schedule_([obj]() { obj->turn_off().perform(); });
586 if (request->method() == HTTP_GET) {
588 request->send(200,
"application/json", data.c_str());
589 }
else if (match.
method ==
"toggle") {
590 this->
schedule_([obj]() { obj->toggle().perform(); });
592 }
else if (match.
method ==
"turn_on") {
593 auto call = obj->turn_on();
594 if (request->hasParam(
"brightness"))
595 call.set_brightness(request->getParam(
"brightness")->value().toFloat() / 255.0f);
596 if (request->hasParam(
"r"))
597 call.set_red(request->getParam(
"r")->value().toFloat() / 255.0f);
598 if (request->hasParam(
"g"))
599 call.set_green(request->getParam(
"g")->value().toFloat() / 255.0f);
600 if (request->hasParam(
"b"))
601 call.set_blue(request->getParam(
"b")->value().toFloat() / 255.0f);
602 if (request->hasParam(
"white_value"))
603 call.set_white(request->getParam(
"white_value")->value().toFloat() / 255.0f);
604 if (request->hasParam(
"color_temp"))
605 call.set_color_temperature(request->getParam(
"color_temp")->value().toFloat());
607 if (request->hasParam(
"flash")) {
608 float length_s = request->getParam(
"flash")->value().toFloat();
609 call.set_flash_length(static_cast<uint32_t>(length_s * 1000));
612 if (request->hasParam(
"transition")) {
613 float length_s = request->getParam(
"transition")->value().toFloat();
614 call.set_transition_length(static_cast<uint32_t>(length_s * 1000));
617 if (request->hasParam(
"effect")) {
618 const char *effect = request->getParam(
"effect")->value().c_str();
619 call.set_effect(effect);
624 }
else if (match.
method ==
"turn_off") {
625 auto call = obj->turn_off();
626 if (request->hasParam(
"transition")) {
627 auto length = (uint32_t) request->getParam(
"transition")->value().toFloat() * 1000;
628 call.set_transition_length(length);
641 set_json_id(root, obj,
"light-" + obj->
get_object_id(), start_config);
646 JsonArray opt = root.createNestedArray(
"effects");
649 opt.add(option->get_name());
665 if (request->method() == HTTP_GET) {
667 request->send(200,
"application/json", data.c_str());
671 auto call = obj->make_call();
672 if (match.
method ==
"open") {
673 call.set_command_open();
674 }
else if (match.
method ==
"close") {
675 call.set_command_close();
676 }
else if (match.
method ==
"stop") {
677 call.set_command_stop();
678 }
else if (match.
method !=
"set") {
683 auto traits = obj->get_traits();
684 if ((request->hasParam(
"position") && !traits.get_supports_position()) ||
685 (request->hasParam(
"tilt") && !traits.get_supports_tilt())) {
690 if (request->hasParam(
"position"))
691 call.set_position(request->getParam(
"position")->value().toFloat());
692 if (request->hasParam(
"tilt"))
693 call.set_tilt(request->getParam(
"tilt")->value().toFloat());
708 root[
"tilt"] = obj->
tilt;
722 if (request->method() == HTTP_GET) {
724 request->send(200,
"application/json", data.c_str());
727 if (match.
method !=
"set") {
732 auto call = obj->make_call();
733 if (request->hasParam(
"value")) {
734 String value = request->getParam(
"value")->value();
737 call.set_value(*value_f);
749 set_json_id(root, obj,
"number-" + obj->
get_object_id(), start_config);
757 root[
"value"] =
"\"NaN\"";
758 root[
"state"] =
"NA";
760 root[
"value"] = value;
764 root[
"state"] =
state;
779 if (request->method() == HTTP_GET) {
781 request->send(200,
"application/json", data.c_str());
785 if (match.
method !=
"set") {
790 auto call = obj->make_call();
792 if (request->hasParam(
"option")) {
793 String option = request->getParam(
"option")->value();
794 call.set_option(option.c_str());
805 set_json_state_value(root, obj,
"select-" + obj->
get_object_id(), value, value, start_config);
807 JsonArray opt = root.createNestedArray(
"option");
826 if (request->method() == HTTP_GET) {
828 request->send(200,
"application/json", data.c_str());
832 if (match.
method !=
"set") {
837 auto call = obj->make_call();
839 if (request->hasParam(
"mode")) {
840 String
mode = request->getParam(
"mode")->value();
841 call.set_mode(mode.c_str());
844 if (request->hasParam(
"target_temperature_high")) {
845 String value = request->getParam(
"target_temperature_high")->value();
848 call.set_target_temperature_high(*value_f);
851 if (request->hasParam(
"target_temperature_low")) {
852 String value = request->getParam(
"target_temperature_low")->value();
855 call.set_target_temperature_low(*value_f);
858 if (request->hasParam(
"target_temperature")) {
859 String value = request->getParam(
"target_temperature")->value();
862 call.set_target_temperature(*value_f);
873 #define PSTR_LOCAL(mode_s) strncpy_P(__buf, (PGM_P) ((mode_s)), 15) 877 set_json_id(root, obj,
"climate-" + obj->
get_object_id(), start_config);
880 int8_t current_accuracy = traits.get_current_temperature_accuracy_decimals();
884 JsonArray opt = root.createNestedArray(
"modes");
887 if (!traits.get_supported_custom_fan_modes().empty()) {
888 JsonArray opt = root.createNestedArray(
"fan_modes");
893 if (!traits.get_supported_custom_fan_modes().empty()) {
894 JsonArray opt = root.createNestedArray(
"custom_fan_modes");
895 for (
auto const &
custom_fan_mode : traits.get_supported_custom_fan_modes())
898 if (traits.get_supports_swing_modes()) {
899 JsonArray opt = root.createNestedArray(
"swing_modes");
900 for (
auto swing_mode : traits.get_supported_swing_modes())
904 JsonArray opt = root.createNestedArray(
"presets");
909 JsonArray opt = root.createNestedArray(
"custom_presets");
910 for (
auto const &
custom_preset : traits.get_supported_custom_presets())
915 bool has_state =
false;
919 root[
"step"] = traits.get_visual_target_temperature_step();
920 if (traits.get_supports_action()) {
922 root[
"state"] = root[
"action"];
937 if (traits.get_supports_swing_modes()) {
940 if (traits.get_supports_current_temperature()) {
944 root[
"current_temperature"] =
"NA";
947 if (traits.get_supports_two_point_target_temperature()) {
957 root[
"state"] = root[
"target_temperature"];
978 if (request->method() == HTTP_GET) {
980 request->send(200,
"application/json", data.c_str());
981 }
else if (match.
method ==
"lock") {
982 this->
schedule_([obj]() { obj->lock(); });
984 }
else if (match.
method ==
"unlock") {
985 this->
schedule_([obj]() { obj->unlock(); });
987 }
else if (match.
method ==
"open") {
988 this->
schedule_([obj]() { obj->open(); });
1000 if (request->url() ==
"/")
1003 #ifdef USE_WEBSERVER_CSS_INCLUDE 1004 if (request->url() ==
"/0.css")
1008 #ifdef USE_WEBSERVER_JS_INCLUDE 1009 if (request->url() ==
"/0.js")
1017 if (request->method() == HTTP_GET && match.
domain ==
"sensor")
1022 if ((request->method() == HTTP_POST || request->method() == HTTP_GET) && match.
domain ==
"switch")
1027 if (request->method() == HTTP_POST && match.
domain ==
"button")
1031 #ifdef USE_BINARY_SENSOR 1032 if (request->method() == HTTP_GET && match.
domain ==
"binary_sensor")
1037 if ((request->method() == HTTP_POST || request->method() == HTTP_GET) && match.
domain ==
"fan")
1042 if ((request->method() == HTTP_POST || request->method() == HTTP_GET) && match.
domain ==
"light")
1046 #ifdef USE_TEXT_SENSOR 1047 if (request->method() == HTTP_GET && match.
domain ==
"text_sensor")
1052 if ((request->method() == HTTP_POST || request->method() == HTTP_GET) && match.
domain ==
"cover")
1057 if ((request->method() == HTTP_POST || request->method() == HTTP_GET) && match.
domain ==
"number")
1062 if ((request->method() == HTTP_POST || request->method() == HTTP_GET) && match.
domain ==
"select")
1067 if ((request->method() == HTTP_POST || request->method() == HTTP_GET) && match.
domain ==
"climate")
1072 if ((request->method() == HTTP_POST || request->method() == HTTP_GET) && match.
domain ==
"lock")
1079 if (request->url() ==
"/") {
1084 #ifdef USE_WEBSERVER_CSS_INCLUDE 1085 if (request->url() ==
"/0.css") {
1091 #ifdef USE_WEBSERVER_JS_INCLUDE 1092 if (request->url() ==
"/0.js") {
1100 if (match.
domain ==
"sensor") {
1107 if (match.
domain ==
"switch") {
1114 if (match.
domain ==
"button") {
1120 #ifdef USE_BINARY_SENSOR 1121 if (match.
domain ==
"binary_sensor") {
1128 if (match.
domain ==
"fan") {
1135 if (match.
domain ==
"light") {
1141 #ifdef USE_TEXT_SENSOR 1142 if (match.
domain ==
"text_sensor") {
1149 if (match.
domain ==
"cover") {
1156 if (match.
domain ==
"number") {
1163 if (match.
domain ==
"select") {
1170 if (match.
domain ==
"climate") {
1177 if (match.
domain ==
"lock") {
1193 this->
defer(std::move(f));
1200 #endif // USE_ARDUINO Base class for all switches.
value_type const & value() const
bool state
The current on/off state of the fan.
ClimateSwingMode swing_mode
The active swing mode of the climate device.
void handle_number_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a number request under '/number/<id>'.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
bool oscillating
The current oscillation state of the fan.
void set_interval(const std::string &name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a unique name.
std::string number_json(number::Number *obj, float value, JsonDetail start_config)
Dump the number state with its value as a JSON string.
std::string sensor_json(sensor::Sensor *obj, float value, JsonDetail start_config)
Dump the sensor state with its value as a JSON string.
void add_on_log_callback(std::function< void(int, const char *, const char *)> &&callback)
Register a callback that will be called for every log message sent.
void on_sensor_update(sensor::Sensor *obj, float state) override
bool is_on() const
Get the binary true/false state of these light color values.
Base class for all cover devices.
std::string value_accuracy_to_string(float value, int8_t accuracy_decimals)
Create a string from a value and an accuracy in decimals.
WebServer(web_server_base::WebServerBase *base)
void handleRequest(AsyncWebServerRequest *request) override
Override the web handler's handleRequest method.
ClimatePreset
Enum for all preset modes.
const std::vector< climate::Climate * > & get_climates()
float target_temperature
The target temperature of the climate device.
SemaphoreHandle_t to_schedule_lock_
std::string get_use_address()
Get the active network hostname.
void handle_binary_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a binary sensor request under '/binary_sensor/<id>'.
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.
LockState state
The current reported state of the lock.
const char * lock_state_to_string(LockState state)
void handle_select_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a select request under '/select/<id>'.
CoverOperation current_operation
The current operation of the cover (idle, opening, closing).
const LogString * climate_mode_to_string(ClimateMode mode)
Convert the given ClimateMode to a human-readable string.
virtual FanTraits get_traits()=0
void defer(const std::string &name, std::function< void()> &&f)
Defer a callback to the next loop() call.
ClimateMode mode
The active mode of the climate device.
void on_lock_update(lock::Lock *obj) override
virtual bool assumed_state()
Return whether this switch uses an assumed state - i.e.
void write_row(AsyncResponseStream *stream, EntityBase *obj, const std::string &klass, const std::string &action, const std::function< void(AsyncResponseStream &stream, EntityBase *obj)> &action_func=nullptr)
const std::string & get_friendly_name() const
Get the friendly name of this Application set by pre_setup().
void setup() override
Setup the internal web server and register handlers.
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
float current_temperature
The current temperature of the climate device, as reported from the integration.
const std::vector< fan::Fan * > & get_fans()
void on_binary_sensor_update(binary_sensor::BinarySensor *obj, bool state) override
void handle_light_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a light request under '/light/<id>/</turn_on/turn_off/toggle>'.
bool isRequestHandlerTrivial() override
This web handle is not trivial.
void handle_lock_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a lock request under '/lock/<id>/</lock/unlock/open>'.
void handle_button_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a button request under '/button/<id>/press'.
bool supports_oscillation() const
Return if this fan supports oscillation.
void on_light_update(light::LightState *obj) override
const std::string & get_comment() const
Get the comment of this Application set by pre_setup().
float tilt
The current tilt value of the cover from 0.0 to 1.0.
std::string get_object_id() const
uint32_t IRAM_ATTR HOT millis()
ParseOnOffState parse_on_off(const char *str, const char *on, const char *off)
Parse a string that contains either on, off or toggle.
ClimateSwingMode swing_mode
Internal helper struct that is used to parse incoming URLs.
optional< std::string > custom_fan_mode
The active custom fan mode of the climate device.
virtual CoverTraits get_traits()=0
void handle_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a sensor request under '/sensor/<id>'.
const std::vector< lock::Lock * > & get_locks()
uint16_t get_port() const
void dump_config() 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.
std::string domain
The domain of the component, for example "sensor".
void on_text_sensor_update(text_sensor::TextSensor *obj, const std::string &state) override
void add_handler(AsyncWebHandler *handler)
void set_css_include(const char *css_include)
Set local path to the script that's embedded in the index page.
const std::vector< button::Button * > & get_buttons()
void handle_switch_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a switch request under '/switch/<id>/</turn_on/turn_off/toggle>'.
std::vector< std::string > get_options() const
optional< ClimatePreset > preset
The active preset of the climate device.
UrlMatch match_url(const std::string &url, bool only_domain=false)
const std::vector< switch_::Switch * > & get_switches()
Base-class for all numbers.
const char * cover_operation_to_str(CoverOperation op)
int speed
The current fan speed level.
void handle_css_request(AsyncWebServerRequest *request)
Handle included css request under '/0.css'.
bool valid
Whether this match is valid.
BedjetMode mode
BedJet operating mode.
bool is_fully_closed() const
Helper method to check if the cover is fully closed. Equivalent to comparing .position against 0...
void on_select_update(select::Select *obj, const std::string &state, size_t index) override
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
std::string get_unit_of_measurement()
Get the unit of measurement, using the manual override if set.
const std::vector< text_sensor::TextSensor * > & get_text_sensors()
const LogString * climate_preset_to_string(ClimatePreset preset)
Convert the given PresetMode to a human-readable string.
int8_t get_target_temperature_accuracy_decimals() const
const std::vector< sensor::Sensor * > & get_sensors()
Application App
Global storage of Application pointer - only one Application can exist.
const std::vector< binary_sensor::BinarySensor * > & get_binary_sensors()
const std::vector< LightEffect * > & get_effects() const
Get all effects for this light state.
int8_t step_to_accuracy_decimals(float step)
Derive accuracy in decimals from an increment step.
std::string switch_json(switch_::Switch *obj, bool value, JsonDetail start_config)
Dump the switch state with its value as a JSON string.
std::string build_json(const json_build_t &f)
Build a JSON string with the provided json build function.
void begin(bool include_internal=false)
const std::string & get_name() const
Get the name of this Application set by pre_setup().
std::string light_json(light::LightState *obj, JsonDetail start_config)
Dump the light state as a JSON string.
static void dump_json(LightState &state, JsonObject root)
Dump the state of a light as JSON.
ClimateMode
Enum for all modes a climate device can be in.
void handle_index_request(AsyncWebServerRequest *request)
Handle an index request under '/'.
void on_climate_update(climate::Climate *obj) override
const std::vector< cover::Cover * > & get_covers()
constexpr const char * c_str() const
void set_js_url(const char *js_url)
Set the URL to the script that's embedded in the index page.
float get_setup_priority() const override
MQTT setup priority.
optional< std::string > custom_preset
The active custom preset mode of the climate device.
const LogString * climate_fan_mode_to_string(ClimateFanMode fan_mode)
Convert the given ClimateFanMode to a human-readable string.
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
float position
The position of the cover from 0.0 (fully closed) to 1.0 (fully open).
void handle_fan_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a fan request under '/fan/<id>/</turn_on/turn_off/toggle>'.
void set_css_url(const char *css_url)
Set the URL to the CSS <link> that's sent to each client.
std::string id
The id of the device that's being accessed, for example "living_room_fan".
const std::vector< light::LightState * > & get_lights()
std::string button_json(button::Button *obj, JsonDetail start_config)
Dump the button details with its value as a JSON string.
void on_cover_update(cover::Cover *obj) override
void handle_cover_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a cover request under '/cover/<id>/<open/close/stop/set>'.
void on_switch_update(switch_::Switch *obj, bool state) override
const char * css_include_
bool get_supports_tilt() const
void setup_controller(bool include_internal=false)
Base-class for all selects.
void on_fan_update(fan::Fan *obj) override
web_server_base::WebServerBase * base_
float get_min_value() const
void on_number_update(number::Number *obj, float state) override
std::string fan_json(fan::Fan *obj, JsonDetail start_config)
Dump the fan state as a JSON string.
Base class for all binary_sensor-type classes.
LightColorValues remote_values
The remote color values reported to the frontend.
LockState
Enum for all states a lock can be in.
NumberMode get_mode() const
void handle_climate_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a climate request under '/climate/<id>'.
int8_t get_accuracy_decimals()
Get the accuracy in decimals, using the manual override if set.
const std::vector< select::Select * > & get_selects()
Base-class for all sensors.
bool canHandle(AsyncWebServerRequest *request) override
Override the web handler's canHandle method.
ListEntitiesIterator entities_iterator_
std::deque< std::function< void()> > to_schedule_
const std::vector< number::Number * > & get_numbers()
float get_max_value() const
const LogString * climate_action_to_string(ClimateAction action)
Convert the given ClimateAction to a human-readable string.
void handle_text_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match)
Handle a text sensor request under '/text_sensor/<id>'.
bool get_supports_open() const
void schedule_(std::function< void()> &&f)
std::string lock_json(lock::Lock *obj, lock::LockState value, JsonDetail start_config)
Dump the lock state with its value as a JSON string.
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
const StringRef & get_name() const
std::string climate_json(climate::Climate *obj, JsonDetail start_config)
Dump the climate details.
std::string method
The method that's being called, for example "turn_on".
Base class for all locks.
ClimateAction action
The active state of the climate device.
ClimateDevice - This is the base class for all climate integrations.
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.
std::string cover_json(cover::Cover *obj, JsonDetail start_config)
Dump the cover state as a JSON string.
void handle_js_request(AsyncWebServerRequest *request)
Handle included js request under '/0.js'.
void set_js_include(const char *js_include)
Set local path to the script that's embedded in the index page.
const LogString * climate_swing_mode_to_string(ClimateSwingMode swing_mode)
Convert the given ClimateSwingMode to a human-readable string.