Skip to content

Commit

Permalink
Merge pull request #746 from SignalK/arduinojson_deprecations
Browse files Browse the repository at this point in the history
Fix ArduinoJson deprecations
  • Loading branch information
mairas authored Sep 26, 2024
2 parents 088528a + dbed98f commit 8a8884b
Show file tree
Hide file tree
Showing 31 changed files with 58 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/sensesp.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#ifndef CORE_DEBUG_LEVEL
#error \
"SensESP v3 requires CORE_DEBUG_LEVEL to be defined. See https://signalk.org/SensESP/pages/migration/."
"SensESP v3 requires CORE_DEBUG_LEVEL to be defined. See https:\/\/signalk.org/SensESP/pages/migration/."
#endif

namespace sensesp {
Expand Down
6 changes: 3 additions & 3 deletions src/sensesp/net/http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ class HTTPServer : public Configurable {
}

virtual bool set_configuration(const JsonObject& config) override {
if (config.containsKey("auth_required")) {
if (config["auth_required"].is<bool>()) {
auth_required_ = config["auth_required"];
}
if (config.containsKey("username")) {
if (config["username"].is<String>()) {
username_ = config["username"].as<String>();
}
if (config.containsKey("password")) {
if (config["password"].is<String>()) {
password_ = config["password"].as<String>();
}
return true;
Expand Down
10 changes: 5 additions & 5 deletions src/sensesp/net/networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,16 @@ void Networking::get_configuration(JsonObject& root) {
}

bool Networking::set_configuration(const JsonObject& config) {
if (config.containsKey("hostname")) {
if (config["hostname"].is<String>()) {
// deal with the legacy Json format
String hostname = config["hostname"].as<String>();
SensESPBaseApp::get()->get_hostname_observable()->set(hostname);

if (config.containsKey("ssid")) {
if (config["ssid"].is<String>()) {
String ssid = config["ssid"].as<String>();
String password = config["password"].as<String>();

if (config.containsKey("ap_mode")) {
if (config["ap_mode"].is<String>()) {
bool ap_mode;
if (config["ap_mode"].as<String>() == "Access Point" ||
config["ap_mode"].as<String>() == "Hotspot") {
Expand All @@ -242,12 +242,12 @@ bool Networking::set_configuration(const JsonObject& config) {
}
} else {
// Either an empty config or a new-style config
if (config.containsKey("apSettings")) {
if (config["apSettings"].is<JsonVariant>()) {
ap_settings_ = AccessPointSettings::from_json(config["apSettings"]);
} else {
ap_settings_ = AccessPointSettings(true);
}
if (config.containsKey("clientSettings")) {
if (config["clientSettings"].is<JsonVariant>()) {
const JsonObject& client_settings_json = config["clientSettings"];
client_enabled_ = client_settings_json["enabled"] | false;
client_settings_.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/sensors/analog_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ String AnalogInput::get_config_schema() { return kSchema; }
bool AnalogInput::set_configuration(const JsonObject& config) {
String const expected[] = {"read_delay"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/sensors/constant_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ConstantSensor : public Sensor<T> {
}
virtual bool set_configuration(const JsonObject &config) override {
// Neither of the configuration parameters are mandatory
if (config.containsKey("value")) {
if (config["value"].is<T>()) {
value_ = config["value"].as<T>();
}
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/sensesp/sensors/digital_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ String DigitalInputState::get_config_schema() { return kSchema2; }
bool DigitalInputState::set_configuration(const JsonObject& config) {
String const expected[] = {"read_delay"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand All @@ -47,7 +47,7 @@ String DigitalInputCounter::get_config_schema() { return kSchema; }
bool DigitalInputCounter::set_configuration(const JsonObject& config) {
String const expected[] = {"read_delay"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down Expand Up @@ -82,7 +82,7 @@ String DigitalInputDebounceCounter::get_config_schema() {
bool DigitalInputDebounceCounter::set_configuration(const JsonObject& config) {
String const expected[] = {"read_delay", "ignore_interval"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
ESP_LOGE(
__FILENAME__,
"Cannot set DigitalInputDebounceConfiguration configuration: missing "
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/signalk/signalk_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void SKListener::get_configuration(JsonObject &root) {
}

bool SKListener::set_configuration(const JsonObject &config) {
if (!config.containsKey("sk_path")) {
if (!config["sk_path"].is<String>()) {
return false;
}
this->set_sk_path(config["sk_path"].as<String>());
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/signalk/signalk_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SKOutput : public SKEmitter, public SymmetricTransform<T> {
String get_config_schema() override { return FPSTR(SIGNALKOUTPUT_SCHEMA); }

virtual bool set_configuration(const JsonObject& config) override {
if (!config.containsKey("sk_path")) {
if (!config["sk_path"].is<String>()) {
return false;
}
this->set_sk_path(config["sk_path"].as<String>());
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/signalk/signalk_put_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ String SKPutRequestBase::get_config_schema() { return kSchema; }
bool SKPutRequestBase::set_configuration(const JsonObject& config) {
const String expected[] = {"sk_path"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/signalk/signalk_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ String SKOutputTime::get_config_schema() { return kSchema; }
bool SKOutputTime::set_configuration(const JsonObject& config) {
const String expected[] = {"sk_path"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/sensesp/signalk/signalk_ws_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,16 @@ void SKWSClient::on_receive_delta(uint8_t* payload, size_t length) {
auto error = deserializeJson(message, buf);

if (!error) {
if (message.containsKey("updates")) {
if (message["updates"].is<JsonVariant>()) {
on_receive_updates(message);
}

if (message.containsKey("put")) {
if (message["put"].is<JsonVariant>()) {
on_receive_put(message);
}

// Putrequest contains also requestId Key GA
if (message.containsKey("requestId") && !message.containsKey("put")) {
if (message["requestId"].is<JsonVariant>() && !message["put"].is<JsonVariant>()) {
SKRequest::handle_response(message);
}
} else {
Expand Down Expand Up @@ -696,22 +696,22 @@ void SKWSClient::get_configuration(JsonObject& root) {
}

bool SKWSClient::set_configuration(const JsonObject& config) {
if (config.containsKey("sk_address")) {
if (config["sk_address"].is<String>()) {
this->conf_server_address_ = config["sk_address"].as<String>();
}
if (config.containsKey("sk_port")) {
if (config["sk_port"].is<int>()) {
this->conf_server_port_ = config["sk_port"].as<int>();
}
if (config.containsKey("use_mdns")) {
if (config["use_mdns"].is<bool>()) {
this->use_mdns_ = config["use_mdns"].as<bool>();
}
if (config.containsKey("token")) {
if (config["token"].is<String>()) {
this->auth_token_ = config["token"].as<String>();
}
if (config.containsKey("client_id")) {
if (config["client_id"].is<String>()) {
this->client_id_ = config["client_id"].as<String>();
}
if (config.containsKey("polling_href")) {
if (config["polling_href"].is<String>()) {
this->polling_href_ = config["polling_href"].as<String>();
}

Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/system/observablevalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class PersistingObservableValue : public ObservableValue<T>,
}

virtual bool set_configuration(const JsonObject& config) override {
if (!config.containsKey("value")) {
if (!config["value"].is<T>()) {
return false;
}
ObservableValue<T>::set(config["value"]);
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/system/rgb_led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ String RgbLed::get_config_schema() { return kSchema; }
bool RgbLed::set_configuration(const JsonObject& config) {
String expected[] = {"led_on_rgb", "led_off_rgb"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/analogvoltage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ String AnalogVoltage::get_config_schema() { return kSchema; }
bool AnalogVoltage::set_configuration(const JsonObject& config) {
const String expected[] = {"max_voltage", "multiplier", "offset"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/angle_correction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ String AngleCorrection::get_config_schema() { return kSchema; }
bool AngleCorrection::set_configuration(const JsonObject& config) {
String const expected[] = {"offset", "min_angle"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/change_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ String ChangeFilter::get_config_schema() { return (kSchema); }
bool ChangeFilter::set_configuration(const JsonObject& config) {
String const expected[] = {"min_delta", "max_delta", "max_skips"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/click_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ bool ClickType::set_configuration(const JsonObject& config) {
String const expected[] = {"long_click_delay", "ultra_long_click_delay",
"double_click_interval"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/curveinterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ String CurveInterpolator::get_config_schema() {
bool CurveInterpolator::set_configuration(const JsonObject& config) {
String const expected[] = {"samples"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
ESP_LOGE(
__FILENAME__,
"Can not set CurveInterpolator configuration: missing json field "
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/debounce.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Debounce : public SymmetricTransform<T> {
virtual bool set_configuration(const JsonObject& config) override {
const String expected[] = {"min_delay"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/enable.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Enable : public Transform<T, T> {
doc["enabled"] = enabled_;
}
virtual bool set_configuration(const JsonObject& config) override {
if (config.containsKey("enabled")) {
if (config["enabled"].is<bool>()) {
enabled_ = config["enabled"];
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/frequency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ String Frequency::get_config_schema() { return (kSchema); }
bool Frequency::set_configuration(const JsonObject& config) {
String const expected[] = {"multiplier"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/sensesp/transforms/integrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ class Integrator : public Transform<C, P> {
doc["k"] = k;
}
virtual bool set_configuration(const JsonObject& config) override final {
String expected[] = {"k"};
for (auto str : expected) {
if (!config.containsKey(str)) {
return false;
}
if (!config["k"].is<P>()) {
return false;
}
k = config["k"];
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/lambda_transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class LambdaTransform : public Transform<IN, OUT> {
ESP_LOGD(__FILENAME__, "Preparing to restore configuration from FS.");
for (int i = 0; i < num_params_; i++) {
const char* expected = param_info_[i].key;
if (!config.containsKey(expected)) {
if (!config[expected].is<JsonVariant>()) {
ESP_LOGD(__FILENAME__, "Didn't find all keys.");
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/median.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ String Median::get_config_schema() { return (kSchema); }
bool Median::set_configuration(const JsonObject& config) {
String const expected[] = {"sample_size"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/moving_average.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ String MovingAverage::get_config_schema() { return (kSchema); }
bool MovingAverage::set_configuration(const JsonObject& config) {
String const expected[] = {"multiplier", "sample_size"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/press_repeater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ String PressRepeater::get_config_schema() { return (kSchema); }
bool PressRepeater::set_configuration(const JsonObject& config) {
String const expected[] = {"repeat_start_interval", "repeat_interval"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/sensesp/transforms/threshold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static const char kFloatSchema[] = R"({
bool FloatThreshold::set_configuration(const JsonObject& config) {
String const expected[] = {"min", "max", "in_range"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down Expand Up @@ -61,7 +61,7 @@ static const char kIntSchema[] = R"({
bool IntThreshold::set_configuration(const JsonObject& config) {
String const expected[] = {"min", "max", "in_range"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sensesp/transforms/voltage_multiplier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ String VoltageMultiplier::get_config_schema() { return (kSchema); }
bool VoltageMultiplier::set_configuration(const JsonObject& config) {
String const expected[] = {"R1", "R2"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/sensesp/transforms/voltagedivider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ String VoltageDividerR1::get_config_schema() { return (kSchemaR1); }
bool VoltageDividerR1::set_configuration(const JsonObject& config) {
String const expected[] = {"Vin", "R2"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
ESP_LOGE(
__FILENAME__,
"Cannot set VoltageDividerR1: configuration: missing json field %s\n",
Expand Down Expand Up @@ -73,7 +73,7 @@ String VoltageDividerR2::get_config_schema() { return (kSchemaR2); }
bool VoltageDividerR2::set_configuration(const JsonObject& config) {
String const expected[] = {"Vin", "R1"};
for (auto str : expected) {
if (!config.containsKey(str)) {
if (!config[str].is<JsonVariant>()) {
ESP_LOGE(
__FILENAME__,
"Cannot set VoltageDividerR2: configuration: missing json field %s\n",
Expand Down
Loading

0 comments on commit 8a8884b

Please sign in to comment.