avoid deprecated containsKey() method of ArduinoJson 7.2.0

This commit is contained in:
Bernhard Kirchen 2024-09-21 22:09:42 +02:00
parent 38726b99ab
commit 97f95f8a11
5 changed files with 19 additions and 19 deletions

View File

@ -83,7 +83,7 @@ void WebApiHuaweiClass::onPost(AsyncWebServerRequest* request)
auto& retMsg = response->getRoot(); auto& retMsg = response->getRoot();
if (root.containsKey("online")) { if (root["online"].is<bool>()) {
online = root["online"].as<bool>(); online = root["online"].as<bool>();
if (online) { if (online) {
minimal_voltage = HUAWEI_MINIMAL_ONLINE_VOLTAGE; minimal_voltage = HUAWEI_MINIMAL_ONLINE_VOLTAGE;
@ -98,7 +98,7 @@ void WebApiHuaweiClass::onPost(AsyncWebServerRequest* request)
return; return;
} }
if (root.containsKey("voltage_valid")) { if (root["voltage_valid"].is<bool>()) {
if (root["voltage_valid"].as<bool>()) { if (root["voltage_valid"].as<bool>()) {
if (root["voltage"].as<float>() < minimal_voltage || root["voltage"].as<float>() > 58) { 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 !"; 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_valid"].as<bool>()) {
if (root["current"].as<float>() < 0 || root["current"].as<float>() > 60) { if (root["current"].as<float>() < 0 || root["current"].as<float>() > 60) {
retMsg["message"] = "current must be in range between 0 and 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(); auto& retMsg = response->getRoot();
if (!(root.containsKey("enabled")) || if (!(root["enabled"].is<bool>()) ||
!(root.containsKey("can_controller_frequency")) || !(root["can_controller_frequency"].is<uint32_t>()) ||
!(root.containsKey("auto_power_enabled")) || !(root["auto_power_enabled"].is<bool>()) ||
!(root.containsKey("emergency_charge_enabled")) || !(root["emergency_charge_enabled"].is<bool>()) ||
!(root.containsKey("voltage_limit")) || !(root["voltage_limit"].is<float>()) ||
!(root.containsKey("lower_power_limit")) || !(root["lower_power_limit"].is<float>()) ||
!(root.containsKey("upper_power_limit"))) { !(root["upper_power_limit"].is<float>())) {
retMsg["message"] = "Values are missing!"; retMsg["message"] = "Values are missing!";
retMsg["code"] = WebApiError::GenericValueMissing; retMsg["code"] = WebApiError::GenericValueMissing;
response->setLength(); response->setLength();

View File

@ -63,7 +63,7 @@ void WebApiBatteryClass::onAdminPost(AsyncWebServerRequest* request)
auto& retMsg = response->getRoot(); 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["message"] = "Values are missing!";
retMsg["code"] = WebApiError::GenericValueMissing; retMsg["code"] = WebApiError::GenericValueMissing;
WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__); WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);

View File

@ -137,7 +137,7 @@ void WebApiPowerLimiterClass::onAdminPost(AsyncWebServerRequest* request)
// anyways to always include the keys accessed below. if we wanted to // anyways to always include the keys accessed below. if we wanted to
// support a simpler API, like only sending the "enabled" key which only // support a simpler API, like only sending the "enabled" key which only
// changes that key, we need to refactor all of the code below. // 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["message"] = "Values are missing!";
retMsg["code"] = WebApiError::GenericValueMissing; retMsg["code"] = WebApiError::GenericValueMissing;
response->setLength(); response->setLength();

View File

@ -82,7 +82,7 @@ void WebApiPowerMeterClass::onAdminPost(AsyncWebServerRequest* request)
auto& retMsg = response->getRoot(); 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!"; retMsg["message"] = "Values are missing!";
response->setLength(); response->setLength();
request->send(response); request->send(response);
@ -90,7 +90,7 @@ void WebApiPowerMeterClass::onAdminPost(AsyncWebServerRequest* request)
} }
auto checkHttpConfig = [&](JsonObject const& cfg) -> bool { 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("http://")
&& !cfg["url"].as<String>().startsWith("https://"))) { && !cfg["url"].as<String>().startsWith("https://"))) {
retMsg["message"] = "URL must either start with http:// or https://!"; retMsg["message"] = "URL must either start with http:// or https://!";
@ -107,7 +107,7 @@ void WebApiPowerMeterClass::onAdminPost(AsyncWebServerRequest* request)
return false; return false;
} }
if (!cfg.containsKey("timeout") if (!cfg["timeout"].is<uint16_t>()
|| cfg["timeout"].as<uint16_t>() <= 0) { || cfg["timeout"].as<uint16_t>() <= 0) {
retMsg["message"] = "Timeout must be greater than 0 ms!"; retMsg["message"] = "Timeout must be greater than 0 ms!";
response->setLength(); 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) { || valueConfig["json_path"].as<String>().length() == 0) {
retMsg["message"] = "Json path must not be empty!"; retMsg["message"] = "Json path must not be empty!";
response->setLength(); response->setLength();

View File

@ -73,9 +73,9 @@ void WebApiVedirectClass::onVedirectAdminPost(AsyncWebServerRequest* request)
auto& retMsg = response->getRoot(); auto& retMsg = response->getRoot();
if (!root.containsKey("vedirect_enabled") || if (!root["vedirect_enabled"].is<bool>() ||
!root.containsKey("verbose_logging") || !root["verbose_logging"].is<bool>() ||
!root.containsKey("vedirect_updatesonly") ) { !root["vedirect_updatesonly"].is<bool>() ) {
retMsg["message"] = "Values are missing!"; retMsg["message"] = "Values are missing!";
retMsg["code"] = WebApiError::GenericValueMissing; retMsg["code"] = WebApiError::GenericValueMissing;
response->setLength(); response->setLength();