From 2e379e6c1eba2f03cef02eab19b4955c4291810c Mon Sep 17 00:00:00 2001 From: cjkas Date: Tue, 24 Mar 2026 22:15:17 +0100 Subject: [PATCH] Cleanup build warnings --- src/ConfigSettings.cpp | 58 +++++++-------- src/Somfy.cpp | 156 ++++++++++++++++++++--------------------- src/Web.cpp | 140 ++++++++++++++++++------------------ 3 files changed, 177 insertions(+), 177 deletions(-) diff --git a/src/ConfigSettings.cpp b/src/ConfigSettings.cpp index b981711..4cbc1e5 100644 --- a/src/ConfigSettings.cpp +++ b/src/ConfigSettings.cpp @@ -13,12 +13,12 @@ static const char *TAG = "Config"; Preferences pref; void restore_options_t::fromJSON(JsonObject &obj) { - if(obj.containsKey("shades")) this->shades = obj["shades"]; - if(obj.containsKey("settings")) this->settings = obj["settings"]; - if(obj.containsKey("network")) this->network = obj["network"]; - if(obj.containsKey("transceiver")) this->transceiver = obj["transceiver"]; - if(obj.containsKey("repeaters")) this->repeaters = obj["repeaters"]; - if(obj.containsKey("mqtt")) this->mqtt = obj["mqtt"]; + if(!obj["shades"].isNull()) this->shades = obj["shades"]; + if(!obj["settings"].isNull()) this->settings = obj["settings"]; + if(!obj["network"].isNull()) this->network = obj["network"]; + if(!obj["transceiver"].isNull()) this->transceiver = obj["transceiver"]; + if(!obj["repeaters"].isNull()) this->repeaters = obj["repeaters"]; + if(!obj["mqtt"].isNull()) this->mqtt = obj["mqtt"]; } int8_t appver_t::compare(appver_t &ver) { if(this->major == ver.major && this->minor == ver.minor && this->build == ver.build) return 0; @@ -125,11 +125,11 @@ bool BaseSettings::saveFile(const char *filename) { return true; } bool BaseSettings::parseValueString(JsonObject &obj, const char *prop, char *pdest, size_t size) { - if(obj.containsKey(prop)) strlcpy(pdest, obj[prop], size); + if(!obj[prop].isNull()) strlcpy(pdest, obj[prop], size); return true; } bool BaseSettings::parseIPAddress(JsonObject &obj, const char *prop, IPAddress *pdest) { - if(obj.containsKey(prop)) { + if(!obj[prop].isNull()) { char buff[16]; strlcpy(buff, obj[prop], sizeof(buff)); pdest->fromString(buff); @@ -137,11 +137,11 @@ bool BaseSettings::parseIPAddress(JsonObject &obj, const char *prop, IPAddress * return true; } int BaseSettings::parseValueInt(JsonObject &obj, const char *prop, int defVal) { - if(obj.containsKey(prop)) return obj[prop]; + if(!obj[prop].isNull()) return obj[prop]; return defVal; } double BaseSettings::parseValueDouble(JsonObject &obj, const char *prop, double defVal) { - if(obj.containsKey(prop)) return obj[prop]; + if(!obj[prop].isNull()) return obj[prop]; return defVal; } bool ConfigSettings::begin() { @@ -247,10 +247,10 @@ bool ConfigSettings::toJSON(JsonObject &obj) { } bool ConfigSettings::requiresAuth() { return this->Security.type != security_types::None; } bool ConfigSettings::fromJSON(JsonObject &obj) { - if(obj.containsKey("ssdpBroadcast")) this->ssdpBroadcast = obj["ssdpBroadcast"]; - if(obj.containsKey("hostname")) this->parseValueString(obj, "hostname", this->hostname, sizeof(this->hostname)); - if(obj.containsKey("connType")) this->connType = static_cast(obj["connType"].as()); - if(obj.containsKey("checkForUpdate")) this->checkForUpdate = obj["checkForUpdate"]; + if(!obj["ssdpBroadcast"].isNull()) this->ssdpBroadcast = obj["ssdpBroadcast"]; + if(!obj["hostname"].isNull()) this->parseValueString(obj, "hostname", this->hostname, sizeof(this->hostname)); + if(!obj["connType"].isNull()) this->connType = static_cast(obj["connType"].as()); + if(!obj["checkForUpdate"].isNull()) this->checkForUpdate = obj["checkForUpdate"]; return true; } void ConfigSettings::print() { @@ -309,15 +309,15 @@ bool MQTTSettings::toJSON(JsonObject &obj) { return true; } bool MQTTSettings::fromJSON(JsonObject &obj) { - if(obj.containsKey("enabled")) this->enabled = obj["enabled"]; - if(obj.containsKey("pubDisco")) this->pubDisco = obj["pubDisco"]; + if(!obj["enabled"].isNull()) this->enabled = obj["enabled"]; + if(!obj["pubDisco"].isNull()) this->pubDisco = obj["pubDisco"]; this->parseValueString(obj, "protocol", this->protocol, sizeof(this->protocol)); this->parseValueString(obj, "hostname", this->hostname, sizeof(this->hostname)); this->parseValueString(obj, "username", this->username, sizeof(this->username)); this->parseValueString(obj, "password", this->password, sizeof(this->password)); this->parseValueString(obj, "rootTopic", this->rootTopic, sizeof(this->rootTopic)); this->parseValueString(obj, "discoTopic", this->discoTopic, sizeof(this->discoTopic)); - if(obj.containsKey("port")) this->port = obj["port"]; + if(!obj["port"].isNull()) this->port = obj["port"]; return true; } bool MQTTSettings::save() { @@ -409,7 +409,7 @@ bool IPSettings::begin() { return true; } bool IPSettings::fromJSON(JsonObject &obj) { - if(obj.containsKey("dhcp")) this->dhcp = obj["dhcp"]; + if(!obj["dhcp"].isNull()) this->dhcp = obj["dhcp"]; this->parseIPAddress(obj, "ip", &this->ip); this->parseIPAddress(obj, "gateway", &this->gateway); this->parseIPAddress(obj, "subnet", &this->subnet); @@ -472,11 +472,11 @@ bool SecuritySettings::begin() { return true; } bool SecuritySettings::fromJSON(JsonObject &obj) { - if(obj.containsKey("type")) this->type = static_cast(obj["type"].as()); + if(!obj["type"].isNull()) this->type = static_cast(obj["type"].as()); this->parseValueString(obj, "username", this->username, sizeof(this->username)); this->parseValueString(obj, "password", this->password, sizeof(this->password)); this->parseValueString(obj, "pin", this->pin, sizeof(this->pin)); - if(obj.containsKey("permissions")) this->permissions = obj["permissions"]; + if(!obj["permissions"].isNull()) this->permissions = obj["permissions"]; return true; } bool SecuritySettings::toJSON(JsonObject &obj) { @@ -521,8 +521,8 @@ bool WifiSettings::begin() { bool WifiSettings::fromJSON(JsonObject &obj) { this->parseValueString(obj, "ssid", this->ssid, sizeof(this->ssid)); this->parseValueString(obj, "passphrase", this->passphrase, sizeof(this->passphrase)); - if(obj.containsKey("roaming")) this->roaming = obj["roaming"]; - if(obj.containsKey("hidden")) this->hidden = obj["hidden"]; + if(!obj["roaming"].isNull()) this->roaming = obj["roaming"]; + if(!obj["hidden"].isNull()) this->hidden = obj["hidden"]; return true; } bool WifiSettings::toJSON(JsonObject &obj) { @@ -596,13 +596,13 @@ bool EthernetSettings::begin() { return true; } bool EthernetSettings::fromJSON(JsonObject &obj) { - if(obj.containsKey("boardType")) this->boardType = obj["boardType"]; - if(obj.containsKey("phyAddress")) this->phyAddress = obj["phyAddress"]; - if(obj.containsKey("CLKMode")) this->CLKMode = static_cast(obj["CLKMode"]); - if(obj.containsKey("phyType")) this->phyType = static_cast(obj["phyType"]); - if(obj.containsKey("PWRPin")) this->PWRPin = obj["PWRPin"]; - if(obj.containsKey("MDCPin")) this->MDCPin = obj["MDCPin"]; - if(obj.containsKey("MDIOPin")) this->MDIOPin = obj["MDIOPin"]; + if(!obj["boardType"].isNull()) this->boardType = obj["boardType"]; + if(!obj["phyAddress"].isNull()) this->phyAddress = obj["phyAddress"]; + if(!obj["CLKMode"].isNull()) this->CLKMode = static_cast(obj["CLKMode"]); + if(!obj["phyType"].isNull()) this->phyType = static_cast(obj["phyType"]); + if(!obj["PWRPin"].isNull()) this->PWRPin = obj["PWRPin"]; + if(!obj["MDCPin"].isNull()) this->MDCPin = obj["MDCPin"]; + if(!obj["MDIOPin"].isNull()) this->MDIOPin = obj["MDIOPin"]; return true; } bool EthernetSettings::toJSON(JsonObject &obj) { diff --git a/src/Somfy.cpp b/src/Somfy.cpp index 2ee950e..59284b6 100644 --- a/src/Somfy.cpp +++ b/src/Somfy.cpp @@ -3105,7 +3105,7 @@ bool SomfyShade::usesPin(uint8_t pin) { int8_t SomfyShade::validateJSON(JsonObject &obj) { int8_t ret = 0; shade_types type = this->shadeType; - if(obj.containsKey("shadeType")) { + if(!obj["shadeType"].isNull()) { if(obj["shadeType"].is()) { if(strncmp(obj["shadeType"].as(), "roller", 7) == 0) type = shade_types::roller; @@ -3134,14 +3134,14 @@ int8_t SomfyShade::validateJSON(JsonObject &obj) { this->shadeType = static_cast(obj["shadeType"].as()); } } - if(obj.containsKey("proto")) { + if(!obj["proto"].isNull()) { radio_proto proto = this->proto; if(proto == radio_proto::GP_Relay || proto == radio_proto::GP_Remote) { // Check to see if we are using the up and or down // GPIOs anywhere else. - uint8_t upPin = obj.containsKey("gpioUp") ? obj["gpioUp"].as() : this->gpioUp; - uint8_t downPin = obj.containsKey("gpioDown") ? obj["gpioDown"].as() : this->gpioDown; - uint8_t myPin = obj.containsKey("gpioMy") ? obj["gpioMy"].as() : this->gpioMy; + uint8_t upPin = !obj["gpioUp"].isNull() ? obj["gpioUp"].as() : this->gpioUp; + uint8_t downPin = !obj["gpioDown"].isNull() ? obj["gpioDown"].as() : this->gpioDown; + uint8_t myPin = !obj["gpioMy"].isNull() ? obj["gpioMy"].as() : this->gpioMy; if(type == shade_types::drycontact || ((type == shade_types::garage1 || type == shade_types::lgate1 || type == shade_types::cgate1 || type == shade_types::rgate1) && proto == radio_proto::GP_Remote)) upPin = myPin = 255; @@ -3178,28 +3178,28 @@ int8_t SomfyShade::validateJSON(JsonObject &obj) { int8_t SomfyShade::fromJSON(JsonObject &obj) { int8_t err = this->validateJSON(obj); if(err == 0) { - if(obj.containsKey("name")) strlcpy(this->name, obj["name"], sizeof(this->name)); - if(obj.containsKey("roomId")) this->roomId = obj["roomId"]; - if(obj.containsKey("upTime")) this->upTime = obj["upTime"]; - if(obj.containsKey("downTime")) this->downTime = obj["downTime"]; - if(obj.containsKey("remoteAddress")) this->setRemoteAddress(obj["remoteAddress"]); - if(obj.containsKey("tiltTime")) this->tiltTime = obj["tiltTime"]; - if(obj.containsKey("stepSize")) this->stepSize = obj["stepSize"]; - if(obj.containsKey("hasTilt")) this->tiltType = static_cast(obj["hasTilt"]) ? tilt_types::none : tilt_types::tiltmotor; - if(obj.containsKey("bitLength")) this->bitLength = obj["bitLength"]; - if(obj.containsKey("proto")) this->proto = static_cast(obj["proto"].as()); - if(obj.containsKey("sunSensor")) this->setSunSensor(obj["sunSensor"]); - if(obj.containsKey("simMy")) this->setSimMy(obj["simMy"]); - if(obj.containsKey("light")) this->setLight(obj["light"]); - if(obj.containsKey("gpioFlags")) this->gpioFlags = obj["gpioFlags"]; - if(obj.containsKey("gpioLLTrigger")) { + if(!obj["name"].isNull()) strlcpy(this->name, obj["name"], sizeof(this->name)); + if(!obj["roomId"].isNull()) this->roomId = obj["roomId"]; + if(!obj["upTime"].isNull()) this->upTime = obj["upTime"]; + if(!obj["downTime"].isNull()) this->downTime = obj["downTime"]; + if(!obj["remoteAddress"].isNull()) this->setRemoteAddress(obj["remoteAddress"]); + if(!obj["tiltTime"].isNull()) this->tiltTime = obj["tiltTime"]; + if(!obj["stepSize"].isNull()) this->stepSize = obj["stepSize"]; + if(!obj["hasTilt"].isNull()) this->tiltType = static_cast(obj["hasTilt"]) ? tilt_types::none : tilt_types::tiltmotor; + if(!obj["bitLength"].isNull()) this->bitLength = obj["bitLength"]; + if(!obj["proto"].isNull()) this->proto = static_cast(obj["proto"].as()); + if(!obj["sunSensor"].isNull()) this->setSunSensor(obj["sunSensor"]); + if(!obj["simMy"].isNull()) this->setSimMy(obj["simMy"]); + if(!obj["light"].isNull()) this->setLight(obj["light"]); + if(!obj["gpioFlags"].isNull()) this->gpioFlags = obj["gpioFlags"]; + if(!obj["gpioLLTrigger"].isNull()) { if(obj["gpioLLTrigger"].as()) this->gpioFlags |= (uint8_t)gpio_flags_t::LowLevelTrigger; else this->gpioFlags &= ~(uint8_t)gpio_flags_t::LowLevelTrigger; } - if(obj.containsKey("shadeType")) { + if(!obj["shadeType"].isNull()) { if(obj["shadeType"].is()) { if(strncmp(obj["shadeType"].as(), "roller", 7) == 0) this->shadeType = shade_types::roller; @@ -3228,10 +3228,10 @@ int8_t SomfyShade::fromJSON(JsonObject &obj) { this->shadeType = static_cast(obj["shadeType"].as()); } } - if(obj.containsKey("flipCommands")) this->flipCommands = obj["flipCommands"].as(); - if(obj.containsKey("flipPosition")) this->flipPosition = obj["flipPosition"].as(); - if(obj.containsKey("repeats")) this->repeats = obj["repeats"]; - if(obj.containsKey("tiltType")) { + if(!obj["flipCommands"].isNull()) this->flipCommands = obj["flipCommands"].as(); + if(!obj["flipPosition"].isNull()) this->flipPosition = obj["flipPosition"].as(); + if(!obj["repeats"].isNull()) this->repeats = obj["repeats"]; + if(!obj["tiltType"].isNull()) { if(obj["tiltType"].is()) { if(strncmp(obj["tiltType"].as(), "none", 4) == 0) this->tiltType = tilt_types::none; @@ -3246,7 +3246,7 @@ int8_t SomfyShade::fromJSON(JsonObject &obj) { this->tiltType = static_cast(obj["tiltType"].as()); } } - if(obj.containsKey("linkedAddresses")) { + if(!obj["linkedAddresses"].isNull()) { uint32_t linkedAddresses[SOMFY_MAX_LINKED_REMOTES]; memset(linkedAddresses, 0x00, sizeof(linkedAddresses)); JsonArray arr = obj["linkedAddresses"]; @@ -3258,15 +3258,15 @@ int8_t SomfyShade::fromJSON(JsonObject &obj) { this->linkedRemotes[j].setRemoteAddress(linkedAddresses[j]); } } - if(obj.containsKey("flags")) this->flags = obj["flags"]; + if(!obj["flags"].isNull()) this->flags = obj["flags"]; if(this->proto == radio_proto::GP_Remote || this->proto == radio_proto::GP_Relay) { - if(obj.containsKey("gpioUp")) this->gpioUp = obj["gpioUp"]; - if(obj.containsKey("gpioDown")) this->gpioDown = obj["gpioDown"]; + if(!obj["gpioUp"].isNull()) this->gpioUp = obj["gpioUp"]; + if(!obj["gpioDown"].isNull()) this->gpioDown = obj["gpioDown"]; pinMode(this->gpioUp, OUTPUT); pinMode(this->gpioDown, OUTPUT); } if(this->proto == radio_proto::GP_Remote) { - if(obj.containsKey("gpioMy")) this->gpioMy = obj["gpioMy"]; + if(!obj["gpioMy"].isNull()) this->gpioMy = obj["gpioMy"]; pinMode(this->gpioMy, OUTPUT); } } @@ -3327,8 +3327,8 @@ bool SomfyShade::toJSON(JsonObject &obj) { } */ bool SomfyRoom::fromJSON(JsonObject &obj) { - if(obj.containsKey("name")) strlcpy(this->name, obj["name"], sizeof(this->name)); - if(obj.containsKey("sortOrder")) this->sortOrder = obj["sortOrder"]; + if(!obj["name"].isNull()) strlcpy(this->name, obj["name"], sizeof(this->name)); + if(!obj["sortOrder"].isNull()) this->sortOrder = obj["sortOrder"]; return true; } /* @@ -3340,16 +3340,16 @@ bool SomfyRoom::toJSON(JsonObject &obj) { } */ bool SomfyGroup::fromJSON(JsonObject &obj) { - if(obj.containsKey("name")) strlcpy(this->name, obj["name"], sizeof(this->name)); - if(obj.containsKey("roomId")) this->roomId = obj["roomId"]; - if(obj.containsKey("remoteAddress")) this->setRemoteAddress(obj["remoteAddress"]); - if(obj.containsKey("bitLength")) this->bitLength = obj["bitLength"]; - if(obj.containsKey("proto")) this->proto = static_cast(obj["proto"].as()); - if(obj.containsKey("flipCommands")) this->flipCommands = obj["flipCommands"].as(); + if(!obj["name"].isNull()) strlcpy(this->name, obj["name"], sizeof(this->name)); + if(!obj["roomId"].isNull()) this->roomId = obj["roomId"]; + if(!obj["remoteAddress"].isNull()) this->setRemoteAddress(obj["remoteAddress"]); + if(!obj["bitLength"].isNull()) this->bitLength = obj["bitLength"]; + if(!obj["proto"].isNull()) this->proto = static_cast(obj["proto"].as()); + if(!obj["flipCommands"].isNull()) this->flipCommands = obj["flipCommands"].as(); - //if(obj.containsKey("sunSensor")) this->hasSunSensor() = obj["sunSensor"]; This is calculated - if(obj.containsKey("repeats")) this->repeats = obj["repeats"]; - if(obj.containsKey("linkedShades")) { + //if(!obj["sunSensor"].isNull()) this->hasSunSensor() = obj["sunSensor"]; This is calculated + if(!obj["repeats"].isNull()) this->repeats = obj["repeats"]; + if(!obj["linkedShades"].isNull()) { uint8_t linkedShades[SOMFY_MAX_GROUPED_SHADES]; memset(linkedShades, 0x00, sizeof(linkedShades)); JsonArray arr = obj["linkedShades"]; @@ -4485,7 +4485,7 @@ bool Transceiver::toJSON(JsonObject& obj) { } */ bool Transceiver::fromJSON(JsonObject& obj) { - if (obj.containsKey("config")) { + if (!obj["config"].isNull()) { JsonObject objConfig = obj["config"]; this->config.fromJSON(objConfig); } @@ -4514,43 +4514,43 @@ bool Transceiver::end() { } void transceiver_config_t::fromJSON(JsonObject& obj) { //Serial.print("Deserialize Radio JSON "); - if(obj.containsKey("type")) this->type = obj["type"]; - if(obj.containsKey("CSNPin")) this->CSNPin = obj["CSNPin"]; - if(obj.containsKey("MISOPin")) this->MISOPin = obj["MISOPin"]; - if(obj.containsKey("MOSIPin")) this->MOSIPin = obj["MOSIPin"]; - if(obj.containsKey("RXPin")) this->RXPin = obj["RXPin"]; - if(obj.containsKey("SCKPin")) this->SCKPin = obj["SCKPin"]; - if(obj.containsKey("TXPin")) this->TXPin = obj["TXPin"]; - if(obj.containsKey("rxBandwidth")) this->rxBandwidth = obj["rxBandwidth"]; // float - if(obj.containsKey("frequency")) this->frequency = obj["frequency"]; // float - if(obj.containsKey("deviation")) this->deviation = obj["deviation"]; // float - if(obj.containsKey("enabled")) this->enabled = obj["enabled"]; - if(obj.containsKey("txPower")) this->txPower = obj["txPower"]; - if(obj.containsKey("proto")) this->proto = static_cast(obj["proto"].as()); + if(!obj["type"].isNull()) this->type = obj["type"]; + if(!obj["CSNPin"].isNull()) this->CSNPin = obj["CSNPin"]; + if(!obj["MISOPin"].isNull()) this->MISOPin = obj["MISOPin"]; + if(!obj["MOSIPin"].isNull()) this->MOSIPin = obj["MOSIPin"]; + if(!obj["RXPin"].isNull()) this->RXPin = obj["RXPin"]; + if(!obj["SCKPin"].isNull()) this->SCKPin = obj["SCKPin"]; + if(!obj["TXPin"].isNull()) this->TXPin = obj["TXPin"]; + if(!obj["rxBandwidth"].isNull()) this->rxBandwidth = obj["rxBandwidth"]; // float + if(!obj["frequency"].isNull()) this->frequency = obj["frequency"]; // float + if(!obj["deviation"].isNull()) this->deviation = obj["deviation"]; // float + if(!obj["enabled"].isNull()) this->enabled = obj["enabled"]; + if(!obj["txPower"].isNull()) this->txPower = obj["txPower"]; + if(!obj["proto"].isNull()) this->proto = static_cast(obj["proto"].as()); /* - if (obj.containsKey("internalCCMode")) this->internalCCMode = obj["internalCCMode"]; - if (obj.containsKey("modulationMode")) this->modulationMode = obj["modulationMode"]; - if (obj.containsKey("channel")) this->channel = obj["channel"]; - if (obj.containsKey("channelSpacing")) this->channelSpacing = obj["channelSpacing"]; // float - if (obj.containsKey("dataRate")) this->dataRate = obj["dataRate"]; // float - if (obj.containsKey("syncMode")) this->syncMode = obj["syncMode"]; - if (obj.containsKey("syncWordHigh")) this->syncWordHigh = obj["syncWordHigh"]; - if (obj.containsKey("syncWordLow")) this->syncWordLow = obj["syncWordLow"]; - if (obj.containsKey("addrCheckMode")) this->addrCheckMode = obj["addrCheckMode"]; - if (obj.containsKey("checkAddr")) this->checkAddr = obj["checkAddr"]; - if (obj.containsKey("dataWhitening")) this->dataWhitening = obj["dataWhitening"]; - if (obj.containsKey("pktFormat")) this->pktFormat = obj["pktFormat"]; - if (obj.containsKey("pktLengthMode")) this->pktLengthMode = obj["pktLengthMode"]; - if (obj.containsKey("pktLength")) this->pktLength = obj["pktLength"]; - if (obj.containsKey("useCRC")) this->useCRC = obj["useCRC"]; - if (obj.containsKey("autoFlushCRC")) this->autoFlushCRC = obj["autoFlushCRC"]; - if (obj.containsKey("disableDCFilter")) this->disableDCFilter = obj["disableCRCFilter"]; - if (obj.containsKey("enableManchester")) this->enableManchester = obj["enableManchester"]; - if (obj.containsKey("enableFEC")) this->enableFEC = obj["enableFEC"]; - if (obj.containsKey("minPreambleBytes")) this->minPreambleBytes = obj["minPreambleBytes"]; - if (obj.containsKey("pqtThreshold")) this->pqtThreshold = obj["pqtThreshold"]; - if (obj.containsKey("appendStatus")) this->appendStatus = obj["appendStatus"]; - if (obj.containsKey("printBuffer")) this->printBuffer = obj["printBuffer"]; + if (!obj["internalCCMode"].isNull()) this->internalCCMode = obj["internalCCMode"]; + if (!obj["modulationMode"].isNull()) this->modulationMode = obj["modulationMode"]; + if (!obj["channel"].isNull()) this->channel = obj["channel"]; + if (!obj["channelSpacing"].isNull()) this->channelSpacing = obj["channelSpacing"]; // float + if (!obj["dataRate"].isNull()) this->dataRate = obj["dataRate"]; // float + if (!obj["syncMode"].isNull()) this->syncMode = obj["syncMode"]; + if (!obj["syncWordHigh"].isNull()) this->syncWordHigh = obj["syncWordHigh"]; + if (!obj["syncWordLow"].isNull()) this->syncWordLow = obj["syncWordLow"]; + if (!obj["addrCheckMode"].isNull()) this->addrCheckMode = obj["addrCheckMode"]; + if (!obj["checkAddr"].isNull()) this->checkAddr = obj["checkAddr"]; + if (!obj["dataWhitening"].isNull()) this->dataWhitening = obj["dataWhitening"]; + if (!obj["pktFormat"].isNull()) this->pktFormat = obj["pktFormat"]; + if (!obj["pktLengthMode"].isNull()) this->pktLengthMode = obj["pktLengthMode"]; + if (!obj["pktLength"].isNull()) this->pktLength = obj["pktLength"]; + if (!obj["useCRC"].isNull()) this->useCRC = obj["useCRC"]; + if (!obj["autoFlushCRC"].isNull()) this->autoFlushCRC = obj["autoFlushCRC"]; + if (!obj["disableDCFilter"].isNull()) this->disableDCFilter = obj["disableCRCFilter"]; + if (!obj["enableManchester"].isNull()) this->enableManchester = obj["enableManchester"]; + if (!obj["enableFEC"].isNull()) this->enableFEC = obj["enableFEC"]; + if (!obj["minPreambleBytes"].isNull()) this->minPreambleBytes = obj["minPreambleBytes"]; + if (!obj["pqtThreshold"].isNull()) this->pqtThreshold = obj["pqtThreshold"]; + if (!obj["appendStatus"].isNull()) this->appendStatus = obj["appendStatus"]; + if (!obj["printBuffer"].isNull()) this->printBuffer = obj["printBuffer"]; */ ESP_LOGD(TAG, "SCK:%u MISO:%u MOSI:%u CSN:%u RX:%u TX:%u", this->SCKPin, this->MISOPin, this->MOSIPin, this->CSNPin, this->RXPin, this->TXPin); } diff --git a/src/Web.cpp b/src/Web.cpp index 344e39a..9a5f6f7 100644 --- a/src/Web.cpp +++ b/src/Web.cpp @@ -463,9 +463,9 @@ void Web::handleLogin(AsyncWebServerRequest *request, JsonVariant &json) { // Override from JSON body if present if(!json.isNull()) { JsonObject obj = json.as(); - if(obj.containsKey("username")) strlcpy(username, obj["username"], sizeof(username)); - if(obj.containsKey("password")) strlcpy(password, obj["password"], sizeof(password)); - if(obj.containsKey("pin")) strlcpy(pin, obj["pin"], sizeof(pin)); + if(!obj["username"].isNull()) strlcpy(username, obj["username"], sizeof(username)); + if(!obj["password"].isNull()) strlcpy(password, obj["password"], sizeof(password)); + if(!obj["pin"].isNull()) strlcpy(pin, obj["pin"], sizeof(pin)); } bool success = false; if(settings.Security.type == security_types::PinEntry) { @@ -511,12 +511,12 @@ void Web::handleShadeCommand(AsyncWebServerRequest *request, JsonVariant &json) } else if(!json.isNull()) { JsonObject obj = json.as(); - if(obj.containsKey("shadeId")) shadeId = obj["shadeId"]; + if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"]; else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade id was supplied.\"}")); return; } - if(obj.containsKey("command")) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); } - else if(obj.containsKey("target")) target = obj["target"].as(); - if(obj.containsKey("repeat")) repeat = obj["repeat"].as(); - if(obj.containsKey("stepSize")) stepSize = obj["stepSize"].as(); + if(!obj["command"].isNull()) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); } + else if(!obj["target"].isNull()) target = obj["target"].as(); + if(!obj["repeat"].isNull()) repeat = obj["repeat"].as(); + if(!obj["stepSize"].isNull()) stepSize = obj["stepSize"].as(); } else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade object supplied.\"}")); return; } SomfyShade *shade = somfy.getShadeById(shadeId); @@ -547,11 +547,11 @@ void Web::handleGroupCommand(AsyncWebServerRequest *request, JsonVariant &json) } else if(!json.isNull()) { JsonObject obj = json.as(); - if(obj.containsKey("groupId")) groupId = obj["groupId"]; + if(!obj["groupId"].isNull()) groupId = obj["groupId"]; else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No group id was supplied.\"}")); return; } - if(obj.containsKey("command")) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); } - if(obj.containsKey("repeat")) repeat = obj["repeat"].as(); - if(obj.containsKey("stepSize")) stepSize = obj["stepSize"].as(); + if(!obj["command"].isNull()) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); } + if(!obj["repeat"].isNull()) repeat = obj["repeat"].as(); + if(!obj["stepSize"].isNull()) stepSize = obj["stepSize"].as(); } else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No group object supplied.\"}")); return; } SomfyGroup *group = somfy.getGroupById(groupId); @@ -579,10 +579,10 @@ void Web::handleTiltCommand(AsyncWebServerRequest *request, JsonVariant &json) { } else if(!json.isNull()) { JsonObject obj = json.as(); - if(obj.containsKey("shadeId")) shadeId = obj["shadeId"]; + if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"]; else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade id was supplied.\"}")); return; } - if(obj.containsKey("command")) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); } - else if(obj.containsKey("target")) target = obj["target"].as(); + if(!obj["command"].isNull()) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); } + else if(!obj["target"].isNull()) target = obj["target"].as(); } else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade object supplied.\"}")); return; } SomfyShade *shade = somfy.getShadeById(shadeId); @@ -613,11 +613,11 @@ void Web::handleRepeatCommand(AsyncWebServerRequest *request, JsonVariant &json) if(asyncHasParam(request, "stepSize")) stepSize = asyncParam(request, "stepSize").toInt(); if(shadeId == 255 && groupId == 255 && !json.isNull()) { JsonObject obj = json.as(); - if(obj.containsKey("shadeId")) shadeId = obj["shadeId"]; - if(obj.containsKey("groupId")) groupId = obj["groupId"]; - if(obj.containsKey("stepSize")) stepSize = obj["stepSize"]; - if(obj.containsKey("command")) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); } - if(obj.containsKey("repeat")) repeat = obj["repeat"].as(); + if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"]; + if(!obj["groupId"].isNull()) groupId = obj["groupId"]; + if(!obj["stepSize"].isNull()) stepSize = obj["stepSize"]; + if(!obj["command"].isNull()) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); } + if(!obj["repeat"].isNull()) repeat = obj["repeat"].as(); } if(shadeId != 255) { SomfyShade *shade = somfy.getShadeById(shadeId); @@ -717,9 +717,9 @@ void Web::handleSetPositions(AsyncWebServerRequest *request, JsonVariant &json) int8_t tiltPos = asyncHasParam(request, "tiltPosition") ? asyncParam(request, "tiltPosition").toInt() : -1; if(!json.isNull()) { JsonObject obj = json.as(); - if(obj.containsKey("shadeId")) shadeId = obj["shadeId"]; - if(obj.containsKey("position")) pos = obj["position"]; - if(obj.containsKey("tiltPosition")) tiltPos = obj["tiltPosition"]; + if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"]; + if(!obj["position"].isNull()) pos = obj["position"]; + if(!obj["tiltPosition"].isNull()) tiltPos = obj["tiltPosition"]; } if(shadeId != 255) { SomfyShade *shade = somfy.getShadeById(shadeId); @@ -748,17 +748,17 @@ void Web::handleSetSensor(AsyncWebServerRequest *request, JsonVariant &json) { int8_t repeat = asyncHasParam(request, "repeat") ? asyncParam(request, "repeat").toInt() : -1; if(!json.isNull()) { JsonObject obj = json.as(); - if(obj.containsKey("shadeId")) shadeId = obj["shadeId"].as(); - if(obj.containsKey("groupId")) groupId = obj["groupId"].as(); - if(obj.containsKey("sunny")) { + if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"].as(); + if(!obj["groupId"].isNull()) groupId = obj["groupId"].as(); + if(!obj["sunny"].isNull()) { if(obj["sunny"].is()) sunny = obj["sunny"].as() ? 1 : 0; else sunny = obj["sunny"].as(); } - if(obj.containsKey("windy")) { + if(!obj["windy"].isNull()) { if(obj["windy"].is()) windy = obj["windy"].as() ? 1 : 0; else windy = obj["windy"].as(); } - if(obj.containsKey("repeat")) repeat = obj["repeat"].as(); + if(!obj["repeat"].isNull()) repeat = obj["repeat"].as(); } if(shadeId != 255) { SomfyShade *shade = somfy.getShadeById(shadeId); @@ -1214,7 +1214,7 @@ void Web::begin() { if(json.isNull()) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No room object supplied.\"}")); return; } ESP_LOGD(TAG, "Updating a room"); JsonObject obj = json.as(); - if(obj.containsKey("roomId")) { + if(!obj["roomId"].isNull()) { SomfyRoom* room = somfy.getRoomById(obj["roomId"]); if(room) { room->fromJSON(obj); @@ -1236,7 +1236,7 @@ void Web::begin() { if(json.isNull()) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade object supplied.\"}")); return; } ESP_LOGD(TAG, "Updating a shade"); JsonObject obj = json.as(); - if(obj.containsKey("shadeId")) { + if(!obj["shadeId"].isNull()) { SomfyShade* shade = somfy.getShadeById(obj["shadeId"]); if(shade) { int8_t err = shade->fromJSON(obj); @@ -1264,7 +1264,7 @@ void Web::begin() { if(json.isNull()) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No group object supplied.\"}")); return; } ESP_LOGD(TAG, "Updating a group"); JsonObject obj = json.as(); - if(obj.containsKey("groupId")) { + if(!obj["groupId"].isNull()) { SomfyGroup* group = somfy.getGroupById(obj["groupId"]); if(group) { group->fromJSON(obj); @@ -1289,10 +1289,10 @@ void Web::begin() { int8_t tilt = -1; if(!json.isNull()) { JsonObject obj = json.as(); - if(obj.containsKey("shadeId")) shadeId = obj["shadeId"]; + if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"]; else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade id was supplied.\"}")); return; } - if(obj.containsKey("pos")) pos = obj["pos"].as(); - if(obj.containsKey("tilt")) tilt = obj["tilt"].as(); + if(!obj["pos"].isNull()) pos = obj["pos"].as(); + if(!obj["tilt"].isNull()) tilt = obj["tilt"].as(); } SomfyShade* shade = somfy.getShadeById(shadeId); if(shade) { @@ -1346,8 +1346,8 @@ void Web::begin() { uint16_t rollingCode = 0; if(!json.isNull()) { JsonObject obj = json.as(); - if(obj.containsKey("shadeId")) shadeId = obj["shadeId"]; - if(obj.containsKey("rollingCode")) rollingCode = obj["rollingCode"]; + if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"]; + if(!obj["rollingCode"].isNull()) rollingCode = obj["rollingCode"]; } SomfyShade* shade = nullptr; if(shadeId != 255) shade = somfy.getShadeById(shadeId); @@ -1394,8 +1394,8 @@ void Web::begin() { bool paired = false; if(!json.isNull()) { JsonObject obj = json.as(); - if(obj.containsKey("shadeId")) shadeId = obj["shadeId"]; - if(obj.containsKey("paired")) paired = obj["paired"]; + if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"]; + if(!obj["paired"].isNull()) paired = obj["paired"]; } SomfyShade* shade = nullptr; if(shadeId != 255) shade = somfy.getShadeById(shadeId); @@ -1443,7 +1443,7 @@ void Web::begin() { uint8_t shadeId = 255; if(!json.isNull()) { JsonObject obj = json.as(); - if(obj.containsKey("shadeId")) shadeId = obj["shadeId"]; + if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"]; } SomfyShade* shade = nullptr; if(shadeId != 255) shade = somfy.getShadeById(shadeId); @@ -1497,8 +1497,8 @@ void Web::begin() { if(!json.isNull()) { ESP_LOGD(TAG, "Linking a repeater"); JsonObject obj = json.as(); - if(obj.containsKey("address")) address = obj["address"]; - else if(obj.containsKey("remoteAddress")) address = obj["remoteAddress"]; + if(!obj["address"].isNull()) address = obj["address"]; + else if(!obj["remoteAddress"].isNull()) address = obj["remoteAddress"]; } if(address == 0) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No repeater address was supplied.\"}")); @@ -1538,8 +1538,8 @@ void Web::begin() { if(!json.isNull()) { ESP_LOGD(TAG, "Unlinking a repeater"); JsonObject obj = json.as(); - if(obj.containsKey("address")) address = obj["address"]; - else if(obj.containsKey("remoteAddress")) address = obj["remoteAddress"]; + if(!obj["address"].isNull()) address = obj["address"]; + else if(!obj["remoteAddress"].isNull()) address = obj["remoteAddress"]; } if(address == 0) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No repeater address was supplied.\"}")); @@ -1577,10 +1577,10 @@ void Web::begin() { [](AsyncWebServerRequest *request, JsonVariant &json) { if(json.isNull()) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No remote object supplied.\"}")); return; } JsonObject obj = json.as(); - if(obj.containsKey("shadeId")) { + if(!obj["shadeId"].isNull()) { SomfyShade* shade = somfy.getShadeById(obj["shadeId"]); if(shade) { - if(obj.containsKey("remoteAddress")) { + if(!obj["remoteAddress"].isNull()) { shade->unlinkRemote(obj["remoteAddress"]); } else { @@ -1604,11 +1604,11 @@ void Web::begin() { if(json.isNull()) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No remote object supplied.\"}")); return; } ESP_LOGD(TAG, "Linking a remote"); JsonObject obj = json.as(); - if(obj.containsKey("shadeId")) { + if(!obj["shadeId"].isNull()) { SomfyShade* shade = somfy.getShadeById(obj["shadeId"]); if(shade) { - if(obj.containsKey("remoteAddress")) { - if(obj.containsKey("rollingCode")) shade->linkRemote(obj["remoteAddress"], obj["rollingCode"]); + if(!obj["remoteAddress"].isNull()) { + if(!obj["rollingCode"].isNull()) shade->linkRemote(obj["remoteAddress"], obj["rollingCode"]); else shade->linkRemote(obj["remoteAddress"]); } else { @@ -1632,8 +1632,8 @@ void Web::begin() { if(json.isNull()) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No linking object supplied.\"}")); return; } ESP_LOGD(TAG, "Linking a shade to a group"); JsonObject obj = json.as(); - uint8_t shadeId = obj.containsKey("shadeId") ? obj["shadeId"] : 0; - uint8_t groupId = obj.containsKey("groupId") ? obj["groupId"] : 0; + uint8_t shadeId = !obj["shadeId"].isNull() ? obj["shadeId"] : 0; + uint8_t groupId = !obj["groupId"].isNull() ? obj["groupId"] : 0; if(groupId == 0) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"Group id not provided.\"}")); return; @@ -1667,8 +1667,8 @@ void Web::begin() { if(json.isNull()) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No unlinking object supplied.\"}")); return; } ESP_LOGD(TAG, "Unlinking a shade from a group"); JsonObject obj = json.as(); - uint8_t shadeId = obj.containsKey("shadeId") ? obj["shadeId"] : 0; - uint8_t groupId = obj.containsKey("groupId") ? obj["groupId"] : 0; + uint8_t shadeId = !obj["shadeId"].isNull() ? obj["shadeId"] : 0; + uint8_t groupId = !obj["groupId"].isNull() ? obj["groupId"] : 0; if(groupId == 0) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"Group id not provided.\"}")); return; @@ -1703,7 +1703,7 @@ void Web::begin() { if(!json.isNull()) { ESP_LOGD(TAG, "Deleting a Room"); JsonObject obj = json.as(); - if(obj.containsKey("roomId")) roomId = obj["roomId"]; + if(!obj["roomId"].isNull()) roomId = obj["roomId"]; else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No room id was supplied.\"}")); return; } } SomfyRoom* room = somfy.getRoomById(roomId); @@ -1734,7 +1734,7 @@ void Web::begin() { if(!json.isNull()) { ESP_LOGD(TAG, "Deleting a shade"); JsonObject obj = json.as(); - if(obj.containsKey("shadeId")) shadeId = obj["shadeId"]; + if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"]; else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade id was supplied.\"}")); return; } } SomfyShade* shade = somfy.getShadeById(shadeId); @@ -1771,7 +1771,7 @@ void Web::begin() { if(!json.isNull()) { ESP_LOGD(TAG, "Deleting a group"); JsonObject obj = json.as(); - if(obj.containsKey("groupId")) groupId = obj["groupId"]; + if(!obj["groupId"].isNull()) groupId = obj["groupId"]; else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No group id was supplied.\"}")); return; } } SomfyGroup *group = somfy.getGroupById(groupId); @@ -2000,11 +2000,11 @@ void Web::begin() { if(!json.isNull()) { JsonObject obj = json.as(); String scmd; - if(obj.containsKey("address")) frame.remoteAddress = obj["address"]; - if(obj.containsKey("command")) scmd = obj["command"].as(); - if(obj.containsKey("repeats")) repeats = obj["repeats"]; - if(obj.containsKey("rcode")) frame.rollingCode = obj["rcode"]; - if(obj.containsKey("encKey")) frame.encKey = obj["encKey"]; + if(!obj["address"].isNull()) frame.remoteAddress = obj["address"]; + if(!obj["command"].isNull()) scmd = obj["command"].as(); + if(!obj["repeats"].isNull()) repeats = obj["repeats"]; + if(!obj["rcode"].isNull()) frame.rollingCode = obj["rcode"]; + if(!obj["encKey"].isNull()) frame.encKey = obj["encKey"]; frame.cmd = translateSomfyCommand(scmd.c_str()); } if(frame.remoteAddress > 0 && frame.rollingCode > 0) { @@ -2040,14 +2040,14 @@ void Web::begin() { return; } JsonObject obj = json.as(); - if(obj.containsKey("hostname") || obj.containsKey("ssdpBroadcast") || obj.containsKey("checkForUpdate")) { + if(!obj["hostname"].isNull() || !obj["ssdpBroadcast"].isNull() || !obj["checkForUpdate"].isNull()) { bool checkForUpdate = settings.checkForUpdate; settings.fromJSON(obj); settings.save(); if(settings.checkForUpdate != checkForUpdate) git.emitUpdateCheck(); - if(obj.containsKey("hostname")) net.updateHostname(); + if(!obj["hostname"].isNull()) net.updateHostname(); } - if(obj.containsKey("ntpServer") || obj.containsKey("ntpServer")) { + if(!obj["ntpServer"].isNull() || !obj["ntpServer"].isNull()) { settings.NTP.fromJSON(obj); settings.NTP.save(); } @@ -2063,25 +2063,25 @@ void Web::begin() { } JsonObject obj = json.as(); bool reboot = false; - if(obj.containsKey("connType") && obj["connType"].as() != static_cast(settings.connType)) { + if(!obj["connType"].isNull() && obj["connType"].as() != static_cast(settings.connType)) { settings.connType = static_cast(obj["connType"].as()); settings.save(); reboot = true; } - if(obj.containsKey("wifi")) { + if(!obj["wifi"].isNull()) { JsonObject objWifi = obj["wifi"]; if(settings.connType == conn_types_t::wifi) { - if(objWifi.containsKey("ssid") && objWifi["ssid"].as().compareTo(settings.WIFI.ssid) != 0) { + if(!objWifi["ssid"].isNull() && objWifi["ssid"].as().compareTo(settings.WIFI.ssid) != 0) { if(WiFi.softAPgetStationNum() == 0) reboot = true; } - if(objWifi.containsKey("passphrase") && objWifi["passphrase"].as().compareTo(settings.WIFI.passphrase) != 0) { + if(!objWifi["passphrase"].isNull() && objWifi["passphrase"].as().compareTo(settings.WIFI.passphrase) != 0) { if(WiFi.softAPgetStationNum() == 0) reboot = true; } } settings.WIFI.fromJSON(objWifi); settings.WIFI.save(); } - if(obj.containsKey("ethernet")) { + if(!obj["ethernet"].isNull()) { JsonObject objEth = obj["ethernet"]; if(settings.connType == conn_types_t::ethernet || settings.connType == conn_types_t::ethernetpref) reboot = true; @@ -2121,8 +2121,8 @@ void Web::begin() { ESP_LOGD(TAG, "Settings WIFI connection..."); String ssid = ""; String passphrase = ""; - if(obj.containsKey("ssid")) ssid = obj["ssid"].as(); - if(obj.containsKey("passphrase")) passphrase = obj["passphrase"].as(); + if(!obj["ssid"].isNull()) ssid = obj["ssid"].as(); + if(!obj["passphrase"].isNull()) passphrase = obj["passphrase"].as(); bool reboot = false; if(ssid.compareTo(settings.WIFI.ssid) != 0) reboot = true; if(passphrase.compareTo(settings.WIFI.passphrase) != 0) reboot = true;