Skip to content

Commit

Permalink
Feature: Allow reset of radio statistics via WebApp
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnobody committed Sep 25, 2024
1 parent d3903d8 commit 9b56559
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/WebApi_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum WebApiError {
InverterChanged,
InverterDeleted,
InverterOrdered,
InverterStatsResetted,

LimitBase = 5000,
LimitSerialZero,
Expand Down
1 change: 1 addition & 0 deletions include/WebApi_inverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ class WebApiInverterClass {
void onInverterEdit(AsyncWebServerRequest* request);
void onInverterDelete(AsyncWebServerRequest* request);
void onInverterOrder(AsyncWebServerRequest* request);
void onInverterStatReset(AsyncWebServerRequest* request);
};
22 changes: 22 additions & 0 deletions src/WebApi_inverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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__);
}
4 changes: 3 additions & 1 deletion webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 23 additions & 0 deletions webapp/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,20 @@
</tr>
</tbody>
</table>
<button
:disabled="!isLogged || performRadioStatsReset"
type="button"
class="btn btn-danger"
@click="onResetRadioStats(inverter.serial)"
>
<template v-if="!performRadioStatsReset">
{{ $t('home.StatsReset') }}
</template>
<template v-else>
<span class="spinner-border spinner-border-sm" aria-hidden="true"></span>
<span role="status"> {{ $t('home.StatsResetting') }}</span>
</template>
</button>
</div>
</div>
</div>
Expand Down Expand Up @@ -551,6 +565,7 @@ export default defineComponent({
alertMessageLimit: '',
alertTypeLimit: 'info',
showAlertLimit: false,
performRadioStatsReset: false,
powerSettingView: {} as bootstrap.Modal,
powerSettingSerial: '',
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 9b56559

Please sign in to comment.