mirror of
https://github.com/esphome/esphome.git
synced 2025-08-10 12:27:46 +00:00
Merge remote-tracking branch 'origin/integration' into integration
This commit is contained in:
@@ -372,6 +372,12 @@ void WebServer::handle_js_request(AsyncWebServerRequest *request) {
|
|||||||
set_json_value(root, obj, sensor, value, start_config); \
|
set_json_value(root, obj, sensor, value, start_config); \
|
||||||
(root)["state"] = state;
|
(root)["state"] = state;
|
||||||
|
|
||||||
|
// Helper to get request detail parameter
|
||||||
|
static JsonDetail get_request_detail_(AsyncWebServerRequest *request) {
|
||||||
|
auto *param = request->getParam("detail");
|
||||||
|
return (param && param->value() == "all") ? DETAIL_ALL : DETAIL_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_SENSOR
|
#ifdef USE_SENSOR
|
||||||
void WebServer::on_sensor_update(sensor::Sensor *obj, float state) {
|
void WebServer::on_sensor_update(sensor::Sensor *obj, float state) {
|
||||||
if (this->events_.empty())
|
if (this->events_.empty())
|
||||||
@@ -383,11 +389,7 @@ void WebServer::handle_sensor_request(AsyncWebServerRequest *request, const UrlM
|
|||||||
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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->sensor_json(obj, obj->state, detail);
|
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;
|
||||||
@@ -432,11 +434,7 @@ void WebServer::handle_text_sensor_request(AsyncWebServerRequest *request, const
|
|||||||
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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->text_sensor_json(obj, obj->state, detail);
|
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;
|
||||||
@@ -475,11 +473,7 @@ 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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->switch_json(obj, obj->state, detail);
|
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") {
|
||||||
@@ -521,11 +515,7 @@ void WebServer::handle_button_request(AsyncWebServerRequest *request, const UrlM
|
|||||||
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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->button_json(obj, detail);
|
std::string data = this->button_json(obj, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
} else if (match.method == "press") {
|
} else if (match.method == "press") {
|
||||||
@@ -566,11 +556,7 @@ void WebServer::handle_binary_sensor_request(AsyncWebServerRequest *request, con
|
|||||||
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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->binary_sensor_json(obj, obj->state, detail);
|
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;
|
||||||
@@ -609,11 +595,7 @@ 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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->fan_json(obj, detail);
|
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") {
|
||||||
@@ -694,11 +676,7 @@ 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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->light_json(obj, detail);
|
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") {
|
||||||
@@ -814,11 +792,7 @@ 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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->cover_json(obj, detail);
|
std::string data = this->cover_json(obj, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
@@ -899,11 +873,7 @@ 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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->number_json(obj, obj->state, detail);
|
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;
|
||||||
@@ -973,11 +943,7 @@ void WebServer::handle_date_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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->date_json(obj, detail);
|
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;
|
||||||
@@ -1036,11 +1002,7 @@ 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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->time_json(obj, detail);
|
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;
|
||||||
@@ -1098,11 +1060,7 @@ 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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->datetime_json(obj, detail);
|
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;
|
||||||
@@ -1162,11 +1120,7 @@ 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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->text_json(obj, obj->state, detail);
|
std::string data = this->text_json(obj, obj->state, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
@@ -1227,11 +1181,7 @@ void WebServer::handle_select_request(AsyncWebServerRequest *request, const UrlM
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->select_json(obj, obj->state, detail);
|
std::string data = this->select_json(obj, obj->state, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
@@ -1290,11 +1240,7 @@ 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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->climate_json(obj, detail);
|
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;
|
||||||
@@ -1453,11 +1399,7 @@ 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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->lock_json(obj, obj->state, detail);
|
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") {
|
||||||
@@ -1505,11 +1447,7 @@ 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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->valve_json(obj, detail);
|
std::string data = this->valve_json(obj, detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
@@ -1581,11 +1519,7 @@ 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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
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);
|
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;
|
||||||
@@ -1652,11 +1586,7 @@ void WebServer::handle_event_request(AsyncWebServerRequest *request, const UrlMa
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (request->method() == HTTP_GET && match.method.empty()) {
|
if (request->method() == HTTP_GET && match.method.empty()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->event_json(obj, "", detail);
|
std::string data = this->event_json(obj, "", detail);
|
||||||
request->send(200, "application/json", data.c_str());
|
request->send(200, "application/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
@@ -1702,11 +1632,7 @@ 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()) {
|
||||||
auto detail = DETAIL_STATE;
|
auto detail = get_request_detail_(request);
|
||||||
auto *param = request->getParam("detail");
|
|
||||||
if (param && param->value() == "all") {
|
|
||||||
detail = DETAIL_ALL;
|
|
||||||
}
|
|
||||||
std::string data = this->update_json(obj, detail);
|
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;
|
||||||
|
Reference in New Issue
Block a user