diff --git a/mock-api/package.json b/mock-api/package.json index 9d7cc08ec..f5326f7b3 100644 --- a/mock-api/package.json +++ b/mock-api/package.json @@ -11,7 +11,7 @@ "dependencies": { "@msgpack/msgpack": "^3.1.1", "@trivago/prettier-plugin-sort-imports": "^5.2.2", - "formidable": "^3.5.3", + "formidable": "^3.5.4", "itty-router": "^5.0.18", "prettier": "^3.5.3" }, diff --git a/mock-api/yarn.lock b/mock-api/yarn.lock index 9a7b69dc1..a37814230 100644 --- a/mock-api/yarn.lock +++ b/mock-api/yarn.lock @@ -210,14 +210,14 @@ __metadata: languageName: node linkType: hard -"formidable@npm:^3.5.3": - version: 3.5.3 - resolution: "formidable@npm:3.5.3" +"formidable@npm:^3.5.4": + version: 3.5.4 + resolution: "formidable@npm:3.5.4" dependencies: "@paralleldrive/cuid2": "npm:^2.2.2" dezalgo: "npm:^1.0.4" once: "npm:^1.4.0" - checksum: 10c0/4e2732d3ed946dd972bc80ecba5c5a3709baa7d541583058c7e0a7344e64ced3b69f32813884a174855ad31f9ce978a6dc9fbf2578a1ed5e08691baf679266f4 + checksum: 10c0/3a311ce57617eb8f532368e91c0f2bbfb299a0f1a35090e085bd6ca772298f196fbb0b66f0d4b5549d7bf3c5e1844439338d4402b7b6d1fedbe206ad44a931f8 languageName: node linkType: hard @@ -271,7 +271,7 @@ __metadata: dependencies: "@msgpack/msgpack": "npm:^3.1.1" "@trivago/prettier-plugin-sort-imports": "npm:^5.2.2" - formidable: "npm:^3.5.3" + formidable: "npm:^3.5.4" itty-router: "npm:^5.0.18" prettier: "npm:^3.5.3" languageName: unknown diff --git a/src/test/test.cpp b/src/test/test.cpp index 22059e57c..3176f7c24 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -352,6 +352,10 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const #ifdef EMSESP_STANDALONE AsyncWebServerRequest request; + JsonDocument doc; + JsonVariant json; + + // read requests request.method(HTTP_GET); request.url("/api/custom"); EMSESP::webAPIService.webAPIService(&request); @@ -363,6 +367,20 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const EMSESP::webAPIService.webAPIService(&request); shell.invoke_command("call custom info"); + // write requests + request.method(HTTP_POST); + char data[] = "{\"value\":\"99\"}"; + deserializeJson(doc, data); + json = doc.as(); + // validate + request.url("/api/custom/test_ram"); + EMSESP::webAPIService.webAPIService(&request, json); + + request.method(HTTP_GET); + request.url("/api/custom"); + EMSESP::webAPIService.webAPIService(&request); + + #endif ok = true; } @@ -1091,6 +1109,16 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const // POST COMMANDS request.method(HTTP_POST); + char data0[] = "{\"value\":12}"; + deserializeJson(doc, data0); + request.url("/api/thermostat/seltemp"); + EMSESP::webAPIService.webAPIService(&request, doc.as()); + // request.method(HTTP_GET); + // request.url("/api/thermostat/seltemp/value"); + // EMSESP::webAPIService.webAPIService(&request); + + // request.method(HTTP_POST); + // char data1[] = "{\"device\":\"system\", \"cmd\":\"restart\",\"id\":-1}"; // deserializeJson(doc, data1); // request.url("/api"); @@ -1114,28 +1142,28 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const // test version checks // use same data as in rest_server.ts // log shows first if you can upgrade to dev, and then if you can upgrade to stable - request.url("/rest/action"); - std::string LATEST_STABLE_VERSION = "3.7.2"; - std::string LATEST_DEV_VERSION = "3.7.3-dev.3"; - std::string param = LATEST_DEV_VERSION + "," + LATEST_STABLE_VERSION; - std::string action = "{\"action\":\"checkUpgrade\", \"param\":\"" + param + "\"}"; - deserializeJson(doc, action); + // request.url("/rest/action"); + // std::string LATEST_STABLE_VERSION = "3.7.2"; + // std::string LATEST_DEV_VERSION = "3.7.3-dev.3"; + // std::string param = LATEST_DEV_VERSION + "," + LATEST_STABLE_VERSION; + // std::string action = "{\"action\":\"checkUpgrade\", \"param\":\"" + param + "\"}"; + // deserializeJson(doc, action); - // case 0: on latest stable, can upgrade to dev only. So true, false - EMSESP::webStatusService.set_current_version(LATEST_STABLE_VERSION); - EMSESP::webStatusService.action(&request, doc.as()); + // // case 0: on latest stable, can upgrade to dev only. So true, false + // EMSESP::webStatusService.set_current_version(LATEST_STABLE_VERSION); + // EMSESP::webStatusService.action(&request, doc.as()); - // case 1: on latest dev, no updates to either dev or stable. So false, false - EMSESP::webStatusService.set_current_version(LATEST_DEV_VERSION); - EMSESP::webStatusService.action(&request, doc.as()); + // // case 1: on latest dev, no updates to either dev or stable. So false, false + // EMSESP::webStatusService.set_current_version(LATEST_DEV_VERSION); + // EMSESP::webStatusService.action(&request, doc.as()); - // case 2: upgrade an older stable to latest stable or the latest dev. So true, true - EMSESP::webStatusService.set_current_version("3.6.5"); - EMSESP::webStatusService.action(&request, doc.as()); + // // case 2: upgrade an older stable to latest stable or the latest dev. So true, true + // EMSESP::webStatusService.set_current_version("3.6.5"); + // EMSESP::webStatusService.action(&request, doc.as()); - // case 3: upgrade an older dev to latest dev, no stable upgrades available. So true, false - EMSESP::webStatusService.set_current_version("3.7.3-dev.2"); - EMSESP::webStatusService.action(&request, doc.as()); + // // case 3: upgrade an older dev to latest dev, no stable upgrades available. So true, false + // EMSESP::webStatusService.set_current_version("3.7.3-dev.2"); + // EMSESP::webStatusService.action(&request, doc.as()); // char data6[] = "{\"device\":\"system\", \"cmd\":\"read\",\"value\":\"8 2 27 1\"}"; // deserializeJson(doc, data6); diff --git a/src/test/test.h b/src/test/test.h index dbed1bca7..92170f7cc 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -41,7 +41,7 @@ namespace emsesp { // #define EMSESP_DEBUG_DEFAULT "310" // #define EMSESP_DEBUG_DEFAULT "render" // #define EMSESP_DEBUG_DEFAULT "api" -#define EMSESP_DEBUG_DEFAULT "api3" +// #define EMSESP_DEBUG_DEFAULT "api3" // #define EMSESP_DEBUG_DEFAULT "api4" // #define EMSESP_DEBUG_DEFAULT "crash" // #define EMSESP_DEBUG_DEFAULT "dv" @@ -56,7 +56,7 @@ namespace emsesp { // #define EMSESP_DEBUG_DEFAULT "telegram_dump" // #define EMSESP_DEBUG_DEFAULT "memory" // #define EMSESP_DEBUG_DEFAULT "coldshot" -// #define EMSESP_DEBUG_DEFAULT "custom" +#define EMSESP_DEBUG_DEFAULT "custom" // #define EMSESP_DEBUG_DEFAULT "scheduler" // #define EMSESP_DEBUG_DEFAULT "heat_exchange" // #define EMSESP_DEBUG_DEFAULT "ls" diff --git a/src/web/WebCustomEntityService.cpp b/src/web/WebCustomEntityService.cpp index 790c4cba4..19e0f6fe0 100644 --- a/src/web/WebCustomEntityService.cpp +++ b/src/web/WebCustomEntityService.cpp @@ -666,6 +666,7 @@ bool WebCustomEntityService::get_value(std::shared_ptr telegram) } // hard coded tests +// add the entity and also add the command for writeable entities #ifdef EMSESP_TEST void WebCustomEntityService::test() { update([&](WebCustomEntity & webCustomEntity) { @@ -685,6 +686,14 @@ void WebCustomEntityService::test() { entityItem.writeable = true; entityItem.data = "70"; webCustomEntity.customEntityItems.push_back(entityItem); + Command::add( + EMSdevice::DeviceType::CUSTOM, + webCustomEntity.customEntityItems.back().name.c_str(), + [webCustomEntity](const char * value, const int8_t id) { + return EMSESP::webCustomEntityService.command_setvalue(value, id, webCustomEntity.customEntityItems.back().name.c_str()); + }, + FL_(entity_cmd), + CommandFlag::ADMIN_ONLY); // test 2 entityItem.id = 2; @@ -713,6 +722,14 @@ void WebCustomEntityService::test() { entityItem.writeable = true; entityItem.data = "14"; webCustomEntity.customEntityItems.push_back(entityItem); + Command::add( + EMSdevice::DeviceType::CUSTOM, + webCustomEntity.customEntityItems.back().name.c_str(), + [webCustomEntity](const char * value, const int8_t id) { + return EMSESP::webCustomEntityService.command_setvalue(value, id, webCustomEntity.customEntityItems.back().name.c_str()); + }, + FL_(entity_cmd), + CommandFlag::ADMIN_ONLY); // test 4 entityItem.id = 4; @@ -728,6 +745,14 @@ void WebCustomEntityService::test() { entityItem.data = "14"; entityItem.value = 12; webCustomEntity.customEntityItems.push_back(entityItem); + Command::add( + EMSdevice::DeviceType::CUSTOM, + webCustomEntity.customEntityItems.back().name.c_str(), + [webCustomEntity](const char * value, const int8_t id) { + return EMSESP::webCustomEntityService.command_setvalue(value, id, webCustomEntity.customEntityItems.back().name.c_str()); + }, + FL_(entity_cmd), + CommandFlag::ADMIN_ONLY); return StateUpdateResult::CHANGED; // persist the changes }); diff --git a/test/test_api/api_test.http b/test/test_api/api_test.http index 4c7d6d33f..ae30be6fc 100755 --- a/test/test_api/api_test.http +++ b/test/test_api/api_test.http @@ -74,6 +74,20 @@ Authorization: Bearer {{token}} GET {{host}}/api/boiler/commands +### + +POST {{host}}/api/custom/test_custom +Content-Type: application/json +Authorization: Bearer {{token}} + +{ + "value" : 22.0 +} + +### + +GET {{host}}/api/custom/test_custom + # # Test on dev #