From 9b565596d59e908a7fbb8eb2037c2b0bc293ac90 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Wed, 25 Sep 2024 20:18:36 +0200 Subject: [PATCH] Feature: Allow reset of radio statistics via WebApp --- include/WebApi_errors.h | 1 + include/WebApi_inverter.h | 1 + src/WebApi_inverter.cpp | 22 ++++++++++++++++++++++ webapp/src/locales/de.json | 4 +++- webapp/src/locales/en.json | 4 +++- webapp/src/locales/fr.json | 4 +++- webapp/src/views/HomeView.vue | 23 +++++++++++++++++++++++ 7 files changed, 56 insertions(+), 3 deletions(-) diff --git a/include/WebApi_errors.h b/include/WebApi_errors.h index 0da8d3d9f..c4cdaf210 100644 --- a/include/WebApi_errors.h +++ b/include/WebApi_errors.h @@ -32,6 +32,7 @@ enum WebApiError { InverterChanged, InverterDeleted, InverterOrdered, + InverterStatsResetted, LimitBase = 5000, LimitSerialZero, diff --git a/include/WebApi_inverter.h b/include/WebApi_inverter.h index c316622e5..6ba6c5e8e 100644 --- a/include/WebApi_inverter.h +++ b/include/WebApi_inverter.h @@ -14,4 +14,5 @@ class WebApiInverterClass { void onInverterEdit(AsyncWebServerRequest* request); void onInverterDelete(AsyncWebServerRequest* request); void onInverterOrder(AsyncWebServerRequest* request); + void onInverterStatReset(AsyncWebServerRequest* request); }; diff --git a/src/WebApi_inverter.cpp b/src/WebApi_inverter.cpp index 4e8fc53a3..79c8a8e9c 100644 --- a/src/WebApi_inverter.cpp +++ b/src/WebApi_inverter.cpp @@ -21,6 +21,7 @@ void WebApiInverterClass::init(AsyncWebServer& server, Scheduler& scheduler) server.on("/api/inverter/edit", HTTP_POST, std::bind(&WebApiInverterClass::onInverterEdit, this, _1)); server.on("/api/inverter/del", HTTP_POST, std::bind(&WebApiInverterClass::onInverterDelete, this, _1)); server.on("/api/inverter/order", HTTP_POST, std::bind(&WebApiInverterClass::onInverterOrder, this, _1)); + server.on("/api/inverter/stats_reset", HTTP_GET, std::bind(&WebApiInverterClass::onInverterStatReset, this, _1)); } void WebApiInverterClass::onInverterList(AsyncWebServerRequest* request) @@ -349,3 +350,24 @@ void WebApiInverterClass::onInverterOrder(AsyncWebServerRequest* request) WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__); } + +void WebApiInverterClass::onInverterStatReset(AsyncWebServerRequest* request) +{ + if (!WebApi.checkCredentials(request)) { + return; + } + + AsyncJsonResponse* response = new AsyncJsonResponse(); + auto retMsg = response->getRoot(); + auto serial = WebApi.parseSerialFromRequest(request); + auto inv = Hoymiles.getInverterBySerial(serial); + + if (inv != nullptr) { + inv->resetRadioStats(); + retMsg["type"] = "success"; + retMsg["message"] = "Stats resetted"; + retMsg["code"] = WebApiError::InverterStatsResetted; + } + + WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__); +} diff --git a/webapp/src/locales/de.json b/webapp/src/locales/de.json index 93610890f..995f6ec7c 100644 --- a/webapp/src/locales/de.json +++ b/webapp/src/locales/de.json @@ -148,7 +148,9 @@ "RxFailNothing": "Empfang Fehler: Nichts empfangen", "RxFailPartial": "Empfang Fehler: Teilweise empfangen", "RxFailCorrupt": "Empfang Fehler: Beschädigt empfangen", - "TxReRequest": "Gesendete Fragment Wiederanforderungen" + "TxReRequest": "Gesendete Fragment Wiederanforderungen", + "StatsReset": "Statistiken zurücksetzen", + "StatsResetting": "Zurücksetzen..." }, "eventlog": { "Start": "Beginn", diff --git a/webapp/src/locales/en.json b/webapp/src/locales/en.json index 34be62f42..cf3c74f07 100644 --- a/webapp/src/locales/en.json +++ b/webapp/src/locales/en.json @@ -148,7 +148,9 @@ "RxFailNothing": "RX Fail: Receive Nothing", "RxFailPartial": "RX Fail: Receive Partial", "RxFailCorrupt": "RX Fail: Receive Corrupt", - "TxReRequest": "TX Re-Request Fragment" + "TxReRequest": "TX Re-Request Fragment", + "StatsReset": "Reset Statistics", + "StatsResetting": "Resetting..." }, "eventlog": { "Start": "Start", diff --git a/webapp/src/locales/fr.json b/webapp/src/locales/fr.json index d9d148dae..fcb22a19c 100644 --- a/webapp/src/locales/fr.json +++ b/webapp/src/locales/fr.json @@ -148,7 +148,9 @@ "RxFailNothing": "RX Fail: Receive Nothing", "RxFailPartial": "RX Fail: Receive Partial", "RxFailCorrupt": "RX Fail: Receive Corrupt", - "TxReRequest": "TX Re-Request Fragment" + "TxReRequest": "TX Re-Request Fragment", + "StatsReset": "Reset Statistics", + "StatsResetting": "Resetting..." }, "eventlog": { "Start": "Départ", diff --git a/webapp/src/views/HomeView.vue b/webapp/src/views/HomeView.vue index 7082e17c9..95c910315 100644 --- a/webapp/src/views/HomeView.vue +++ b/webapp/src/views/HomeView.vue @@ -293,6 +293,20 @@ + @@ -551,6 +565,7 @@ export default defineComponent({ alertMessageLimit: '', alertTypeLimit: 'info', showAlertLimit: false, + performRadioStatsReset: false, powerSettingView: {} as bootstrap.Modal, powerSettingSerial: '', @@ -780,6 +795,14 @@ export default defineComponent({ this.limitSettingView.show(); }, + onResetRadioStats(serial: string) { + this.performRadioStatsReset = true; + fetch('/api/inverter/stats_reset?inv=' + serial, { headers: authHeader() }) + .then((response) => handleResponse(response, this.$emitter, this.$router)) + .then(() => { + this.performRadioStatsReset = false; + }); + }, onSetLimitSettings(setPersistent: boolean) { this.targetLimitList.limit_type = (setPersistent ? 256 : 0) + this.targetLimitType; const formData = new FormData();