[select] Refactor to index-based operations for immediate and future RAM savings (#11623)

This commit is contained in:
J. Nick Koston
2025-11-04 16:33:01 -06:00
committed by GitHub
parent c7ae424613
commit 6f7e54c3f3
44 changed files with 268 additions and 204 deletions

View File

@@ -1188,7 +1188,7 @@ void WebServer::handle_select_request(AsyncWebServerRequest *request, const UrlM
if (request->method() == HTTP_GET && match.method_empty()) {
auto detail = get_request_detail(request);
std::string data = this->select_json(obj, obj->state, detail);
std::string data = this->select_json(obj, obj->has_state() ? obj->current_option() : "", detail);
request->send(200, "application/json", data.c_str());
return;
}
@@ -1208,12 +1208,14 @@ void WebServer::handle_select_request(AsyncWebServerRequest *request, const UrlM
request->send(404);
}
std::string WebServer::select_state_json_generator(WebServer *web_server, void *source) {
return web_server->select_json((select::Select *) (source), ((select::Select *) (source))->state, DETAIL_STATE);
auto *obj = (select::Select *) (source);
return web_server->select_json(obj, obj->has_state() ? obj->current_option() : "", DETAIL_STATE);
}
std::string WebServer::select_all_json_generator(WebServer *web_server, void *source) {
return web_server->select_json((select::Select *) (source), ((select::Select *) (source))->state, DETAIL_ALL);
auto *obj = (select::Select *) (source);
return web_server->select_json(obj, obj->has_state() ? obj->current_option() : "", DETAIL_ALL);
}
std::string WebServer::select_json(select::Select *obj, const std::string &value, JsonDetail start_config) {
std::string WebServer::select_json(select::Select *obj, const char *value, JsonDetail start_config) {
json::JsonBuilder builder;
JsonObject root = builder.root();