avoid deprecated containsKey() method of ArduinoJson 7.2.0
This commit is contained in:
parent
38726b99ab
commit
97f95f8a11
@ -83,7 +83,7 @@ void WebApiHuaweiClass::onPost(AsyncWebServerRequest* request)
|
||||
|
||||
auto& retMsg = response->getRoot();
|
||||
|
||||
if (root.containsKey("online")) {
|
||||
if (root["online"].is<bool>()) {
|
||||
online = root["online"].as<bool>();
|
||||
if (online) {
|
||||
minimal_voltage = HUAWEI_MINIMAL_ONLINE_VOLTAGE;
|
||||
@ -98,7 +98,7 @@ void WebApiHuaweiClass::onPost(AsyncWebServerRequest* request)
|
||||
return;
|
||||
}
|
||||
|
||||
if (root.containsKey("voltage_valid")) {
|
||||
if (root["voltage_valid"].is<bool>()) {
|
||||
if (root["voltage_valid"].as<bool>()) {
|
||||
if (root["voltage"].as<float>() < minimal_voltage || root["voltage"].as<float>() > 58) {
|
||||
retMsg["message"] = "voltage not in range between 42 (online)/48 (offline and 58V !";
|
||||
@ -119,7 +119,7 @@ void WebApiHuaweiClass::onPost(AsyncWebServerRequest* request)
|
||||
}
|
||||
}
|
||||
|
||||
if (root.containsKey("current_valid")) {
|
||||
if (root["current_valid"].is<bool>()) {
|
||||
if (root["current_valid"].as<bool>()) {
|
||||
if (root["current"].as<float>() < 0 || root["current"].as<float>() > 60) {
|
||||
retMsg["message"] = "current must be in range between 0 and 60!";
|
||||
@ -186,13 +186,13 @@ void WebApiHuaweiClass::onAdminPost(AsyncWebServerRequest* request)
|
||||
|
||||
auto& retMsg = response->getRoot();
|
||||
|
||||
if (!(root.containsKey("enabled")) ||
|
||||
!(root.containsKey("can_controller_frequency")) ||
|
||||
!(root.containsKey("auto_power_enabled")) ||
|
||||
!(root.containsKey("emergency_charge_enabled")) ||
|
||||
!(root.containsKey("voltage_limit")) ||
|
||||
!(root.containsKey("lower_power_limit")) ||
|
||||
!(root.containsKey("upper_power_limit"))) {
|
||||
if (!(root["enabled"].is<bool>()) ||
|
||||
!(root["can_controller_frequency"].is<uint32_t>()) ||
|
||||
!(root["auto_power_enabled"].is<bool>()) ||
|
||||
!(root["emergency_charge_enabled"].is<bool>()) ||
|
||||
!(root["voltage_limit"].is<float>()) ||
|
||||
!(root["lower_power_limit"].is<float>()) ||
|
||||
!(root["upper_power_limit"].is<float>())) {
|
||||
retMsg["message"] = "Values are missing!";
|
||||
retMsg["code"] = WebApiError::GenericValueMissing;
|
||||
response->setLength();
|
||||
|
||||
@ -63,7 +63,7 @@ void WebApiBatteryClass::onAdminPost(AsyncWebServerRequest* request)
|
||||
|
||||
auto& retMsg = response->getRoot();
|
||||
|
||||
if (!root.containsKey("enabled") || !root.containsKey("provider")) {
|
||||
if (!root["enabled"].is<bool>() || !root["provider"].is<uint8_t>()) {
|
||||
retMsg["message"] = "Values are missing!";
|
||||
retMsg["code"] = WebApiError::GenericValueMissing;
|
||||
WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
|
||||
|
||||
@ -137,7 +137,7 @@ void WebApiPowerLimiterClass::onAdminPost(AsyncWebServerRequest* request)
|
||||
// anyways to always include the keys accessed below. if we wanted to
|
||||
// support a simpler API, like only sending the "enabled" key which only
|
||||
// changes that key, we need to refactor all of the code below.
|
||||
if (!root.containsKey("enabled")) {
|
||||
if (!root["enabled"].is<bool>()) {
|
||||
retMsg["message"] = "Values are missing!";
|
||||
retMsg["code"] = WebApiError::GenericValueMissing;
|
||||
response->setLength();
|
||||
|
||||
@ -82,7 +82,7 @@ void WebApiPowerMeterClass::onAdminPost(AsyncWebServerRequest* request)
|
||||
|
||||
auto& retMsg = response->getRoot();
|
||||
|
||||
if (!(root.containsKey("enabled") && root.containsKey("source"))) {
|
||||
if (!(root["enabled"].is<bool>() && root["source"].is<uint32_t>())) {
|
||||
retMsg["message"] = "Values are missing!";
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
@ -90,7 +90,7 @@ void WebApiPowerMeterClass::onAdminPost(AsyncWebServerRequest* request)
|
||||
}
|
||||
|
||||
auto checkHttpConfig = [&](JsonObject const& cfg) -> bool {
|
||||
if (!cfg.containsKey("url")
|
||||
if (!cfg["url"].is<String>()
|
||||
|| (!cfg["url"].as<String>().startsWith("http://")
|
||||
&& !cfg["url"].as<String>().startsWith("https://"))) {
|
||||
retMsg["message"] = "URL must either start with http:// or https://!";
|
||||
@ -107,7 +107,7 @@ void WebApiPowerMeterClass::onAdminPost(AsyncWebServerRequest* request)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!cfg.containsKey("timeout")
|
||||
if (!cfg["timeout"].is<uint16_t>()
|
||||
|| cfg["timeout"].as<uint16_t>() <= 0) {
|
||||
retMsg["message"] = "Timeout must be greater than 0 ms!";
|
||||
response->setLength();
|
||||
@ -134,7 +134,7 @@ void WebApiPowerMeterClass::onAdminPost(AsyncWebServerRequest* request)
|
||||
}
|
||||
}
|
||||
|
||||
if (!valueConfig.containsKey("json_path")
|
||||
if (!valueConfig["json_path"].is<String>()
|
||||
|| valueConfig["json_path"].as<String>().length() == 0) {
|
||||
retMsg["message"] = "Json path must not be empty!";
|
||||
response->setLength();
|
||||
|
||||
@ -73,9 +73,9 @@ void WebApiVedirectClass::onVedirectAdminPost(AsyncWebServerRequest* request)
|
||||
|
||||
auto& retMsg = response->getRoot();
|
||||
|
||||
if (!root.containsKey("vedirect_enabled") ||
|
||||
!root.containsKey("verbose_logging") ||
|
||||
!root.containsKey("vedirect_updatesonly") ) {
|
||||
if (!root["vedirect_enabled"].is<bool>() ||
|
||||
!root["verbose_logging"].is<bool>() ||
|
||||
!root["vedirect_updatesonly"].is<bool>() ) {
|
||||
retMsg["message"] = "Values are missing!";
|
||||
retMsg["code"] = WebApiError::GenericValueMissing;
|
||||
response->setLength();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user