From 97f95f8a11f88037e270fc1640571a71315437a5 Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Sat, 21 Sep 2024 22:09:42 +0200 Subject: [PATCH] avoid deprecated containsKey() method of ArduinoJson 7.2.0 --- src/WebApi_Huawei.cpp | 20 ++++++++++---------- src/WebApi_battery.cpp | 2 +- src/WebApi_powerlimiter.cpp | 2 +- src/WebApi_powermeter.cpp | 8 ++++---- src/WebApi_vedirect.cpp | 6 +++--- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/WebApi_Huawei.cpp b/src/WebApi_Huawei.cpp index d2f1d2e10..e836842e7 100644 --- a/src/WebApi_Huawei.cpp +++ b/src/WebApi_Huawei.cpp @@ -83,7 +83,7 @@ void WebApiHuaweiClass::onPost(AsyncWebServerRequest* request) auto& retMsg = response->getRoot(); - if (root.containsKey("online")) { + if (root["online"].is()) { online = root["online"].as(); 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()) { if (root["voltage_valid"].as()) { if (root["voltage"].as() < minimal_voltage || root["voltage"].as() > 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()) { if (root["current_valid"].as()) { if (root["current"].as() < 0 || root["current"].as() > 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()) || + !(root["can_controller_frequency"].is()) || + !(root["auto_power_enabled"].is()) || + !(root["emergency_charge_enabled"].is()) || + !(root["voltage_limit"].is()) || + !(root["lower_power_limit"].is()) || + !(root["upper_power_limit"].is())) { retMsg["message"] = "Values are missing!"; retMsg["code"] = WebApiError::GenericValueMissing; response->setLength(); diff --git a/src/WebApi_battery.cpp b/src/WebApi_battery.cpp index 5965caeef..bc3081e9a 100644 --- a/src/WebApi_battery.cpp +++ b/src/WebApi_battery.cpp @@ -63,7 +63,7 @@ void WebApiBatteryClass::onAdminPost(AsyncWebServerRequest* request) auto& retMsg = response->getRoot(); - if (!root.containsKey("enabled") || !root.containsKey("provider")) { + if (!root["enabled"].is() || !root["provider"].is()) { retMsg["message"] = "Values are missing!"; retMsg["code"] = WebApiError::GenericValueMissing; WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__); diff --git a/src/WebApi_powerlimiter.cpp b/src/WebApi_powerlimiter.cpp index adea6105b..89e671d8c 100644 --- a/src/WebApi_powerlimiter.cpp +++ b/src/WebApi_powerlimiter.cpp @@ -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()) { retMsg["message"] = "Values are missing!"; retMsg["code"] = WebApiError::GenericValueMissing; response->setLength(); diff --git a/src/WebApi_powermeter.cpp b/src/WebApi_powermeter.cpp index 59297a0b3..d27fd65d1 100644 --- a/src/WebApi_powermeter.cpp +++ b/src/WebApi_powermeter.cpp @@ -82,7 +82,7 @@ void WebApiPowerMeterClass::onAdminPost(AsyncWebServerRequest* request) auto& retMsg = response->getRoot(); - if (!(root.containsKey("enabled") && root.containsKey("source"))) { + if (!(root["enabled"].is() && root["source"].is())) { 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() || (!cfg["url"].as().startsWith("http://") && !cfg["url"].as().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() || cfg["timeout"].as() <= 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() || valueConfig["json_path"].as().length() == 0) { retMsg["message"] = "Json path must not be empty!"; response->setLength(); diff --git a/src/WebApi_vedirect.cpp b/src/WebApi_vedirect.cpp index 2499ebed3..653ab8ca4 100644 --- a/src/WebApi_vedirect.cpp +++ b/src/WebApi_vedirect.cpp @@ -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() || + !root["verbose_logging"].is() || + !root["vedirect_updatesonly"].is() ) { retMsg["message"] = "Values are missing!"; retMsg["code"] = WebApiError::GenericValueMissing; response->setLength();