mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
move allvalues to new action endpoint
This commit is contained in:
@@ -40,8 +40,9 @@ For more details go to [www.emsesp.org](https://www.emsesp.org/).
|
||||
- autodetect and download firmware upgrades via the WebUI
|
||||
- command 'show log' that lists out the current weblog buffer, showing last messages.
|
||||
- default web log buffer to 25 lines for ESP32s with no PSRAM
|
||||
- Try and determine correct board profile if none is set
|
||||
- try and determine correct board profile if none is set during boot
|
||||
- auto Scroll in WebLog UI - reduced delay so incoming logs are faster
|
||||
- uploading custom support info for Guest users [#2054]<https://github.com/emsesp/EMS-ESP32/issues/2054>
|
||||
|
||||
## Fixed
|
||||
|
||||
@@ -70,3 +71,4 @@ For more details go to [www.emsesp.org](https://www.emsesp.org/).
|
||||
- WebLog UI matches color schema of the terminal console correctly
|
||||
- Updated Web libraries, ArduinoJson
|
||||
- Help page doesn't show detailed tech info if the user is not 'admin' role [#2054](https://github.com/emsesp/EMS-ESP32/issues/2054)
|
||||
- removed system command `allvalues` and moved to an action called `export`
|
||||
|
||||
@@ -75,7 +75,6 @@ MAKE_WORD_TRANSLATION(schedule_cmd, "enable schedule item", "Aktiviere Zeitplane
|
||||
MAKE_WORD_TRANSLATION(entity_cmd, "set custom value on ems", "Sende eigene Entitäten zu EMS", "verstuur custom waarde naar EMS", "", "wyślij własną wartość na EMS", "", "", "emp üzerinde özel değer ayarla", "imposta valori personalizzati su EMS", "nastaviť vlastnú hodnotu na ems") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(commands_response, "get response", "Hole Antwort", "Verzoek om antwoord", "", "uzyskaj odpowiedź", "", "", "gelen cevap", "", "získať odpoveď") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(coldshot_cmd, "send a cold shot of water", "Zugabe einer Menge kalten Wassers", "", "", "uruchom tryśnięcie zimnej wody", "", "", "soğuk su gönder", "", "pošlite studenú dávku vody") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(allvalues_cmd, "output all values in system", "Alle Werte im System ausgeben", "", "", "wyświetl wszystkie wartości", "", "", "", "", "vypísať všetky hodnoty") // TODO remove
|
||||
MAKE_WORD_TRANSLATION(message_cmd, "send a message", "Eine Nachricht senden", "", "", "", "", "", "", "", "poslať správu") // TODO translate
|
||||
MAKE_WORD_TRANSLATION(values_cmd, "list all values", "Liste alle Werte auf", "", "", "", "", "", "", "", "vypísať všetky hodnoty") // TODO translate
|
||||
|
||||
|
||||
@@ -111,45 +111,6 @@ bool System::command_response(const char * value, const int8_t id, JsonObject ou
|
||||
return true;
|
||||
}
|
||||
|
||||
// output all the devices and the values
|
||||
// not system info
|
||||
// TODO remove?
|
||||
bool System::command_allvalues(const char * value, const int8_t id, JsonObject output) {
|
||||
JsonDocument doc;
|
||||
JsonObject device_output;
|
||||
// default to values
|
||||
if (value == nullptr || strlen(value) == 0) {
|
||||
value = F_(values);
|
||||
}
|
||||
|
||||
// System Entities
|
||||
// device_output = output["System"].to<JsonObject>();
|
||||
// get_value_info(device_output, value);
|
||||
|
||||
// EMS-Device Entities
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
std::string title = emsdevice->device_type_2_device_name_translated() + std::string(" ") + emsdevice->to_string();
|
||||
device_output = output[title].to<JsonObject>();
|
||||
emsdevice->get_value_info(device_output, value, DeviceValueTAG::TAG_NONE);
|
||||
}
|
||||
|
||||
// Custom Entities
|
||||
device_output = output["Custom Entities"].to<JsonObject>();
|
||||
EMSESP::webCustomEntityService.get_value_info(device_output, value);
|
||||
|
||||
// Scheduler
|
||||
device_output = output["Scheduler"].to<JsonObject>();
|
||||
EMSESP::webSchedulerService.get_value_info(device_output, value);
|
||||
|
||||
// Sensors
|
||||
device_output = output["Analog Sensors"].to<JsonObject>();
|
||||
EMSESP::analogsensor_.get_value_info(device_output, value);
|
||||
device_output = output["Temperature Sensors"].to<JsonObject>();
|
||||
EMSESP::temperaturesensor_.get_value_info(device_output, value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// fetch device values
|
||||
bool System::command_fetch(const char * value, const int8_t id) {
|
||||
std::string value_s;
|
||||
@@ -339,6 +300,8 @@ void System::system_restart(const char * partitionname) {
|
||||
delay(1000); // wait 1 second
|
||||
ESP.restart();
|
||||
#else
|
||||
restart_requested(false);
|
||||
restart_pending(false);
|
||||
if (partitionname != nullptr) {
|
||||
LOG_INFO("Restarting EMS-ESP from %s partition", partitionname);
|
||||
} else {
|
||||
@@ -875,7 +838,6 @@ void System::commands_init() {
|
||||
|
||||
// these commands will return data in JSON format
|
||||
Command::add(EMSdevice::DeviceType::SYSTEM, F("response"), System::command_response, FL_(commands_response));
|
||||
Command::add(EMSdevice::DeviceType::SYSTEM, F("allvalues"), System::command_allvalues, FL_(allvalues_cmd)); // TODO remove
|
||||
|
||||
// MQTT subscribe "ems-esp/system/#"
|
||||
Mqtt::subscribe(EMSdevice::DeviceType::SYSTEM, "system/#", nullptr); // use empty function callback
|
||||
|
||||
@@ -65,7 +65,6 @@ class System {
|
||||
static bool command_message(const char * value, const int8_t id);
|
||||
static bool command_info(const char * value, const int8_t id, JsonObject output);
|
||||
static bool command_response(const char * value, const int8_t id, JsonObject output);
|
||||
static bool command_allvalues(const char * value, const int8_t id, JsonObject output); // TODO fix
|
||||
|
||||
static bool get_value_info(JsonObject root, const char * cmd);
|
||||
static void get_value_json(JsonObject output, const std::string & circuit, const std::string & name, JsonVariant val);
|
||||
|
||||
@@ -989,11 +989,26 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
// 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>();
|
||||
|
||||
char data1[] = "{\"device\":\"system\", \"cmd\":\"restart\",\"id\":-1}";
|
||||
deserializeJson(doc, data1);
|
||||
request.url("/api");
|
||||
EMSESP::webAPIService.webAPIService(&request, json);
|
||||
EMSESP::webAPIService.webAPIService(&request, doc.as<JsonVariant>());
|
||||
|
||||
char data2[] = "{\"action\":\"customSupport\", \"param\":\"hello\"}";
|
||||
deserializeJson(doc, data2);
|
||||
request.url("/rest/action");
|
||||
EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||
|
||||
char data3[] = "{\"action\":\"export\", \"param\":\"schedule\"}";
|
||||
deserializeJson(doc, data3);
|
||||
request.url("/rest/action");
|
||||
EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||
|
||||
char data4[] = "{\"action\":\"export\", \"param\":\"allvalues\"}";
|
||||
deserializeJson(doc, data4);
|
||||
request.url("/rest/action");
|
||||
EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||
|
||||
// request.url("/api/thermostat");
|
||||
// EMSESP::webAPIService.webAPIService(&request);
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define EMSESP_APP_VERSION "3.7.0-dev.40"
|
||||
#define EMSESP_APP_VERSION "3.7.0-dev.41"
|
||||
|
||||
@@ -584,7 +584,7 @@ void WebSchedulerService::test() {
|
||||
test_value = "(custom/seltemp)";
|
||||
command("test5", test_cmd.c_str(), compute(test_value).c_str());
|
||||
|
||||
// this will fail unless test("boiler") is loaded
|
||||
// note: this will fail unless test("boiler") is loaded before hand
|
||||
test_value = "(boiler/outdoortemp)";
|
||||
command("test6", test_cmd.c_str(), compute(test_value).c_str());
|
||||
|
||||
|
||||
@@ -154,10 +154,6 @@ void WebStatusService::action(AsyncWebServerRequest * request, JsonVariant json)
|
||||
std::string action = json["action"];
|
||||
std::string param = json["param"]; // is optional
|
||||
|
||||
// TODO remove
|
||||
Serial.printf("Action: %s\n", action.c_str());
|
||||
Serial.printf("Param: %s\n", param.c_str());
|
||||
|
||||
bool ok = true;
|
||||
if (action == "checkUpgrade") {
|
||||
ok = checkUpgrade(root, param);
|
||||
@@ -167,6 +163,17 @@ void WebStatusService::action(AsyncWebServerRequest * request, JsonVariant json)
|
||||
ok = customSupport(root);
|
||||
}
|
||||
|
||||
#if defined(EMSESP_UNITY)
|
||||
// store the result so we can test with Unity later
|
||||
storeResponse(output);
|
||||
#endif
|
||||
#if defined(EMSESP_STANDALONE) && !defined(EMSESP_UNITY)
|
||||
Serial.printf("%sweb output: %s[%s]", COLOR_WHITE, COLOR_BRIGHT_CYAN, request->url().c_str());
|
||||
Serial.printf(" %s(%d)%s ", ok ? COLOR_BRIGHT_GREEN : COLOR_BRIGHT_RED, ok ? 200 : 400, COLOR_YELLOW);
|
||||
serializeJson(root, Serial);
|
||||
Serial.println(COLOR_RESET);
|
||||
#endif
|
||||
|
||||
// send response
|
||||
if (!ok) {
|
||||
request->send(400);
|
||||
@@ -192,6 +199,34 @@ bool WebStatusService::checkUpgrade(JsonObject root, std::string & latest_versio
|
||||
return true;
|
||||
}
|
||||
|
||||
// output all the devices and the values
|
||||
void WebStatusService::allvalues(JsonObject output) {
|
||||
JsonDocument doc;
|
||||
JsonObject device_output;
|
||||
auto value = F_(values);
|
||||
|
||||
// EMS-Device Entities
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
std::string title = emsdevice->device_type_2_device_name_translated() + std::string(" ") + emsdevice->to_string();
|
||||
device_output = output[title].to<JsonObject>();
|
||||
emsdevice->get_value_info(device_output, value, DeviceValueTAG::TAG_NONE);
|
||||
}
|
||||
|
||||
// Custom Entities
|
||||
device_output = output["Custom Entities"].to<JsonObject>();
|
||||
EMSESP::webCustomEntityService.get_value_info(device_output, value);
|
||||
|
||||
// Scheduler
|
||||
device_output = output["Scheduler"].to<JsonObject>();
|
||||
EMSESP::webSchedulerService.get_value_info(device_output, value);
|
||||
|
||||
// Sensors
|
||||
device_output = output["Analog Sensors"].to<JsonObject>();
|
||||
EMSESP::analogsensor_.get_value_info(device_output, value);
|
||||
device_output = output["Temperature Sensors"].to<JsonObject>();
|
||||
EMSESP::temperaturesensor_.get_value_info(device_output, value);
|
||||
}
|
||||
|
||||
// returns data for a specific feature/settings as a json object
|
||||
bool WebStatusService::exportData(JsonObject root, std::string & type) {
|
||||
root["type"] = type;
|
||||
@@ -211,6 +246,8 @@ bool WebStatusService::exportData(JsonObject root, std::string & type) {
|
||||
System::extractSettings(EMSESP_CUSTOMIZATION_FILE, "Customizations", root);
|
||||
} else if (type == "entities") {
|
||||
System::extractSettings(EMSESP_CUSTOMENTITY_FILE, "Entities", root);
|
||||
} else if (type == "allvalues") {
|
||||
allvalues(root);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define WebStatusService_h
|
||||
|
||||
#define EMSESP_SYSTEM_STATUS_SERVICE_PATH "/rest/systemStatus"
|
||||
|
||||
#define EMSESP_ACTION_SERVICE_PATH "/rest/action"
|
||||
|
||||
#include <semver200.h> // for version checking
|
||||
@@ -13,7 +12,10 @@ class WebStatusService {
|
||||
public:
|
||||
WebStatusService(AsyncWebServer * server, SecurityManager * securityManager);
|
||||
|
||||
// make all functions public so we can test in the debug and standalone mode
|
||||
#ifndef EMSESP_STANDALONE
|
||||
protected:
|
||||
#endif
|
||||
void systemStatus(AsyncWebServerRequest * request);
|
||||
void action(AsyncWebServerRequest * request, JsonVariant json);
|
||||
|
||||
@@ -21,6 +23,7 @@ class WebStatusService {
|
||||
bool checkUpgrade(JsonObject root, std::string & latest_version);
|
||||
bool exportData(JsonObject root, std::string & type);
|
||||
bool customSupport(JsonObject root);
|
||||
void allvalues(JsonObject output);
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
Reference in New Issue
Block a user