mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
add API to test suite
This commit is contained in:
@@ -76,6 +76,7 @@ class AsyncWebServerRequest {
|
|||||||
void * _tempObject;
|
void * _tempObject;
|
||||||
|
|
||||||
AsyncWebServerRequest(AsyncWebServer *, AsyncClient *){};
|
AsyncWebServerRequest(AsyncWebServer *, AsyncClient *){};
|
||||||
|
AsyncWebServerRequest(){};
|
||||||
~AsyncWebServerRequest(){};
|
~AsyncWebServerRequest(){};
|
||||||
|
|
||||||
AsyncClient * client() {
|
AsyncClient * client() {
|
||||||
@@ -119,6 +120,10 @@ class AsyncWebServerRequest {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasParam(const char * name) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool hasParam(const __FlashStringHelper * data) const {
|
bool hasParam(const __FlashStringHelper * data) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -139,6 +144,10 @@ class AsyncWebServerRequest {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AsyncWebParameter * getParam(const char * name) const {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
AsyncWebParameter * getParam(size_t num) const {
|
AsyncWebParameter * getParam(size_t num) const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,9 +82,9 @@ void WebAPIService::webAPIService_post(AsyncWebServerRequest * request, JsonVari
|
|||||||
// parse the URL looking for query or path parameters
|
// parse the URL looking for query or path parameters
|
||||||
// reporting back any errors
|
// reporting back any errors
|
||||||
void WebAPIService::parse(AsyncWebServerRequest * request, std::string & device_s, std::string & cmd_s, int id, std::string & value_s) {
|
void WebAPIService::parse(AsyncWebServerRequest * request, std::string & device_s, std::string & cmd_s, int id, std::string & value_s) {
|
||||||
#ifndef EMSESP_STANDALONE
|
|
||||||
// parse URL for the path names
|
// parse URL for the path names
|
||||||
SUrlParser p;
|
SUrlParser p;
|
||||||
|
|
||||||
p.parse(request->url().c_str());
|
p.parse(request->url().c_str());
|
||||||
|
|
||||||
// remove the /api from the path
|
// remove the /api from the path
|
||||||
@@ -195,6 +195,14 @@ void WebAPIService::parse(AsyncWebServerRequest * request, std::string & device_
|
|||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response); // send json response
|
request->send(response); // send json response
|
||||||
|
|
||||||
|
// TODO debug
|
||||||
|
#if defined EMSESP_STANDALONE
|
||||||
|
Serial.print(COLOR_YELLOW);
|
||||||
|
if (json.size() != 0) {
|
||||||
|
serializeJsonPretty(json, Serial);
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
Serial.print(COLOR_RESET);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,13 +60,13 @@ class WebAPIService {
|
|||||||
public:
|
public:
|
||||||
WebAPIService(AsyncWebServer * server, SecurityManager * securityManager);
|
WebAPIService(AsyncWebServer * server, SecurityManager * securityManager);
|
||||||
|
|
||||||
|
void webAPIService_post(AsyncWebServerRequest * request, JsonVariant & json); // for POSTs
|
||||||
|
void webAPIService_get(AsyncWebServerRequest * request); // for GETs
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SecurityManager * _securityManager;
|
SecurityManager * _securityManager;
|
||||||
AsyncCallbackJsonWebHandler _apiHandler; // for POSTs
|
AsyncCallbackJsonWebHandler _apiHandler; // for POSTs
|
||||||
|
|
||||||
void webAPIService_post(AsyncWebServerRequest * request, JsonVariant & json); // for POSTs
|
|
||||||
void webAPIService_get(AsyncWebServerRequest * request); // for GETs
|
|
||||||
|
|
||||||
void parse(AsyncWebServerRequest * request, std::string & device, std::string & cmd, int id, std::string & value);
|
void parse(AsyncWebServerRequest * request, std::string & device, std::string & cmd, int id, std::string & value);
|
||||||
void send_message_response(AsyncWebServerRequest * request, uint16_t error_code, const char * error_message = nullptr);
|
void send_message_response(AsyncWebServerRequest * request, uint16_t error_code, const char * error_message = nullptr);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -931,8 +931,17 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
|
|||||||
|
|
||||||
if (command == "api") {
|
if (command == "api") {
|
||||||
shell.printfln(F("Testing RESTful API..."));
|
shell.printfln(F("Testing RESTful API..."));
|
||||||
// TODO add API
|
Mqtt::ha_enabled(false);
|
||||||
// AsyncWebServerRequest * request;
|
run_test("general");
|
||||||
|
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XXLARGE_DYN);
|
||||||
|
JsonObject json = doc.to<JsonObject>();
|
||||||
|
AsyncWebServerRequest request;
|
||||||
|
request.method(HTTP_GET);
|
||||||
|
request.url("/api/thermostat/seltemp");
|
||||||
|
EMSESP::webAPIService.webAPIService_get(&request);
|
||||||
|
|
||||||
|
request.url("/api/boiler/syspress");
|
||||||
|
EMSESP::webAPIService.webAPIService_get(&request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ namespace emsesp {
|
|||||||
// #define EMSESP_DEBUG_DEFAULT "ha"
|
// #define EMSESP_DEBUG_DEFAULT "ha"
|
||||||
// #define EMSESP_DEBUG_DEFAULT "board_profile"
|
// #define EMSESP_DEBUG_DEFAULT "board_profile"
|
||||||
// #define EMSESP_DEBUG_DEFAULT "shower_alert"
|
// #define EMSESP_DEBUG_DEFAULT "shower_alert"
|
||||||
#define EMSESP_DEBUG_DEFAULT "310"
|
// #define EMSESP_DEBUG_DEFAULT "310"
|
||||||
|
#define EMSESP_DEBUG_DEFAULT "api"
|
||||||
|
|
||||||
class Test {
|
class Test {
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user