debug tests for api's

This commit is contained in:
proddy
2024-08-31 16:09:48 +02:00
parent 0753fee385
commit 9c83124424
5 changed files with 75 additions and 32 deletions

View File

@@ -39,7 +39,7 @@ CXX_STANDARD := -std=gnu++14
# Defined Symbols # Defined Symbols
#---------------------------------------------------------------------- #----------------------------------------------------------------------
DEFINES += -DARDUINOJSON_ENABLE -DARDUINOJSON_ENABLE_ARDUINO_STRING -DARDUINOJSON_USE_DOUBLE=0 DEFINES += -DARDUINOJSON_ENABLE -DARDUINOJSON_ENABLE_ARDUINO_STRING -DARDUINOJSON_USE_DOUBLE=0
DEFINES += -DEMSESP_STANDALONE -DEMSESP_TEST -DEMC_RX_BUFFER_SIZE=1500 DEFINES += -DEMSESP_STANDALONE -DEMSESP_TEST -DEMSESP_DEBUG -DEMC_RX_BUFFER_SIZE=1500
DEFINES += $(ARGS) DEFINES += $(ARGS)
DEFAULTS = -DEMSESP_DEFAULT_LOCALE=\"en\" -DEMSESP_DEFAULT_TX_MODE=8 -DEMSESP_DEFAULT_VERSION=\"3.7.0-dev\" -DEMSESP_DEFAULT_BOARD_PROFILE=\"S32\" DEFAULTS = -DEMSESP_DEFAULT_LOCALE=\"en\" -DEMSESP_DEFAULT_TX_MODE=8 -DEMSESP_DEFAULT_VERSION=\"3.7.0-dev\" -DEMSESP_DEFAULT_BOARD_PROFILE=\"S32\"

View File

@@ -4,7 +4,7 @@
# The response will be shown in the right panel # The response will be shown in the right panel
@host = http://ems-esp.local @host = http://ems-esp.local
@host_dev = http://10.10.10.173 @host_dev = http://10.10.10.175
@host_standalone = http://localhost:3080 @host_standalone = http://localhost:3080
@host_standalone2 = http://localhost:3082 @host_standalone2 = http://localhost:3082
@@ -84,6 +84,11 @@ GET {{host_dev}}/api/system/info
### ###
GET {{host_dev}}/api/system/restart
Authorization: Bearer {{token}}
###
GET {{host_dev}}/api?device=system&cmd=test&data=general GET {{host_dev}}/api?device=system&cmd=test&data=general
### ###
@@ -150,7 +155,7 @@ Content-Type: application/json
# https://developers.home-assistant.io/docs/api/rest/#post-apiservicesdomainservice # https://developers.home-assistant.io/docs/api/rest/#post-apiservicesdomainservice
POST {{host_standalone}}/api POST {{host_standalone}}/api
# HA # HA tests
@ha = http://192.168.1.42:8123 @ha = http://192.168.1.42:8123
@ha_token = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIwMzMyZjU1MjhlZmM0NGIyOTgyMjIxNThiODU1NDkyNSIsImlhdCI6MTcyMTMwNDg2NSwiZXhwIjoyMDM2NjY0ODY1fQ.Q-Y7E_i7clH3ff4Ma-OMmhZfbN7aMi_CahKwmoar @ha_token = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIwMzMyZjU1MjhlZmM0NGIyOTgyMjIxNThiODU1NDkyNSIsImlhdCI6MTcyMTMwNDg2NSwiZXhwIjoyMDM2NjY0ODY1fQ.Q-Y7E_i7clH3ff4Ma-OMmhZfbN7aMi_CahKwmoar

View File

@@ -30,6 +30,7 @@ const headers = {
// GLOBAL VARIABLES // GLOBAL VARIABLES
let countWifiScanPoll = 0; // wifi network scan let countWifiScanPoll = 0; // wifi network scan
let countHardwarePoll = 0; // for during an upload
function updateMask(entity: any, de: any, dd: any) { function updateMask(entity: any, de: any, dd: any) {
const current_mask = parseInt(entity.slice(0, 2), 16); const current_mask = parseInt(entity.slice(0, 2), 16);
@@ -359,9 +360,6 @@ const ACTIVITY_ENDPOINT = REST_ENDPOINT_ROOT + 'activity';
// SETTINGS // SETTINGS
const HARDWARE_STATUS_ENDPOINT = REST_ENDPOINT_ROOT + 'hardwareStatus'; const HARDWARE_STATUS_ENDPOINT = REST_ENDPOINT_ROOT + 'hardwareStatus';
const SECURITY_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'securitySettings'; const SECURITY_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'securitySettings';
const RESTART_ENDPOINT = REST_ENDPOINT_ROOT + 'restart';
const RESTART_PARTITION_ENDPOINT = REST_ENDPOINT_ROOT + 'partition';
const FACTORY_RESET_ENDPOINT = REST_ENDPOINT_ROOT + 'factoryReset';
// SYSTEM SIGNIN // SYSTEM SIGNIN
const VERIFY_AUTHORIZATION_ENDPOINT = REST_ENDPOINT_ROOT + 'verifyAuthorization'; const VERIFY_AUTHORIZATION_ENDPOINT = REST_ENDPOINT_ROOT + 'verifyAuthorization';
@@ -371,7 +369,7 @@ const GENERATE_TOKEN_ENDPOINT = REST_ENDPOINT_ROOT + 'generateToken';
const VERSION = '3.7.0-dev.0'; const VERSION = '3.7.0-dev.0';
// const VERSION = '3.6.4'; // const VERSION = '3.6.4';
const hardware_status = { let hardware_status = {
emsesp_version: VERSION, emsesp_version: VERSION,
esp_platform: 'ESP32S3', esp_platform: 'ESP32S3',
build_flags: 'DEMO', build_flags: 'DEMO',
@@ -396,7 +394,8 @@ const hardware_status = {
free_psram: 8166, free_psram: 8166,
has_loader: true, has_loader: true,
// model: '' // model: ''
model: 'BBQKees Electronics EMS Gateway E32 V2 (E32 V2.0 P3/2024011)' model: 'BBQKees Electronics EMS Gateway E32 V2 (E32 V2.0 P3/2024011)',
status: 'downloading'
}; };
const system_status = { const system_status = {
@@ -4212,7 +4211,21 @@ router
router router
.get(SYSTEM_STATUS_ENDPOINT, () => system_status) .get(SYSTEM_STATUS_ENDPOINT, () => system_status)
.get(ACTIVITY_ENDPOINT, () => activity) .get(ACTIVITY_ENDPOINT, () => activity)
.get(HARDWARE_STATUS_ENDPOINT, () => hardware_status) .get(HARDWARE_STATUS_ENDPOINT, () => {
if (countHardwarePoll === 0) {
console.log('Reseting hardware count...');
}
if (countHardwarePoll >= 2) {
countHardwarePoll = 0;
hardware_status.status = 'ready';
}
console.log('Hardware count ' + countHardwarePoll + ' of 2');
countHardwarePoll++;
return hardware_status;
})
.get(SECURITY_SETTINGS_ENDPOINT, () => security_settings) .get(SECURITY_SETTINGS_ENDPOINT, () => security_settings)
.post(SECURITY_SETTINGS_ENDPOINT, async (request: any) => { .post(SECURITY_SETTINGS_ENDPOINT, async (request: any) => {
security_settings = await request.json(); security_settings = await request.json();
@@ -4220,15 +4233,6 @@ router
return status(200); return status(200);
}) })
.get(VERIFY_AUTHORIZATION_ENDPOINT, () => verify_authentication) .get(VERIFY_AUTHORIZATION_ENDPOINT, () => verify_authentication)
.post(RESTART_ENDPOINT, () => {
console.log('restarting...');
return status(200);
})
.post(RESTART_PARTITION_ENDPOINT, () => {
console.log('restarting.from partition...');
return status(200);
})
.post(FACTORY_RESET_ENDPOINT, () => status(200))
.post(SIGN_IN_ENDPOINT, () => signin) .post(SIGN_IN_ENDPOINT, () => signin)
.get(GENERATE_TOKEN_ENDPOINT, () => generate_token); .get(GENERATE_TOKEN_ENDPOINT, () => generate_token);
@@ -4695,13 +4699,33 @@ router
.get(EMSESP_SYSTEM_INFO_ENDPOINT, () => emsesp_info) .get(EMSESP_SYSTEM_INFO_ENDPOINT, () => emsesp_info)
.post(API_ENDPOINT_ROOT, async (request: any) => { .post(API_ENDPOINT_ROOT, async (request: any) => {
const data = await request.json(); const data = await request.json();
// check if the json data has key called cmd
let cmd = '';
if (data.hasOwnProperty('cmd')) {
cmd = data.cmd;
} else if (data.hasOwnProperty('entity')) {
cmd = data.entity;
} else {
return status(400); // bad request
}
if (data.device === 'system') { if (data.device === 'system') {
if (data.entity === 'info') { if (cmd === 'info') {
return emsesp_info; return emsesp_info;
} }
if (data.entity === 'allvalues') { if (cmd === 'allvalues') {
return emsesp_allvalues; return emsesp_allvalues;
} }
if (cmd === 'format') {
console.log('formatting...');
return status(200);
}
if (cmd === 'restart') {
console.log('restarting...');
hardware_status.status = 'restarting';
countHardwarePoll = 0;
return status(200);
}
} }
return status(404); // not found return status(404); // not found
}); });

View File

@@ -417,7 +417,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
if (command == "upload") { if (command == "upload") {
// S3 has 16MB flash // S3 has 16MB flash
EMSESP::system_.uploadFirmwareURL("https://github.com/emsesp/EMS-ESP32/releases/download/latest/EMS-ESP-3_7_0-dev_31-ESP32S3-16MB+.bin"); // TODO remove EMSESP::system_.uploadFirmwareURL("https://github.com/emsesp/EMS-ESP32/releases/download/latest/EMS-ESP-3_7_0-dev_31-ESP32S3-16MB+.bin");
ok = true; ok = true;
} }
#endif #endif
@@ -958,8 +958,8 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
bool single; bool single;
// single = true; single = true;
single = false; // single = false;
AsyncWebServerRequest request; AsyncWebServerRequest request;
JsonDocument doc; JsonDocument doc;
@@ -972,19 +972,33 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
if (single) { if (single) {
// run dedicated tests only // run dedicated tests only
EMSESP::webCustomEntityService.test(); // custom entities
EMSESP::webCustomizationService.test(); // set customizations - this will overwrite any settings in the FS // EMSESP::webCustomEntityService.test(); // custom entities
EMSESP::temperaturesensor_.test(); // add temperature sensors // EMSESP::webCustomizationService.test(); // set customizations - this will overwrite any settings in the FS
EMSESP::webSchedulerService.test(); // run scheduler tests, and conditions // EMSESP::temperaturesensor_.test(); // add temperature sensors
// EMSESP::webSchedulerService.test(); // run scheduler tests, and conditions
// shell.invoke_command("call system fetch"); // shell.invoke_command("call system fetch");
// request.url("/api/system/fetch"); // request.url("/api/system/fetch");
// EMSESP::webAPIService.webAPIService(&request); // EMSESP::webAPIService.webAPIService(&request);
request.url("/api/thermostat"); // request.url("/api/system/restart");
EMSESP::webAPIService.webAPIService(&request); // EMSESP::webAPIService.webAPIService(&request);
request.url("/api/thermostat/hc1");
EMSESP::webAPIService.webAPIService(&request); // request.url("/api/system/format");
// EMSESP::webAPIService.webAPIService(&request);
request.method(HTTP_POST);
char data_api[] = "{\"device\":\"system\", \"cmd\":\"restart\",\"id\":-1}";
deserializeJson(doc, data_api);
json = doc.as<JsonVariant>();
request.url("/api");
EMSESP::webAPIService.webAPIService(&request, json);
// request.url("/api/thermostat");
// EMSESP::webAPIService.webAPIService(&request);
// request.url("/api/thermostat/hc1");
// EMSESP::webAPIService.webAPIService(&request);
} else { } else {
EMSESP::webCustomEntityService.test(); // custom entities EMSESP::webCustomEntityService.test(); // custom entities

View File

@@ -59,7 +59,7 @@ namespace emsesp {
// #define EMSESP_DEBUG_DEFAULT "scheduler" // #define EMSESP_DEBUG_DEFAULT "scheduler"
// #define EMSESP_DEBUG_DEFAULT "heat_exchange" // #define EMSESP_DEBUG_DEFAULT "heat_exchange"
// #define EMSESP_DEBUG_DEFAULT "ls" // #define EMSESP_DEBUG_DEFAULT "ls"
#define EMSESP_DEBUG_DEFAULT "upload" // #define EMSESP_DEBUG_DEFAULT "upload"
#ifndef EMSESP_DEBUG_DEFAULT #ifndef EMSESP_DEBUG_DEFAULT
#define EMSESP_DEBUG_DEFAULT "general" #define EMSESP_DEBUG_DEFAULT "general"