Skip to content

Commit

Permalink
Use auto keyword and references more often (onBattery)
Browse files Browse the repository at this point in the history
  • Loading branch information
helgeerbe committed Jan 6, 2024
1 parent 67e2134 commit 210fce6
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion include/WebApi_Huawei.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class WebApiHuaweiClass {
public:
void init(AsyncWebServer& server);
void loop();
void getJsonData(JsonObject& root);
void getJsonData(JsonVariant& root);
private:
void onStatus(AsyncWebServerRequest* request);
void onAdminGet(AsyncWebServerRequest* request);
Expand Down
10 changes: 5 additions & 5 deletions src/WebApi_Huawei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void WebApiHuaweiClass::loop()
{
}

void WebApiHuaweiClass::getJsonData(JsonObject& root) {
void WebApiHuaweiClass::getJsonData(JsonVariant& root) {
const RectifierParameters_t * rp = HuaweiCan.get();

root["data_age"] = (millis() - HuaweiCan.getLastUpdate()) / 1000;
Expand Down Expand Up @@ -62,7 +62,7 @@ void WebApiHuaweiClass::onStatus(AsyncWebServerRequest* request)
}

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject root = response->getRoot();
auto& root = response->getRoot();
getJsonData(root);

response->setLength();
Expand All @@ -76,7 +76,7 @@ void WebApiHuaweiClass::onPost(AsyncWebServerRequest* request)
}

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject retMsg = response->getRoot();
auto& retMsg = response->getRoot();
retMsg["type"] = "warning";

if (!request->hasParam("data", true)) {
Expand Down Expand Up @@ -186,7 +186,7 @@ void WebApiHuaweiClass::onAdminGet(AsyncWebServerRequest* request)
}

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject root = response->getRoot();
auto& root = response->getRoot();
const CONFIG_T& config = Configuration.get();

root["enabled"] = config.Huawei.Enabled;
Expand All @@ -208,7 +208,7 @@ void WebApiHuaweiClass::onAdminPost(AsyncWebServerRequest* request)
}

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject retMsg = response->getRoot();
auto& retMsg = response->getRoot();
retMsg["type"] = "warning";

if (!request->hasParam("data", true)) {
Expand Down
4 changes: 2 additions & 2 deletions src/WebApi_battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void WebApiBatteryClass::onStatus(AsyncWebServerRequest* request)
}

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject root = response->getRoot();
auto& root = response->getRoot();
const CONFIG_T& config = Configuration.get();

root["enabled"] = config.Battery.Enabled;
Expand All @@ -61,7 +61,7 @@ void WebApiBatteryClass::onAdminPost(AsyncWebServerRequest* request)
}

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject retMsg = response->getRoot();
auto& retMsg = response->getRoot();
retMsg["type"] = "warning";

if (!request->hasParam("data", true)) {
Expand Down
4 changes: 2 additions & 2 deletions src/WebApi_powerlimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void WebApiPowerLimiterClass::loop()
void WebApiPowerLimiterClass::onStatus(AsyncWebServerRequest* request)
{
AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject root = response->getRoot();
auto& root = response->getRoot();
const CONFIG_T& config = Configuration.get();

root["enabled"] = config.PowerLimiter.Enabled;
Expand Down Expand Up @@ -79,7 +79,7 @@ void WebApiPowerLimiterClass::onAdminPost(AsyncWebServerRequest* request)
}

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject retMsg = response->getRoot();
auto& retMsg = response->getRoot();
retMsg["type"] = "warning";

if (!request->hasParam("data", true)) {
Expand Down
6 changes: 3 additions & 3 deletions src/WebApi_powermeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void WebApiPowerMeterClass::loop()
void WebApiPowerMeterClass::onStatus(AsyncWebServerRequest* request)
{
AsyncJsonResponse* response = new AsyncJsonResponse(false, 2048);
JsonObject root = response->getRoot();
auto& root = response->getRoot();
const CONFIG_T& config = Configuration.get();

root["enabled"] = config.PowerMeter.Enabled;
Expand Down Expand Up @@ -86,7 +86,7 @@ void WebApiPowerMeterClass::onAdminPost(AsyncWebServerRequest* request)
}

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject retMsg = response->getRoot();
auto& retMsg = response->getRoot();
retMsg["type"] = "warning";

if (!request->hasParam("data", true)) {
Expand Down Expand Up @@ -216,7 +216,7 @@ void WebApiPowerMeterClass::onTestHttpRequest(AsyncWebServerRequest* request)
}

AsyncJsonResponse* asyncJsonResponse = new AsyncJsonResponse();
JsonObject retMsg = asyncJsonResponse->getRoot();
auto& retMsg = asyncJsonResponse->getRoot();
retMsg["type"] = "warning";

if (!request->hasParam("data", true)) {
Expand Down
6 changes: 3 additions & 3 deletions src/WebApi_vedirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void WebApiVedirectClass::onVedirectStatus(AsyncWebServerRequest* request)
}

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject root = response->getRoot();
auto& root = response->getRoot();
const CONFIG_T& config = Configuration.get();

root["vedirect_enabled"] = config.Vedirect.Enabled;
Expand All @@ -51,7 +51,7 @@ void WebApiVedirectClass::onVedirectAdminGet(AsyncWebServerRequest* request)
}

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject root = response->getRoot();
auto& root = response->getRoot();
const CONFIG_T& config = Configuration.get();

root["vedirect_enabled"] = config.Vedirect.Enabled;
Expand All @@ -69,7 +69,7 @@ void WebApiVedirectClass::onVedirectAdminPost(AsyncWebServerRequest* request)
}

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject retMsg = response->getRoot();
auto& retMsg = response->getRoot();
retMsg["type"] = "warning";

if (!request->hasParam("data", true)) {
Expand Down
2 changes: 1 addition & 1 deletion src/WebApi_ws_Huawei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void WebApiWsHuaweiLiveClass::onLivedataStatus(AsyncWebServerRequest* request)
}
try {
AsyncJsonResponse* response = new AsyncJsonResponse(false, 1024U);
JsonVariant root = response->getRoot().as<JsonVariant>();
auto& root = response->getRoot();
generateJsonResponse(root);

response->setLength();
Expand Down
2 changes: 1 addition & 1 deletion src/WebApi_ws_battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void WebApiWsBatteryLiveClass::onLivedataStatus(AsyncWebServerRequest* request)
}
try {
AsyncJsonResponse* response = new AsyncJsonResponse(false, _responseSize);
JsonVariant root = response->getRoot().as<JsonVariant>();
auto& root = response->getRoot();
generateJsonResponse(root);

response->setLength();
Expand Down
2 changes: 1 addition & 1 deletion src/WebApi_ws_vedirect_live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void WebApiWsVedirectLiveClass::onLivedataStatus(AsyncWebServerRequest* request)
}
try {
AsyncJsonResponse* response = new AsyncJsonResponse(false, _responseSize);
JsonVariant root = response->getRoot();
auto& root = response->getRoot();

generateJsonResponse(root);

Expand Down

0 comments on commit 210fce6

Please sign in to comment.