Use auto keyword and references more often (onBattery)
This commit is contained in:
parent
67e2134f7e
commit
210fce67ce
@ -8,7 +8,7 @@ class WebApiHuaweiClass {
|
|||||||
public:
|
public:
|
||||||
void init(AsyncWebServer& server);
|
void init(AsyncWebServer& server);
|
||||||
void loop();
|
void loop();
|
||||||
void getJsonData(JsonObject& root);
|
void getJsonData(JsonVariant& root);
|
||||||
private:
|
private:
|
||||||
void onStatus(AsyncWebServerRequest* request);
|
void onStatus(AsyncWebServerRequest* request);
|
||||||
void onAdminGet(AsyncWebServerRequest* request);
|
void onAdminGet(AsyncWebServerRequest* request);
|
||||||
|
|||||||
@ -28,7 +28,7 @@ void WebApiHuaweiClass::loop()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebApiHuaweiClass::getJsonData(JsonObject& root) {
|
void WebApiHuaweiClass::getJsonData(JsonVariant& root) {
|
||||||
const RectifierParameters_t * rp = HuaweiCan.get();
|
const RectifierParameters_t * rp = HuaweiCan.get();
|
||||||
|
|
||||||
root["data_age"] = (millis() - HuaweiCan.getLastUpdate()) / 1000;
|
root["data_age"] = (millis() - HuaweiCan.getLastUpdate()) / 1000;
|
||||||
@ -62,7 +62,7 @@ void WebApiHuaweiClass::onStatus(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject root = response->getRoot();
|
auto& root = response->getRoot();
|
||||||
getJsonData(root);
|
getJsonData(root);
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
@ -76,7 +76,7 @@ void WebApiHuaweiClass::onPost(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject retMsg = response->getRoot();
|
auto& retMsg = response->getRoot();
|
||||||
retMsg["type"] = "warning";
|
retMsg["type"] = "warning";
|
||||||
|
|
||||||
if (!request->hasParam("data", true)) {
|
if (!request->hasParam("data", true)) {
|
||||||
@ -186,7 +186,7 @@ void WebApiHuaweiClass::onAdminGet(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject root = response->getRoot();
|
auto& root = response->getRoot();
|
||||||
const CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
root["enabled"] = config.Huawei.Enabled;
|
root["enabled"] = config.Huawei.Enabled;
|
||||||
@ -208,7 +208,7 @@ void WebApiHuaweiClass::onAdminPost(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject retMsg = response->getRoot();
|
auto& retMsg = response->getRoot();
|
||||||
retMsg["type"] = "warning";
|
retMsg["type"] = "warning";
|
||||||
|
|
||||||
if (!request->hasParam("data", true)) {
|
if (!request->hasParam("data", true)) {
|
||||||
|
|||||||
@ -35,7 +35,7 @@ void WebApiBatteryClass::onStatus(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject root = response->getRoot();
|
auto& root = response->getRoot();
|
||||||
const CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
root["enabled"] = config.Battery.Enabled;
|
root["enabled"] = config.Battery.Enabled;
|
||||||
@ -61,7 +61,7 @@ void WebApiBatteryClass::onAdminPost(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject retMsg = response->getRoot();
|
auto& retMsg = response->getRoot();
|
||||||
retMsg["type"] = "warning";
|
retMsg["type"] = "warning";
|
||||||
|
|
||||||
if (!request->hasParam("data", true)) {
|
if (!request->hasParam("data", true)) {
|
||||||
|
|||||||
@ -34,7 +34,7 @@ void WebApiPowerLimiterClass::loop()
|
|||||||
void WebApiPowerLimiterClass::onStatus(AsyncWebServerRequest* request)
|
void WebApiPowerLimiterClass::onStatus(AsyncWebServerRequest* request)
|
||||||
{
|
{
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject root = response->getRoot();
|
auto& root = response->getRoot();
|
||||||
const CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
root["enabled"] = config.PowerLimiter.Enabled;
|
root["enabled"] = config.PowerLimiter.Enabled;
|
||||||
@ -79,7 +79,7 @@ void WebApiPowerLimiterClass::onAdminPost(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject retMsg = response->getRoot();
|
auto& retMsg = response->getRoot();
|
||||||
retMsg["type"] = "warning";
|
retMsg["type"] = "warning";
|
||||||
|
|
||||||
if (!request->hasParam("data", true)) {
|
if (!request->hasParam("data", true)) {
|
||||||
|
|||||||
@ -35,7 +35,7 @@ void WebApiPowerMeterClass::loop()
|
|||||||
void WebApiPowerMeterClass::onStatus(AsyncWebServerRequest* request)
|
void WebApiPowerMeterClass::onStatus(AsyncWebServerRequest* request)
|
||||||
{
|
{
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse(false, 2048);
|
AsyncJsonResponse* response = new AsyncJsonResponse(false, 2048);
|
||||||
JsonObject root = response->getRoot();
|
auto& root = response->getRoot();
|
||||||
const CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
root["enabled"] = config.PowerMeter.Enabled;
|
root["enabled"] = config.PowerMeter.Enabled;
|
||||||
@ -86,7 +86,7 @@ void WebApiPowerMeterClass::onAdminPost(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject retMsg = response->getRoot();
|
auto& retMsg = response->getRoot();
|
||||||
retMsg["type"] = "warning";
|
retMsg["type"] = "warning";
|
||||||
|
|
||||||
if (!request->hasParam("data", true)) {
|
if (!request->hasParam("data", true)) {
|
||||||
@ -216,7 +216,7 @@ void WebApiPowerMeterClass::onTestHttpRequest(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncJsonResponse* asyncJsonResponse = new AsyncJsonResponse();
|
AsyncJsonResponse* asyncJsonResponse = new AsyncJsonResponse();
|
||||||
JsonObject retMsg = asyncJsonResponse->getRoot();
|
auto& retMsg = asyncJsonResponse->getRoot();
|
||||||
retMsg["type"] = "warning";
|
retMsg["type"] = "warning";
|
||||||
|
|
||||||
if (!request->hasParam("data", true)) {
|
if (!request->hasParam("data", true)) {
|
||||||
|
|||||||
@ -33,7 +33,7 @@ void WebApiVedirectClass::onVedirectStatus(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject root = response->getRoot();
|
auto& root = response->getRoot();
|
||||||
const CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
root["vedirect_enabled"] = config.Vedirect.Enabled;
|
root["vedirect_enabled"] = config.Vedirect.Enabled;
|
||||||
@ -51,7 +51,7 @@ void WebApiVedirectClass::onVedirectAdminGet(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject root = response->getRoot();
|
auto& root = response->getRoot();
|
||||||
const CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
root["vedirect_enabled"] = config.Vedirect.Enabled;
|
root["vedirect_enabled"] = config.Vedirect.Enabled;
|
||||||
@ -69,7 +69,7 @@ void WebApiVedirectClass::onVedirectAdminPost(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject retMsg = response->getRoot();
|
auto& retMsg = response->getRoot();
|
||||||
retMsg["type"] = "warning";
|
retMsg["type"] = "warning";
|
||||||
|
|
||||||
if (!request->hasParam("data", true)) {
|
if (!request->hasParam("data", true)) {
|
||||||
|
|||||||
@ -123,7 +123,7 @@ void WebApiWsHuaweiLiveClass::onLivedataStatus(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse(false, 1024U);
|
AsyncJsonResponse* response = new AsyncJsonResponse(false, 1024U);
|
||||||
JsonVariant root = response->getRoot().as<JsonVariant>();
|
auto& root = response->getRoot();
|
||||||
generateJsonResponse(root);
|
generateJsonResponse(root);
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
|
|||||||
@ -92,7 +92,7 @@ void WebApiWsBatteryLiveClass::onLivedataStatus(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse(false, _responseSize);
|
AsyncJsonResponse* response = new AsyncJsonResponse(false, _responseSize);
|
||||||
JsonVariant root = response->getRoot().as<JsonVariant>();
|
auto& root = response->getRoot();
|
||||||
generateJsonResponse(root);
|
generateJsonResponse(root);
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
|
|||||||
@ -169,7 +169,7 @@ void WebApiWsVedirectLiveClass::onLivedataStatus(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse(false, _responseSize);
|
AsyncJsonResponse* response = new AsyncJsonResponse(false, _responseSize);
|
||||||
JsonVariant root = response->getRoot();
|
auto& root = response->getRoot();
|
||||||
|
|
||||||
generateJsonResponse(root);
|
generateJsonResponse(root);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user