🪄 Formats RestartService

This commit is contained in:
Rune Harlyk
2024-07-09 20:06:04 +02:00
committed by Rune Harlyk
parent c47a7bc02f
commit 33e1a28223
2 changed files with 9 additions and 16 deletions
+5 -10
View File
@@ -14,23 +14,18 @@
#include <RestartService.h> #include <RestartService.h>
RestartService::RestartService(PsychicHttpServer *server, SecurityManager *securityManager) : _server(server), RestartService::RestartService(PsychicHttpServer *server, SecurityManager *securityManager)
_securityManager(securityManager) : _server(server), _securityManager(securityManager) {}
{
}
void RestartService::begin() void RestartService::begin() {
{ _server->on(RESTART_SERVICE_PATH, HTTP_POST,
_server->on(RESTART_SERVICE_PATH,
HTTP_POST,
_securityManager->wrapRequest(std::bind(&RestartService::restart, this, std::placeholders::_1), _securityManager->wrapRequest(std::bind(&RestartService::restart, this, std::placeholders::_1),
AuthenticationPredicates::IS_ADMIN)); AuthenticationPredicates::IS_ADMIN));
ESP_LOGV("RestartService", "Registered POST endpoint: %s", RESTART_SERVICE_PATH); ESP_LOGV("RestartService", "Registered POST endpoint: %s", RESTART_SERVICE_PATH);
} }
esp_err_t RestartService::restart(PsychicRequest *request) esp_err_t RestartService::restart(PsychicRequest *request) {
{
request->reply(200); request->reply(200);
restartNow(); restartNow();
return ESP_OK; return ESP_OK;
+4 -6
View File
@@ -22,21 +22,19 @@
#define RESTART_SERVICE_PATH "/api/restart" #define RESTART_SERVICE_PATH "/api/restart"
class RestartService class RestartService {
{ public:
public:
RestartService(PsychicHttpServer *server, SecurityManager *securityManager); RestartService(PsychicHttpServer *server, SecurityManager *securityManager);
void begin(); void begin();
static void restartNow() static void restartNow() {
{
WiFi.disconnect(true); WiFi.disconnect(true);
delay(500); delay(500);
ESP.restart(); ESP.restart();
} }
private: private:
PsychicHttpServer *_server; PsychicHttpServer *_server;
SecurityManager *_securityManager; SecurityManager *_securityManager;
esp_err_t restart(PsychicRequest *request); esp_err_t restart(PsychicRequest *request);