feature/capabilities #1
@@ -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() {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user