Skip to content

Commit

Permalink
avoid possible div-zero
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Sep 29, 2023
1 parent 5bc3bd2 commit 3a1b7ca
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/web/WebStatusService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void WebStatusService::webStatusService(AsyncWebServerRequest * request) {
statJson["f"] = EMSESP::txservice_.telegram_write_fail_count();
statJson["q"] = EMSESP::txservice_.write_quality();

if (EMSESP::temperaturesensor_.sensor_enabled()) {
if (EMSESP::sensor_enabled()) {
statJson = statsJson.createNestedObject();
statJson["id"] = 3;
statJson["s"] = EMSESP::temperaturesensor_.reads();
Expand All @@ -175,16 +175,17 @@ void WebStatusService::webStatusService(AsyncWebServerRequest * request) {
statJson["id"] = 6;
statJson["s"] = WebAPIService::api_count(); // + WebAPIService::api_fails();
statJson["f"] = WebAPIService::api_fails();
statJson["q"] =
WebAPIService::api_count() == 0 ? 100 : 100 - (uint8_t)((100 * WebAPIService::api_fails()) / (WebAPIService::api_count() + WebAPIService::api_fails()));
statJson["q"] = (WebAPIService::api_count() + WebAPIService::api_fails()) == 0
? 100
: 100 - (uint8_t)((100 * WebAPIService::api_fails()) / (WebAPIService::api_count() + WebAPIService::api_fails()));

#ifndef EMSESP_STANDALONE
if (EMSESP::system_.syslog_enabled()) {
statJson = statsJson.createNestedObject();
statJson["id"] = 7;
statJson["s"] = EMSESP::system_.syslog_count();
statJson["f"] = EMSESP::system_.syslog_fails();
statJson["q"] = EMSESP::system_.syslog_count() == 0
statJson["q"] = (EMSESP::system_.syslog_count() + EMSESP::system_.syslog_fails()) == 0
? 100
: 100 - (uint8_t)((100 * EMSESP::system_.syslog_fails()) / (EMSESP::system_.syslog_count() + EMSESP::system_.syslog_fails()));
}
Expand Down

0 comments on commit 3a1b7ca

Please sign in to comment.