mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-28 09:39:11 +03:00
move allvalues to new action endpoint
This commit is contained in:
@@ -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