mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
move the Get* endpoints to their right service classes
This commit is contained in:
@@ -25,25 +25,7 @@ uint16_t WebAPIService::api_fails_ = 0;
|
|||||||
|
|
||||||
WebAPIService::WebAPIService(AsyncWebServer * server, SecurityManager * securityManager)
|
WebAPIService::WebAPIService(AsyncWebServer * server, SecurityManager * securityManager)
|
||||||
: _securityManager(securityManager) {
|
: _securityManager(securityManager) {
|
||||||
// API
|
|
||||||
server->on(EMSESP_API_SERVICE_PATH, [this](AsyncWebServerRequest * request, JsonVariant json) { webAPIService(request, json); });
|
server->on(EMSESP_API_SERVICE_PATH, [this](AsyncWebServerRequest * request, JsonVariant json) { webAPIService(request, json); });
|
||||||
|
|
||||||
// settings
|
|
||||||
server->on(GET_SETTINGS_PATH,
|
|
||||||
HTTP_GET,
|
|
||||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { getSettings(request); }, AuthenticationPredicates::IS_ADMIN));
|
|
||||||
|
|
||||||
server->on(GET_CUSTOMIZATIONS_PATH,
|
|
||||||
HTTP_GET,
|
|
||||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { getCustomizations(request); }, AuthenticationPredicates::IS_ADMIN));
|
|
||||||
|
|
||||||
server->on(GET_SCHEDULE_PATH,
|
|
||||||
HTTP_GET,
|
|
||||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { getSchedule(request); }, AuthenticationPredicates::IS_ADMIN));
|
|
||||||
|
|
||||||
server->on(GET_ENTITIES_PATH,
|
|
||||||
HTTP_GET,
|
|
||||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { getEntities(request); }, AuthenticationPredicates::IS_ADMIN));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST|GET /{device}
|
// POST|GET /{device}
|
||||||
@@ -173,62 +155,6 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject input) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebAPIService::getSettings(AsyncWebServerRequest * request) {
|
|
||||||
auto * response = new AsyncJsonResponse(false);
|
|
||||||
JsonObject root = response->getRoot();
|
|
||||||
|
|
||||||
root["type"] = "settings";
|
|
||||||
|
|
||||||
JsonObject node = root["System"].to<JsonObject>();
|
|
||||||
node["version"] = EMSESP_APP_VERSION;
|
|
||||||
|
|
||||||
System::extractSettings(NETWORK_SETTINGS_FILE, "Network", root);
|
|
||||||
System::extractSettings(AP_SETTINGS_FILE, "AP", root);
|
|
||||||
System::extractSettings(MQTT_SETTINGS_FILE, "MQTT", root);
|
|
||||||
System::extractSettings(NTP_SETTINGS_FILE, "NTP", root);
|
|
||||||
System::extractSettings(SECURITY_SETTINGS_FILE, "Security", root);
|
|
||||||
System::extractSettings(EMSESP_SETTINGS_FILE, "Settings", root);
|
|
||||||
|
|
||||||
response->setLength();
|
|
||||||
request->send(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebAPIService::getCustomizations(AsyncWebServerRequest * request) {
|
|
||||||
auto * response = new AsyncJsonResponse(false);
|
|
||||||
JsonObject root = response->getRoot();
|
|
||||||
|
|
||||||
root["type"] = "customizations";
|
|
||||||
|
|
||||||
System::extractSettings(EMSESP_CUSTOMIZATION_FILE, "Customizations", root);
|
|
||||||
|
|
||||||
response->setLength();
|
|
||||||
request->send(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebAPIService::getSchedule(AsyncWebServerRequest * request) {
|
|
||||||
auto * response = new AsyncJsonResponse(false);
|
|
||||||
JsonObject root = response->getRoot();
|
|
||||||
|
|
||||||
root["type"] = "schedule";
|
|
||||||
|
|
||||||
System::extractSettings(EMSESP_SCHEDULER_FILE, "Schedule", root);
|
|
||||||
|
|
||||||
response->setLength();
|
|
||||||
request->send(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebAPIService::getEntities(AsyncWebServerRequest * request) {
|
|
||||||
auto * response = new AsyncJsonResponse(false);
|
|
||||||
JsonObject root = response->getRoot();
|
|
||||||
|
|
||||||
root["type"] = "entities";
|
|
||||||
|
|
||||||
System::extractSettings(EMSESP_CUSTOMENTITY_FILE, "Entities", root);
|
|
||||||
|
|
||||||
response->setLength();
|
|
||||||
request->send(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(EMSESP_UNITY)
|
#if defined(EMSESP_UNITY)
|
||||||
// store the result so we can test with Unity later
|
// store the result so we can test with Unity later
|
||||||
static JsonDocument storeResponseDoc_;
|
static JsonDocument storeResponseDoc_;
|
||||||
|
|||||||
@@ -21,11 +21,6 @@
|
|||||||
|
|
||||||
#define EMSESP_API_SERVICE_PATH "/api"
|
#define EMSESP_API_SERVICE_PATH "/api"
|
||||||
|
|
||||||
#define GET_SETTINGS_PATH "/rest/getSettings"
|
|
||||||
#define GET_CUSTOMIZATIONS_PATH "/rest/getCustomizations"
|
|
||||||
#define GET_SCHEDULE_PATH "/rest/getSchedule"
|
|
||||||
#define GET_ENTITIES_PATH "/rest/getEntities"
|
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
class WebAPIService {
|
class WebAPIService {
|
||||||
@@ -56,10 +51,6 @@ class WebAPIService {
|
|||||||
static uint16_t api_fails_;
|
static uint16_t api_fails_;
|
||||||
|
|
||||||
void parse(AsyncWebServerRequest * request, JsonObject input);
|
void parse(AsyncWebServerRequest * request, JsonObject input);
|
||||||
void getSettings(AsyncWebServerRequest * request);
|
|
||||||
void getCustomizations(AsyncWebServerRequest * request);
|
|
||||||
void getSchedule(AsyncWebServerRequest * request);
|
|
||||||
void getEntities(AsyncWebServerRequest * request);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace emsesp
|
} // namespace emsesp
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ WebCustomEntityService::WebCustomEntityService(AsyncWebServer * server, FS * fs,
|
|||||||
securityManager,
|
securityManager,
|
||||||
AuthenticationPredicates::IS_AUTHENTICATED)
|
AuthenticationPredicates::IS_AUTHENTICATED)
|
||||||
, _fsPersistence(WebCustomEntity::read, WebCustomEntity::update, this, fs, EMSESP_CUSTOMENTITY_FILE) {
|
, _fsPersistence(WebCustomEntity::read, WebCustomEntity::update, this, fs, EMSESP_CUSTOMENTITY_FILE) {
|
||||||
|
server->on(EMSESP_GET_ENTITIES_PATH,
|
||||||
|
HTTP_GET,
|
||||||
|
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { getEntities(request); }, AuthenticationPredicates::IS_ADMIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
// load the settings when the service starts
|
// load the settings when the service starts
|
||||||
@@ -708,4 +711,17 @@ void WebCustomEntityService::test() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// return entities as a json object
|
||||||
|
void WebCustomEntityService::getEntities(AsyncWebServerRequest * request) {
|
||||||
|
auto * response = new AsyncJsonResponse(false);
|
||||||
|
JsonObject root = response->getRoot();
|
||||||
|
|
||||||
|
root["type"] = "entities";
|
||||||
|
|
||||||
|
System::extractSettings(EMSESP_CUSTOMENTITY_FILE, "Entities", root);
|
||||||
|
|
||||||
|
response->setLength();
|
||||||
|
request->send(response);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace emsesp
|
} // namespace emsesp
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#define EMSESP_CUSTOMENTITY_FILE "/config/emsespEntity.json"
|
#define EMSESP_CUSTOMENTITY_FILE "/config/emsespEntity.json"
|
||||||
#define EMSESP_CUSTOMENTITY_SERVICE_PATH "/rest/customEntities" // GET and POST
|
#define EMSESP_CUSTOMENTITY_SERVICE_PATH "/rest/customEntities" // GET and POST
|
||||||
|
#define EMSESP_GET_ENTITIES_PATH "/rest/getEntities"
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
@@ -80,6 +81,8 @@ class WebCustomEntityService : public StatefulService<WebCustomEntity> {
|
|||||||
HttpEndpoint<WebCustomEntity> _httpEndpoint;
|
HttpEndpoint<WebCustomEntity> _httpEndpoint;
|
||||||
FSPersistence<WebCustomEntity> _fsPersistence;
|
FSPersistence<WebCustomEntity> _fsPersistence;
|
||||||
|
|
||||||
|
void getEntities(AsyncWebServerRequest * request);
|
||||||
|
|
||||||
std::list<CustomEntityItem> * customEntityItems_; // pointer to the list of entity items
|
std::list<CustomEntityItem> * customEntityItems_; // pointer to the list of entity items
|
||||||
|
|
||||||
bool ha_registered_ = false;
|
bool ha_registered_ = false;
|
||||||
|
|||||||
@@ -25,24 +25,25 @@ bool WebCustomization::_start = true;
|
|||||||
WebCustomizationService::WebCustomizationService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
WebCustomizationService::WebCustomizationService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
||||||
: _fsPersistence(WebCustomization::read, WebCustomization::update, this, fs, EMSESP_CUSTOMIZATION_FILE) {
|
: _fsPersistence(WebCustomization::read, WebCustomization::update, this, fs, EMSESP_CUSTOMIZATION_FILE) {
|
||||||
// GET
|
// GET
|
||||||
server->on(DEVICE_ENTITIES_PATH,
|
server->on(EMSESP_DEVICE_ENTITIES_PATH,
|
||||||
HTTP_GET,
|
HTTP_GET,
|
||||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { device_entities(request); }, AuthenticationPredicates::IS_AUTHENTICATED));
|
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { device_entities(request); }, AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
|
server->on(EMSESP_DEVICES_SERVICE_PATH,
|
||||||
server->on(DEVICES_SERVICE_PATH,
|
|
||||||
HTTP_GET,
|
HTTP_GET,
|
||||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { devices(request); }, AuthenticationPredicates::IS_AUTHENTICATED));
|
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { devices(request); }, AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
|
server->on(EMSESP_GET_CUSTOMIZATIONS_PATH,
|
||||||
|
HTTP_GET,
|
||||||
|
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { getCustomizations(request); }, AuthenticationPredicates::IS_ADMIN));
|
||||||
|
|
||||||
|
|
||||||
// POST
|
// POST
|
||||||
server->on(RESET_CUSTOMIZATION_SERVICE_PATH,
|
server->on(EMSESP_RESET_CUSTOMIZATION_SERVICE_PATH,
|
||||||
HTTP_POST,
|
HTTP_POST,
|
||||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { reset_customization(request); }, AuthenticationPredicates::IS_ADMIN));
|
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { reset_customization(request); }, AuthenticationPredicates::IS_ADMIN));
|
||||||
|
server->on(EMSESP_WRITE_DEVICE_NAME_PATH,
|
||||||
server->on(WRITE_DEVICE_NAME_PATH,
|
|
||||||
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { writeDeviceName(request, json); },
|
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { writeDeviceName(request, json); },
|
||||||
AuthenticationPredicates::IS_AUTHENTICATED));
|
AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
|
server->on(EMSESP_CUSTOMIZATION_ENTITIES_PATH,
|
||||||
server->on(CUSTOMIZATION_ENTITIES_PATH,
|
|
||||||
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { customization_entities(request, json); },
|
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { customization_entities(request, json); },
|
||||||
AuthenticationPredicates::IS_AUTHENTICATED));
|
AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
}
|
}
|
||||||
@@ -424,4 +425,17 @@ void WebCustomizationService::test() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// return all customizations in a json object
|
||||||
|
void WebCustomizationService::getCustomizations(AsyncWebServerRequest * request) {
|
||||||
|
auto * response = new AsyncJsonResponse(false);
|
||||||
|
JsonObject root = response->getRoot();
|
||||||
|
|
||||||
|
root["type"] = "customizations";
|
||||||
|
|
||||||
|
System::extractSettings(EMSESP_CUSTOMIZATION_FILE, "Customizations", root);
|
||||||
|
|
||||||
|
response->setLength();
|
||||||
|
request->send(response);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace emsesp
|
} // namespace emsesp
|
||||||
|
|||||||
@@ -22,13 +22,14 @@
|
|||||||
#define EMSESP_CUSTOMIZATION_FILE "/config/emsespCustomization.json"
|
#define EMSESP_CUSTOMIZATION_FILE "/config/emsespCustomization.json"
|
||||||
|
|
||||||
// GET
|
// GET
|
||||||
#define DEVICES_SERVICE_PATH "/rest/devices"
|
#define EMSESP_DEVICES_SERVICE_PATH "/rest/devices"
|
||||||
#define DEVICE_ENTITIES_PATH "/rest/deviceEntities"
|
#define EMSESP_DEVICE_ENTITIES_PATH "/rest/deviceEntities"
|
||||||
|
#define EMSESP_GET_CUSTOMIZATIONS_PATH "/rest/getCustomizations"
|
||||||
|
|
||||||
// POST
|
// POST
|
||||||
#define CUSTOMIZATION_ENTITIES_PATH "/rest/customizationEntities"
|
#define EMSESP_CUSTOMIZATION_ENTITIES_PATH "/rest/customizationEntities"
|
||||||
#define RESET_CUSTOMIZATION_SERVICE_PATH "/rest/resetCustomizations"
|
#define EMSESP_RESET_CUSTOMIZATION_SERVICE_PATH "/rest/resetCustomizations"
|
||||||
#define WRITE_DEVICE_NAME_PATH "/rest/writeDeviceName"
|
#define EMSESP_WRITE_DEVICE_NAME_PATH "/rest/writeDeviceName"
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
@@ -99,6 +100,7 @@ class WebCustomizationService : public StatefulService<WebCustomization> {
|
|||||||
// GET
|
// GET
|
||||||
void devices(AsyncWebServerRequest * request);
|
void devices(AsyncWebServerRequest * request);
|
||||||
void device_entities(AsyncWebServerRequest * request);
|
void device_entities(AsyncWebServerRequest * request);
|
||||||
|
void getCustomizations(AsyncWebServerRequest * request);
|
||||||
|
|
||||||
// POST
|
// POST
|
||||||
void customization_entities(AsyncWebServerRequest * request, JsonVariant json);
|
void customization_entities(AsyncWebServerRequest * request, JsonVariant json);
|
||||||
|
|||||||
@@ -22,25 +22,25 @@ namespace emsesp {
|
|||||||
|
|
||||||
WebDataService::WebDataService(AsyncWebServer * server, SecurityManager * securityManager) {
|
WebDataService::WebDataService(AsyncWebServer * server, SecurityManager * securityManager) {
|
||||||
// write endpoints
|
// write endpoints
|
||||||
server->on(WRITE_DEVICE_VALUE_SERVICE_PATH,
|
server->on(EMSESP_WRITE_DEVICE_VALUE_SERVICE_PATH,
|
||||||
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { write_device_value(request, json); },
|
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { write_device_value(request, json); },
|
||||||
AuthenticationPredicates::IS_ADMIN));
|
AuthenticationPredicates::IS_ADMIN));
|
||||||
server->on(WRITE_TEMPERATURE_SENSOR_SERVICE_PATH,
|
server->on(EMSESP_WRITE_TEMPERATURE_SENSOR_SERVICE_PATH,
|
||||||
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { write_temperature_sensor(request, json); },
|
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { write_temperature_sensor(request, json); },
|
||||||
AuthenticationPredicates::IS_ADMIN));
|
AuthenticationPredicates::IS_ADMIN));
|
||||||
server->on(WRITE_ANALOG_SENSOR_SERVICE_PATH,
|
server->on(EMSESP_WRITE_ANALOG_SENSOR_SERVICE_PATH,
|
||||||
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { write_analog_sensor(request, json); },
|
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { write_analog_sensor(request, json); },
|
||||||
AuthenticationPredicates::IS_ADMIN));
|
AuthenticationPredicates::IS_ADMIN));
|
||||||
// GET's
|
// GET's
|
||||||
server->on(DEVICE_DATA_SERVICE_PATH,
|
server->on(EMSESP_DEVICE_DATA_SERVICE_PATH,
|
||||||
HTTP_GET,
|
HTTP_GET,
|
||||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { device_data(request); }, AuthenticationPredicates::IS_AUTHENTICATED));
|
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { device_data(request); }, AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
|
|
||||||
server->on(CORE_DATA_SERVICE_PATH,
|
server->on(EMSESP_CORE_DATA_SERVICE_PATH,
|
||||||
HTTP_GET,
|
HTTP_GET,
|
||||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { core_data(request); }, AuthenticationPredicates::IS_AUTHENTICATED));
|
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { core_data(request); }, AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
|
|
||||||
server->on(SENSOR_DATA_SERVICE_PATH,
|
server->on(EMSESP_SENSOR_DATA_SERVICE_PATH,
|
||||||
HTTP_GET,
|
HTTP_GET,
|
||||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { sensor_data(request); }, AuthenticationPredicates::IS_AUTHENTICATED));
|
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { sensor_data(request); }, AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
}
|
}
|
||||||
@@ -341,7 +341,7 @@ void WebDataService::write_analog_sensor(AsyncWebServerRequest * request, JsonVa
|
|||||||
ok = EMSESP::analogsensor_.update(gpio, name, offset, factor, uom, type, deleted);
|
ok = EMSESP::analogsensor_.update(gpio, name, offset, factor, uom, type, deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncWebServerResponse * response = request->beginResponse(ok ? 200 : 400); // bad request
|
AsyncWebServerResponse * response = request->beginResponse(ok ? 200 : 400); // ok or bad request
|
||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,14 +20,14 @@
|
|||||||
#define WebDataService_h
|
#define WebDataService_h
|
||||||
|
|
||||||
// GET
|
// GET
|
||||||
#define CORE_DATA_SERVICE_PATH "/rest/coreData"
|
#define EMSESP_CORE_DATA_SERVICE_PATH "/rest/coreData"
|
||||||
#define DEVICE_DATA_SERVICE_PATH "/rest/deviceData"
|
#define EMSESP_DEVICE_DATA_SERVICE_PATH "/rest/deviceData"
|
||||||
#define SENSOR_DATA_SERVICE_PATH "/rest/sensorData"
|
#define EMSESP_SENSOR_DATA_SERVICE_PATH "/rest/sensorData"
|
||||||
|
|
||||||
// POST
|
// POST
|
||||||
#define WRITE_DEVICE_VALUE_SERVICE_PATH "/rest/writeDeviceValue"
|
#define EMSESP_WRITE_DEVICE_VALUE_SERVICE_PATH "/rest/writeDeviceValue"
|
||||||
#define WRITE_TEMPERATURE_SENSOR_SERVICE_PATH "/rest/writeTemperatureSensor"
|
#define EMSESP_WRITE_TEMPERATURE_SENSOR_SERVICE_PATH "/rest/writeTemperatureSensor"
|
||||||
#define WRITE_ANALOG_SENSOR_SERVICE_PATH "/rest/writeAnalogSensor"
|
#define EMSESP_WRITE_ANALOG_SENSOR_SERVICE_PATH "/rest/writeAnalogSensor"
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
|
|||||||
@@ -21,12 +21,12 @@
|
|||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
WebLogService::WebLogService(AsyncWebServer * server, SecurityManager * securityManager)
|
WebLogService::WebLogService(AsyncWebServer * server, SecurityManager * securityManager)
|
||||||
: events_(EVENT_SOURCE_LOG_PATH) {
|
: events_(EMSESP_EVENT_SOURCE_LOG_PATH) {
|
||||||
// get & set settings
|
// get & set settings
|
||||||
server->on(LOG_SETTINGS_PATH, [this](AsyncWebServerRequest * request, JsonVariant json) { getSetValues(request, json); });
|
server->on(EMSESP_LOG_SETTINGS_PATH, [this](AsyncWebServerRequest * request, JsonVariant json) { getSetValues(request, json); });
|
||||||
|
|
||||||
// for bring back the whole log - is a command, hence a POST
|
// for bring back the whole log - is a command, hence a POST
|
||||||
server->on(FETCH_LOG_PATH, HTTP_POST, [this](AsyncWebServerRequest * request) { fetchLog(request); });
|
server->on(EMSESP_FETCH_LOG_PATH, HTTP_POST, [this](AsyncWebServerRequest * request) { fetchLog(request); });
|
||||||
|
|
||||||
// events_.setFilter(securityManager->filterRequest(AuthenticationPredicates::IS_ADMIN));
|
// events_.setFilter(securityManager->filterRequest(AuthenticationPredicates::IS_ADMIN));
|
||||||
server->addHandler(&events_);
|
server->addHandler(&events_);
|
||||||
|
|||||||
@@ -19,9 +19,9 @@
|
|||||||
#ifndef WebLogService_h
|
#ifndef WebLogService_h
|
||||||
#define WebLogService_h
|
#define WebLogService_h
|
||||||
|
|
||||||
#define EVENT_SOURCE_LOG_PATH "/es/log"
|
#define EMSESP_EVENT_SOURCE_LOG_PATH "/es/log"
|
||||||
#define FETCH_LOG_PATH "/rest/fetchLog"
|
#define EMSESP_FETCH_LOG_PATH "/rest/fetchLog"
|
||||||
#define LOG_SETTINGS_PATH "/rest/logSettings"
|
#define EMSESP_LOG_SETTINGS_PATH "/rest/logSettings"
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ namespace emsesp {
|
|||||||
WebSchedulerService::WebSchedulerService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
WebSchedulerService::WebSchedulerService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
||||||
: _httpEndpoint(WebScheduler::read, WebScheduler::update, this, server, EMSESP_SCHEDULER_SERVICE_PATH, securityManager, AuthenticationPredicates::IS_AUTHENTICATED)
|
: _httpEndpoint(WebScheduler::read, WebScheduler::update, this, server, EMSESP_SCHEDULER_SERVICE_PATH, securityManager, AuthenticationPredicates::IS_AUTHENTICATED)
|
||||||
, _fsPersistence(WebScheduler::read, WebScheduler::update, this, fs, EMSESP_SCHEDULER_FILE) {
|
, _fsPersistence(WebScheduler::read, WebScheduler::update, this, fs, EMSESP_SCHEDULER_FILE) {
|
||||||
|
server->on(EMSESP_GET_SCHEDULE_PATH,
|
||||||
|
HTTP_GET,
|
||||||
|
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { getSchedule(request); }, AuthenticationPredicates::IS_ADMIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
// load the settings when the service starts
|
// load the settings when the service starts
|
||||||
@@ -610,4 +613,17 @@ void WebSchedulerService::test() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// return schedule entries in a json object
|
||||||
|
void WebSchedulerService::getSchedule(AsyncWebServerRequest * request) {
|
||||||
|
auto * response = new AsyncJsonResponse(false);
|
||||||
|
JsonObject root = response->getRoot();
|
||||||
|
|
||||||
|
root["type"] = "schedule";
|
||||||
|
|
||||||
|
System::extractSettings(EMSESP_SCHEDULER_FILE, "Schedule", root);
|
||||||
|
|
||||||
|
response->setLength();
|
||||||
|
request->send(response);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace emsesp
|
} // namespace emsesp
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#define EMSESP_SCHEDULER_FILE "/config/emsespScheduler.json"
|
#define EMSESP_SCHEDULER_FILE "/config/emsespScheduler.json"
|
||||||
#define EMSESP_SCHEDULER_SERVICE_PATH "/rest/schedule" // GET and POST
|
#define EMSESP_SCHEDULER_SERVICE_PATH "/rest/schedule" // GET and POST
|
||||||
|
#define EMSESP_GET_SCHEDULE_PATH "/rest/getSchedule"
|
||||||
|
|
||||||
// bit flags for the schedule items. Matches those in interface/src/app/main/SchedulerDialog.tsx
|
// bit flags for the schedule items. Matches those in interface/src/app/main/SchedulerDialog.tsx
|
||||||
// 0-127 (0->0x7F) is day schedule
|
// 0-127 (0->0x7F) is day schedule
|
||||||
@@ -90,6 +91,8 @@ class WebSchedulerService : public StatefulService<WebScheduler> {
|
|||||||
HttpEndpoint<WebScheduler> _httpEndpoint;
|
HttpEndpoint<WebScheduler> _httpEndpoint;
|
||||||
FSPersistence<WebScheduler> _fsPersistence;
|
FSPersistence<WebScheduler> _fsPersistence;
|
||||||
|
|
||||||
|
void getSchedule(AsyncWebServerRequest * request);
|
||||||
|
|
||||||
std::list<ScheduleItem> * scheduleItems_; // pointer to the list of schedule events
|
std::list<ScheduleItem> * scheduleItems_; // pointer to the list of schedule events
|
||||||
bool ha_registered_ = false;
|
bool ha_registered_ = false;
|
||||||
std::deque<ScheduleItem *> cmd_changed_;
|
std::deque<ScheduleItem *> cmd_changed_;
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ WebSettingsService::WebSettingsService(AsyncWebServer * server, FS * fs, Securit
|
|||||||
HTTP_GET,
|
HTTP_GET,
|
||||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { board_profile(request); }, AuthenticationPredicates::IS_AUTHENTICATED));
|
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { board_profile(request); }, AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
addUpdateHandler([this] { onUpdate(); }, false);
|
addUpdateHandler([this] { onUpdate(); }, false);
|
||||||
|
|
||||||
|
server->on(EMSESP_GET_SETTINGS_PATH,
|
||||||
|
HTTP_GET,
|
||||||
|
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { getSettings(request); }, AuthenticationPredicates::IS_ADMIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebSettings::read(WebSettings & settings, JsonObject root) {
|
void WebSettings::read(WebSettings & settings, JsonObject root) {
|
||||||
@@ -425,4 +429,25 @@ void WebSettingsService::board_profile(AsyncWebServerRequest * request) {
|
|||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns json with all system settings
|
||||||
|
void WebSettingsService::getSettings(AsyncWebServerRequest * request) {
|
||||||
|
auto * response = new AsyncJsonResponse(false);
|
||||||
|
JsonObject root = response->getRoot();
|
||||||
|
|
||||||
|
root["type"] = "settings";
|
||||||
|
|
||||||
|
JsonObject node = root["System"].to<JsonObject>();
|
||||||
|
node["version"] = EMSESP_APP_VERSION;
|
||||||
|
|
||||||
|
System::extractSettings(NETWORK_SETTINGS_FILE, "Network", root);
|
||||||
|
System::extractSettings(AP_SETTINGS_FILE, "AP", root);
|
||||||
|
System::extractSettings(MQTT_SETTINGS_FILE, "MQTT", root);
|
||||||
|
System::extractSettings(NTP_SETTINGS_FILE, "NTP", root);
|
||||||
|
System::extractSettings(SECURITY_SETTINGS_FILE, "Security", root);
|
||||||
|
System::extractSettings(EMSESP_SETTINGS_FILE, "Settings", root);
|
||||||
|
|
||||||
|
response->setLength();
|
||||||
|
request->send(response);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace emsesp
|
} // namespace emsesp
|
||||||
|
|||||||
@@ -22,8 +22,10 @@
|
|||||||
#include "../default_settings.h"
|
#include "../default_settings.h"
|
||||||
|
|
||||||
#define EMSESP_SETTINGS_FILE "/config/emsespSettings.json"
|
#define EMSESP_SETTINGS_FILE "/config/emsespSettings.json"
|
||||||
|
|
||||||
#define EMSESP_SETTINGS_SERVICE_PATH "/rest/settings"
|
#define EMSESP_SETTINGS_SERVICE_PATH "/rest/settings"
|
||||||
#define EMSESP_BOARD_PROFILE_SERVICE_PATH "/rest/boardProfile"
|
#define EMSESP_BOARD_PROFILE_SERVICE_PATH "/rest/boardProfile"
|
||||||
|
#define EMSESP_GET_SETTINGS_PATH "/rest/getSettings"
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
@@ -134,6 +136,7 @@ class WebSettingsService : public StatefulService<WebSettings> {
|
|||||||
FSPersistence<WebSettings> _fsPersistence;
|
FSPersistence<WebSettings> _fsPersistence;
|
||||||
|
|
||||||
void board_profile(AsyncWebServerRequest * request);
|
void board_profile(AsyncWebServerRequest * request);
|
||||||
|
void getSettings(AsyncWebServerRequest * request);
|
||||||
|
|
||||||
void onUpdate();
|
void onUpdate();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user