feature/capabilities #1

Merged
master merged 2 commits from feature/capabilities into main 2025-08-28 11:17:24 +02:00
3 changed files with 10 additions and 3 deletions
Showing only changes of commit a4c356df93 - Show all commits

View File

@@ -59,7 +59,7 @@ public:
String json; String json;
serializeJson(resp, json); serializeJson(resp, json);
request->send(ok ? 200 : 400, "application/json", json); request->send(ok ? 200 : 400, "application/json", json);
}, std::vector<ApiServer::ParamSpec>{ ApiServer::ParamSpec{ String("state"), true, String("body"), String("string") } }); }, std::vector<ApiServer::ParamSpec>{ ApiServer::ParamSpec{ String("state"), true, String("body"), String("string"), { String("on"), String("off"), String("toggle") } } });
} }
void turnOn() { void turnOn() {

View File

@@ -28,6 +28,7 @@ public:
bool required; bool required;
String location; // "query" | "body" | "path" | "header" String location; // "query" | "body" | "path" | "header"
String type; // e.g. "string", "number", "boolean" String type; // e.g. "string", "number", "boolean"
std::vector<String> values; // optional allowed values
}; };
struct EndpointCapability { struct EndpointCapability {
String uri; String uri;

View File

@@ -77,8 +77,8 @@ void ApiServer::begin() {
addEndpoint("/api/tasks/control", HTTP_POST, addEndpoint("/api/tasks/control", HTTP_POST,
std::bind(&ApiServer::onTaskControlRequest, this, std::placeholders::_1), std::bind(&ApiServer::onTaskControlRequest, this, std::placeholders::_1),
std::vector<ParamSpec>{ std::vector<ParamSpec>{
ParamSpec{String("task"), true, String("body"), String("string")}, ParamSpec{String("task"), true, String("body"), String("string"), {}},
ParamSpec{String("action"), true, String("body"), String("string")} ParamSpec{String("action"), true, String("body"), String("string"), {String("enable"), String("disable"), String("start"), String("stop"), String("status")}}
} }
); );
@@ -370,6 +370,12 @@ void ApiServer::onCapabilitiesRequest(AsyncWebServerRequest *request) {
p["location"] = ps.location; p["location"] = ps.location;
p["required"] = ps.required; p["required"] = ps.required;
p["type"] = ps.type; p["type"] = ps.type;
if (!ps.values.empty()) {
JsonArray allowed = p["values"].to<JsonArray>();
for (const auto& v : ps.values) {
allowed.add(v);
}
}
} }
} }
} }