Use auto keyword and references more often (onBattery)

This commit is contained in:
helgeerbe 2024-01-06 22:10:07 +01:00
parent 67e2134f7e
commit 210fce67ce
9 changed files with 19 additions and 19 deletions

View File

@ -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);

View File

@ -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;
@ -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();
@ -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)) {
@ -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;
@ -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)) {

View File

@ -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;
@ -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)) {

View File

@ -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;
@ -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)) {

View File

@ -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;
@ -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)) {
@ -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)) {

View File

@ -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;
@ -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;
@ -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)) {

View File

@ -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();

View File

@ -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();

View File

@ -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);