mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
[web_server] Expose detail=all on all components (#7531)
Some checks failed
CI / Create common environment (push) Has been cancelled
CI / Check black (push) Has been cancelled
CI / Check flake8 (push) Has been cancelled
CI / Check pylint (push) Has been cancelled
CI / Check pyupgrade (push) Has been cancelled
CI / Run script/ci-custom (push) Has been cancelled
CI / Run pytest (push) Has been cancelled
CI / Check clang-format (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 1/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 2/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 3/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 4/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF (push) Has been cancelled
CI / Run script/clang-tidy for ESP8266 (push) Has been cancelled
CI / list-components (push) Has been cancelled
CI / Component test (push) Has been cancelled
CI / Split components for testing into 20 groups maximum (push) Has been cancelled
CI / Test split components (push) Has been cancelled
CI / CI Status (push) Has been cancelled
Some checks failed
CI / Create common environment (push) Has been cancelled
CI / Check black (push) Has been cancelled
CI / Check flake8 (push) Has been cancelled
CI / Check pylint (push) Has been cancelled
CI / Check pyupgrade (push) Has been cancelled
CI / Run script/ci-custom (push) Has been cancelled
CI / Run pytest (push) Has been cancelled
CI / Check clang-format (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 1/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 2/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 3/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 4/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF (push) Has been cancelled
CI / Run script/clang-tidy for ESP8266 (push) Has been cancelled
CI / list-components (push) Has been cancelled
CI / Component test (push) Has been cancelled
CI / Split components for testing into 20 groups maximum (push) Has been cancelled
CI / Test split components (push) Has been cancelled
CI / CI Status (push) Has been cancelled
This commit is contained in:
parent
e57a1ff42d
commit
523eedbc51
1 changed files with 127 additions and 29 deletions
|
@ -219,10 +219,17 @@ void WebServer::handle_sensor_request(AsyncWebServerRequest *request, const UrlM
|
||||||
for (sensor::Sensor *obj : App.get_sensors()) {
|
for (sensor::Sensor *obj : App.get_sensors()) {
|
||||||
if (obj->get_object_id() != match.id)
|
if (obj->get_object_id() != match.id)
|
||||||
continue;
|
continue;
|
||||||
std::string data = this->sensor_json(obj, obj->state, DETAIL_STATE);
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->sensor_json(obj, obj->state, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
request->send(404);
|
request->send(404);
|
||||||
}
|
}
|
||||||
std::string WebServer::sensor_json(sensor::Sensor *obj, float value, JsonDetail start_config) {
|
std::string WebServer::sensor_json(sensor::Sensor *obj, float value, JsonDetail start_config) {
|
||||||
|
@ -257,10 +264,17 @@ void WebServer::handle_text_sensor_request(AsyncWebServerRequest *request, const
|
||||||
for (text_sensor::TextSensor *obj : App.get_text_sensors()) {
|
for (text_sensor::TextSensor *obj : App.get_text_sensors()) {
|
||||||
if (obj->get_object_id() != match.id)
|
if (obj->get_object_id() != match.id)
|
||||||
continue;
|
continue;
|
||||||
std::string data = this->text_sensor_json(obj, obj->state, DETAIL_STATE);
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->text_sensor_json(obj, obj->state, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
request->send(404);
|
request->send(404);
|
||||||
}
|
}
|
||||||
std::string WebServer::text_sensor_json(text_sensor::TextSensor *obj, const std::string &value,
|
std::string WebServer::text_sensor_json(text_sensor::TextSensor *obj, const std::string &value,
|
||||||
|
@ -288,7 +302,12 @@ void WebServer::handle_switch_request(AsyncWebServerRequest *request, const UrlM
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
std::string data = this->switch_json(obj, obj->state, DETAIL_STATE);
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->switch_json(obj, obj->state, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
} else if (match.method == "toggle") {
|
} else if (match.method == "toggle") {
|
||||||
this->schedule_([obj]() { obj->toggle(); });
|
this->schedule_([obj]() { obj->toggle(); });
|
||||||
|
@ -324,7 +343,15 @@ void WebServer::handle_button_request(AsyncWebServerRequest *request, const UrlM
|
||||||
for (button::Button *obj : App.get_buttons()) {
|
for (button::Button *obj : App.get_buttons()) {
|
||||||
if (obj->get_object_id() != match.id)
|
if (obj->get_object_id() != match.id)
|
||||||
continue;
|
continue;
|
||||||
if (match.method == "press") {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->button_json(obj, detail);
|
||||||
|
request->send(200, "application/json", data.c_str());
|
||||||
|
} else if (match.method == "press") {
|
||||||
this->schedule_([obj]() { obj->press(); });
|
this->schedule_([obj]() { obj->press(); });
|
||||||
request->send(200);
|
request->send(200);
|
||||||
return;
|
return;
|
||||||
|
@ -357,10 +384,17 @@ void WebServer::handle_binary_sensor_request(AsyncWebServerRequest *request, con
|
||||||
for (binary_sensor::BinarySensor *obj : App.get_binary_sensors()) {
|
for (binary_sensor::BinarySensor *obj : App.get_binary_sensors()) {
|
||||||
if (obj->get_object_id() != match.id)
|
if (obj->get_object_id() != match.id)
|
||||||
continue;
|
continue;
|
||||||
std::string data = this->binary_sensor_json(obj, obj->state, DETAIL_STATE);
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->binary_sensor_json(obj, obj->state, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
request->send(404);
|
request->send(404);
|
||||||
}
|
}
|
||||||
std::string WebServer::binary_sensor_json(binary_sensor::BinarySensor *obj, bool value, JsonDetail start_config) {
|
std::string WebServer::binary_sensor_json(binary_sensor::BinarySensor *obj, bool value, JsonDetail start_config) {
|
||||||
|
@ -388,7 +422,12 @@ void WebServer::handle_fan_request(AsyncWebServerRequest *request, const UrlMatc
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
std::string data = this->fan_json(obj, DETAIL_STATE);
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->fan_json(obj, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
} else if (match.method == "toggle") {
|
} else if (match.method == "toggle") {
|
||||||
this->schedule_([obj]() { obj->toggle().perform(); });
|
this->schedule_([obj]() { obj->toggle().perform(); });
|
||||||
|
@ -466,7 +505,12 @@ void WebServer::handle_light_request(AsyncWebServerRequest *request, const UrlMa
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
std::string data = this->light_json(obj, DETAIL_STATE);
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->light_json(obj, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
} else if (match.method == "toggle") {
|
} else if (match.method == "toggle") {
|
||||||
this->schedule_([obj]() { obj->toggle().perform(); });
|
this->schedule_([obj]() { obj->toggle().perform(); });
|
||||||
|
@ -577,9 +621,14 @@ void WebServer::handle_cover_request(AsyncWebServerRequest *request, const UrlMa
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
std::string data = this->cover_json(obj, DETAIL_STATE);
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->cover_json(obj, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto call = obj->make_call();
|
auto call = obj->make_call();
|
||||||
|
@ -653,7 +702,12 @@ void WebServer::handle_number_request(AsyncWebServerRequest *request, const UrlM
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
std::string data = this->number_json(obj, obj->state, DETAIL_STATE);
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->number_json(obj, obj->state, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -717,8 +771,13 @@ void WebServer::handle_date_request(AsyncWebServerRequest *request, const UrlMat
|
||||||
for (auto *obj : App.get_dates()) {
|
for (auto *obj : App.get_dates()) {
|
||||||
if (obj->get_object_id() != match.id)
|
if (obj->get_object_id() != match.id)
|
||||||
continue;
|
continue;
|
||||||
if (request->method() == HTTP_GET) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
std::string data = this->date_json(obj, DETAIL_STATE);
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->date_json(obj, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -772,7 +831,12 @@ void WebServer::handle_time_request(AsyncWebServerRequest *request, const UrlMat
|
||||||
if (obj->get_object_id() != match.id)
|
if (obj->get_object_id() != match.id)
|
||||||
continue;
|
continue;
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
std::string data = this->time_json(obj, DETAIL_STATE);
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->time_json(obj, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -825,7 +889,12 @@ void WebServer::handle_datetime_request(AsyncWebServerRequest *request, const Ur
|
||||||
if (obj->get_object_id() != match.id)
|
if (obj->get_object_id() != match.id)
|
||||||
continue;
|
continue;
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
std::string data = this->datetime_json(obj, DETAIL_STATE);
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->datetime_json(obj, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -880,8 +949,13 @@ void WebServer::handle_text_request(AsyncWebServerRequest *request, const UrlMat
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
std::string data = this->text_json(obj, obj->state, DETAIL_STATE);
|
auto detail = DETAIL_STATE;
|
||||||
request->send(200, "text/json", data.c_str());
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->text_json(obj, obj->state, detail);
|
||||||
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (match.method != "set") {
|
if (match.method != "set") {
|
||||||
|
@ -995,11 +1069,15 @@ void WebServer::handle_climate_request(AsyncWebServerRequest *request, const Url
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
std::string data = this->climate_json(obj, DETAIL_STATE);
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->climate_json(obj, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match.method != "set") {
|
if (match.method != "set") {
|
||||||
request->send(404);
|
request->send(404);
|
||||||
return;
|
return;
|
||||||
|
@ -1149,7 +1227,12 @@ void WebServer::handle_lock_request(AsyncWebServerRequest *request, const UrlMat
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
std::string data = this->lock_json(obj, obj->state, DETAIL_STATE);
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->lock_json(obj, obj->state, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
} else if (match.method == "lock") {
|
} else if (match.method == "lock") {
|
||||||
this->schedule_([obj]() { obj->lock(); });
|
this->schedule_([obj]() { obj->lock(); });
|
||||||
|
@ -1192,9 +1275,14 @@ void WebServer::handle_valve_request(AsyncWebServerRequest *request, const UrlMa
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
std::string data = this->valve_json(obj, DETAIL_STATE);
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->valve_json(obj, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto call = obj->make_call();
|
auto call = obj->make_call();
|
||||||
|
@ -1257,7 +1345,12 @@ void WebServer::handle_alarm_control_panel_request(AsyncWebServerRequest *reques
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
std::string data = this->alarm_control_panel_json(obj, obj->get_state(), DETAIL_STATE);
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->alarm_control_panel_json(obj, obj->get_state(), detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1314,7 +1407,12 @@ void WebServer::handle_update_request(AsyncWebServerRequest *request, const UrlM
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
std::string data = this->update_json(obj, DETAIL_STATE);
|
auto detail = DETAIL_STATE;
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
if (param && param->value() == "all") {
|
||||||
|
detail = DETAIL_ALL;
|
||||||
|
}
|
||||||
|
std::string data = this->update_json(obj, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue