diff --git a/src/sensesp.h b/src/sensesp.h index c75e93346..868e72538 100644 --- a/src/sensesp.h +++ b/src/sensesp.h @@ -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 { diff --git a/src/sensesp/net/http_server.h b/src/sensesp/net/http_server.h index 214fca24b..8ce0d5cc8 100644 --- a/src/sensesp/net/http_server.h +++ b/src/sensesp/net/http_server.h @@ -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()) { auth_required_ = config["auth_required"]; } - if (config.containsKey("username")) { + if (config["username"].is()) { username_ = config["username"].as(); } - if (config.containsKey("password")) { + if (config["password"].is()) { password_ = config["password"].as(); } return true; diff --git a/src/sensesp/net/networking.cpp b/src/sensesp/net/networking.cpp index 6f088a18f..34ae4b08f 100644 --- a/src/sensesp/net/networking.cpp +++ b/src/sensesp/net/networking.cpp @@ -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()) { // deal with the legacy Json format String hostname = config["hostname"].as(); SensESPBaseApp::get()->get_hostname_observable()->set(hostname); - if (config.containsKey("ssid")) { + if (config["ssid"].is()) { String ssid = config["ssid"].as(); String password = config["password"].as(); - if (config.containsKey("ap_mode")) { + if (config["ap_mode"].is()) { bool ap_mode; if (config["ap_mode"].as() == "Access Point" || config["ap_mode"].as() == "Hotspot") { @@ -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()) { ap_settings_ = AccessPointSettings::from_json(config["apSettings"]); } else { ap_settings_ = AccessPointSettings(true); } - if (config.containsKey("clientSettings")) { + if (config["clientSettings"].is()) { const JsonObject& client_settings_json = config["clientSettings"]; client_enabled_ = client_settings_json["enabled"] | false; client_settings_.clear(); diff --git a/src/sensesp/sensors/analog_input.cpp b/src/sensesp/sensors/analog_input.cpp index c416aeb19..780f8b976 100644 --- a/src/sensesp/sensors/analog_input.cpp +++ b/src/sensesp/sensors/analog_input.cpp @@ -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()) { return false; } } diff --git a/src/sensesp/sensors/constant_sensor.h b/src/sensesp/sensors/constant_sensor.h index 8dc4a0ce3..8940d9a96 100644 --- a/src/sensesp/sensors/constant_sensor.h +++ b/src/sensesp/sensors/constant_sensor.h @@ -73,7 +73,7 @@ class ConstantSensor : public Sensor { } virtual bool set_configuration(const JsonObject &config) override { // Neither of the configuration parameters are mandatory - if (config.containsKey("value")) { + if (config["value"].is()) { value_ = config["value"].as(); } return true; diff --git a/src/sensesp/sensors/digital_input.cpp b/src/sensesp/sensors/digital_input.cpp index ac64c6b64..b1250ef06 100644 --- a/src/sensesp/sensors/digital_input.cpp +++ b/src/sensesp/sensors/digital_input.cpp @@ -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()) { return false; } } @@ -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()) { return false; } } @@ -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()) { ESP_LOGE( __FILENAME__, "Cannot set DigitalInputDebounceConfiguration configuration: missing " diff --git a/src/sensesp/signalk/signalk_listener.cpp b/src/sensesp/signalk/signalk_listener.cpp index 53d085d64..2a50c1bb3 100644 --- a/src/sensesp/signalk/signalk_listener.cpp +++ b/src/sensesp/signalk/signalk_listener.cpp @@ -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()) { return false; } this->set_sk_path(config["sk_path"].as()); diff --git a/src/sensesp/signalk/signalk_output.h b/src/sensesp/signalk/signalk_output.h index 247705deb..ed7ad2536 100644 --- a/src/sensesp/signalk/signalk_output.h +++ b/src/sensesp/signalk/signalk_output.h @@ -58,7 +58,7 @@ class SKOutput : public SKEmitter, public SymmetricTransform { 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()) { return false; } this->set_sk_path(config["sk_path"].as()); diff --git a/src/sensesp/signalk/signalk_put_request.cpp b/src/sensesp/signalk/signalk_put_request.cpp index 2174e6a7d..cb227878e 100644 --- a/src/sensesp/signalk/signalk_put_request.cpp +++ b/src/sensesp/signalk/signalk_put_request.cpp @@ -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()) { return false; } } diff --git a/src/sensesp/signalk/signalk_time.cpp b/src/sensesp/signalk/signalk_time.cpp index cbfda878f..c70479259 100644 --- a/src/sensesp/signalk/signalk_time.cpp +++ b/src/sensesp/signalk/signalk_time.cpp @@ -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()) { return false; } } diff --git a/src/sensesp/signalk/signalk_ws_client.cpp b/src/sensesp/signalk/signalk_ws_client.cpp index 948d126fe..bf1e4566c 100644 --- a/src/sensesp/signalk/signalk_ws_client.cpp +++ b/src/sensesp/signalk/signalk_ws_client.cpp @@ -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()) { on_receive_updates(message); } - if (message.containsKey("put")) { + if (message["put"].is()) { on_receive_put(message); } // Putrequest contains also requestId Key GA - if (message.containsKey("requestId") && !message.containsKey("put")) { + if (message["requestId"].is() && !message["put"].is()) { SKRequest::handle_response(message); } } else { @@ -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()) { this->conf_server_address_ = config["sk_address"].as(); } - if (config.containsKey("sk_port")) { + if (config["sk_port"].is()) { this->conf_server_port_ = config["sk_port"].as(); } - if (config.containsKey("use_mdns")) { + if (config["use_mdns"].is()) { this->use_mdns_ = config["use_mdns"].as(); } - if (config.containsKey("token")) { + if (config["token"].is()) { this->auth_token_ = config["token"].as(); } - if (config.containsKey("client_id")) { + if (config["client_id"].is()) { this->client_id_ = config["client_id"].as(); } - if (config.containsKey("polling_href")) { + if (config["polling_href"].is()) { this->polling_href_ = config["polling_href"].as(); } diff --git a/src/sensesp/system/observablevalue.h b/src/sensesp/system/observablevalue.h index ddf238dee..5c8df832f 100644 --- a/src/sensesp/system/observablevalue.h +++ b/src/sensesp/system/observablevalue.h @@ -76,7 +76,7 @@ class PersistingObservableValue : public ObservableValue, } virtual bool set_configuration(const JsonObject& config) override { - if (!config.containsKey("value")) { + if (!config["value"].is()) { return false; } ObservableValue::set(config["value"]); diff --git a/src/sensesp/system/rgb_led.cpp b/src/sensesp/system/rgb_led.cpp index 6bbc020d4..873c117d7 100644 --- a/src/sensesp/system/rgb_led.cpp +++ b/src/sensesp/system/rgb_led.cpp @@ -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()) { return false; } } diff --git a/src/sensesp/transforms/analogvoltage.cpp b/src/sensesp/transforms/analogvoltage.cpp index bab858191..c5167a24a 100644 --- a/src/sensesp/transforms/analogvoltage.cpp +++ b/src/sensesp/transforms/analogvoltage.cpp @@ -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()) { return false; } } diff --git a/src/sensesp/transforms/angle_correction.cpp b/src/sensesp/transforms/angle_correction.cpp index 875b21c91..1f8594bf6 100644 --- a/src/sensesp/transforms/angle_correction.cpp +++ b/src/sensesp/transforms/angle_correction.cpp @@ -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()) { return false; } } diff --git a/src/sensesp/transforms/change_filter.cpp b/src/sensesp/transforms/change_filter.cpp index 030a1049d..1ca97c5e0 100644 --- a/src/sensesp/transforms/change_filter.cpp +++ b/src/sensesp/transforms/change_filter.cpp @@ -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()) { return false; } } diff --git a/src/sensesp/transforms/click_type.cpp b/src/sensesp/transforms/click_type.cpp index ac57bc5cf..21a12ad5b 100644 --- a/src/sensesp/transforms/click_type.cpp +++ b/src/sensesp/transforms/click_type.cpp @@ -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()) { return false; } } diff --git a/src/sensesp/transforms/curveinterpolator.cpp b/src/sensesp/transforms/curveinterpolator.cpp index 79e7134dc..95aeb3d41 100644 --- a/src/sensesp/transforms/curveinterpolator.cpp +++ b/src/sensesp/transforms/curveinterpolator.cpp @@ -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()) { ESP_LOGE( __FILENAME__, "Can not set CurveInterpolator configuration: missing json field " diff --git a/src/sensesp/transforms/debounce.h b/src/sensesp/transforms/debounce.h index 8df3aec23..4da87a67f 100644 --- a/src/sensesp/transforms/debounce.h +++ b/src/sensesp/transforms/debounce.h @@ -75,7 +75,7 @@ class Debounce : public SymmetricTransform { 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()) { return false; } } diff --git a/src/sensesp/transforms/enable.h b/src/sensesp/transforms/enable.h index 7f905e245..561e309a1 100644 --- a/src/sensesp/transforms/enable.h +++ b/src/sensesp/transforms/enable.h @@ -38,7 +38,7 @@ class Enable : public Transform { doc["enabled"] = enabled_; } virtual bool set_configuration(const JsonObject& config) override { - if (config.containsKey("enabled")) { + if (config["enabled"].is()) { enabled_ = config["enabled"]; } else { return false; diff --git a/src/sensesp/transforms/frequency.cpp b/src/sensesp/transforms/frequency.cpp index 406c04ce8..7624f85c5 100644 --- a/src/sensesp/transforms/frequency.cpp +++ b/src/sensesp/transforms/frequency.cpp @@ -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()) { return false; } } diff --git a/src/sensesp/transforms/integrator.h b/src/sensesp/transforms/integrator.h index d3730a56c..4a4b32600 100644 --- a/src/sensesp/transforms/integrator.h +++ b/src/sensesp/transforms/integrator.h @@ -48,11 +48,8 @@ class Integrator : public Transform { 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

()) { + return false; } k = config["k"]; return true; diff --git a/src/sensesp/transforms/lambda_transform.h b/src/sensesp/transforms/lambda_transform.h index 5cdd9a226..87f0c90e8 100644 --- a/src/sensesp/transforms/lambda_transform.h +++ b/src/sensesp/transforms/lambda_transform.h @@ -232,7 +232,7 @@ class LambdaTransform : public Transform { 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()) { ESP_LOGD(__FILENAME__, "Didn't find all keys."); return false; } diff --git a/src/sensesp/transforms/median.cpp b/src/sensesp/transforms/median.cpp index d4fb5b023..b53a4dde5 100644 --- a/src/sensesp/transforms/median.cpp +++ b/src/sensesp/transforms/median.cpp @@ -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()) { return false; } } diff --git a/src/sensesp/transforms/moving_average.cpp b/src/sensesp/transforms/moving_average.cpp index 85d66101a..5e6bd6f41 100644 --- a/src/sensesp/transforms/moving_average.cpp +++ b/src/sensesp/transforms/moving_average.cpp @@ -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()) { return false; } } diff --git a/src/sensesp/transforms/press_repeater.cpp b/src/sensesp/transforms/press_repeater.cpp index 79b48f6d8..5763a984e 100644 --- a/src/sensesp/transforms/press_repeater.cpp +++ b/src/sensesp/transforms/press_repeater.cpp @@ -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()) { return false; } } diff --git a/src/sensesp/transforms/threshold.cpp b/src/sensesp/transforms/threshold.cpp index 4e2734c85..e82bbad70 100644 --- a/src/sensesp/transforms/threshold.cpp +++ b/src/sensesp/transforms/threshold.cpp @@ -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()) { return false; } } @@ -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()) { return false; } } diff --git a/src/sensesp/transforms/voltage_multiplier.cpp b/src/sensesp/transforms/voltage_multiplier.cpp index 333bc654c..c6f00ec31 100644 --- a/src/sensesp/transforms/voltage_multiplier.cpp +++ b/src/sensesp/transforms/voltage_multiplier.cpp @@ -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()) { return false; } } diff --git a/src/sensesp/transforms/voltagedivider.cpp b/src/sensesp/transforms/voltagedivider.cpp index 3f9e6b974..80658443a 100644 --- a/src/sensesp/transforms/voltagedivider.cpp +++ b/src/sensesp/transforms/voltagedivider.cpp @@ -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()) { ESP_LOGE( __FILENAME__, "Cannot set VoltageDividerR1: configuration: missing json field %s\n", @@ -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()) { ESP_LOGE( __FILENAME__, "Cannot set VoltageDividerR2: configuration: missing json field %s\n", diff --git a/src/sensesp/types/position.cpp b/src/sensesp/types/position.cpp index 16df87fac..2a21b5758 100644 --- a/src/sensesp/types/position.cpp +++ b/src/sensesp/types/position.cpp @@ -8,7 +8,7 @@ void convertFromJson(JsonVariantConst src, Position &dst) { dst.longitude = src["longitude"].as(); dst.latitude = src["latitude"].as(); - if (src.containsKey("altitude")) { + if (src["altitude"].is()) { dst.altitude = src["altitude"].as(); } } @@ -17,7 +17,7 @@ void convertFromJson(JsonVariantConst src, ENUVector &dst) { dst.east = src["east"].as(); dst.north = src["north"].as(); - if (src.containsKey("up")) { + if (src["up"].is()) { dst.up = src["up"].as(); } } @@ -29,17 +29,17 @@ void convertFromJson(JsonVariantConst src, AttitudeVector &dst) { } bool canConvertFromJson(JsonVariantConst src, const Position & /*position*/) { - return src.containsKey("latitude") && src.containsKey("longitude"); + return src["latitude"].is() && src["longitude"].is(); } bool canConvertFromJson(JsonVariantConst src, const ENUVector & /*enu*/) { - return src.containsKey("east") && src.containsKey("north"); + return src["east"].is() && src["north"].is(); } bool canConvertFromJson(JsonVariantConst src, const AttitudeVector & /*attitude*/) { - return src.containsKey("roll") && src.containsKey("pitch") && - src.containsKey("yaw"); + return src["roll"].is() && src["pitch"].is() && + src["yaw"].is(); } void convertToJson(const Position &src, JsonVariant dst) { diff --git a/src/sensesp/ui/ui_controls.cpp b/src/sensesp/ui/ui_controls.cpp index 834d88c59..ae8f68876 100644 --- a/src/sensesp/ui/ui_controls.cpp +++ b/src/sensesp/ui/ui_controls.cpp @@ -20,7 +20,7 @@ String StringConfig::get_config_schema() { void StringConfig::get_configuration(JsonObject& doc) { doc["value"] = value_; } bool StringConfig::set_configuration(const JsonObject& config) { - if (!config.containsKey("value")) { + if (!config["value"].is()) { return false; } @@ -45,7 +45,7 @@ String NumberConfig::get_config_schema() { void NumberConfig::get_configuration(JsonObject& doc) { doc["value"] = value_; } bool NumberConfig::set_configuration(const JsonObject& config) { - if (!config.containsKey("value")) { + if (!config["value"].is()) { return false; } @@ -72,7 +72,7 @@ void CheckboxConfig::get_configuration(JsonObject& doc) { } bool CheckboxConfig::set_configuration(const JsonObject& config) { - if (!config.containsKey("value")) { + if (!config["value"].is()) { return false; } @@ -120,7 +120,7 @@ String SelectConfig::get_config_schema() { void SelectConfig::get_configuration(JsonObject& doc) { doc["value"] = value_; } bool SelectConfig::set_configuration(const JsonObject& config) { - if (!config.containsKey("value")) { + if (!config["value"].is()) { return false; }