Merge pull request #3 from cjkas/scz/123

Cleanup build warnings
This commit is contained in:
cjkas 2026-03-25 07:53:34 +01:00 committed by GitHub
commit 6679d5944f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 177 additions and 177 deletions

View file

@ -13,12 +13,12 @@ static const char *TAG = "Config";
Preferences pref; Preferences pref;
void restore_options_t::fromJSON(JsonObject &obj) { void restore_options_t::fromJSON(JsonObject &obj) {
if(obj.containsKey("shades")) this->shades = obj["shades"]; if(!obj["shades"].isNull()) this->shades = obj["shades"];
if(obj.containsKey("settings")) this->settings = obj["settings"]; if(!obj["settings"].isNull()) this->settings = obj["settings"];
if(obj.containsKey("network")) this->network = obj["network"]; if(!obj["network"].isNull()) this->network = obj["network"];
if(obj.containsKey("transceiver")) this->transceiver = obj["transceiver"]; if(!obj["transceiver"].isNull()) this->transceiver = obj["transceiver"];
if(obj.containsKey("repeaters")) this->repeaters = obj["repeaters"]; if(!obj["repeaters"].isNull()) this->repeaters = obj["repeaters"];
if(obj.containsKey("mqtt")) this->mqtt = obj["mqtt"]; if(!obj["mqtt"].isNull()) this->mqtt = obj["mqtt"];
} }
int8_t appver_t::compare(appver_t &ver) { int8_t appver_t::compare(appver_t &ver) {
if(this->major == ver.major && this->minor == ver.minor && this->build == ver.build) return 0; 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; return true;
} }
bool BaseSettings::parseValueString(JsonObject &obj, const char *prop, char *pdest, size_t size) { 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; return true;
} }
bool BaseSettings::parseIPAddress(JsonObject &obj, const char *prop, IPAddress *pdest) { bool BaseSettings::parseIPAddress(JsonObject &obj, const char *prop, IPAddress *pdest) {
if(obj.containsKey(prop)) { if(!obj[prop].isNull()) {
char buff[16]; char buff[16];
strlcpy(buff, obj[prop], sizeof(buff)); strlcpy(buff, obj[prop], sizeof(buff));
pdest->fromString(buff); pdest->fromString(buff);
@ -137,11 +137,11 @@ bool BaseSettings::parseIPAddress(JsonObject &obj, const char *prop, IPAddress *
return true; return true;
} }
int BaseSettings::parseValueInt(JsonObject &obj, const char *prop, int defVal) { 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; return defVal;
} }
double BaseSettings::parseValueDouble(JsonObject &obj, const char *prop, double 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; return defVal;
} }
bool ConfigSettings::begin() { bool ConfigSettings::begin() {
@ -247,10 +247,10 @@ bool ConfigSettings::toJSON(JsonObject &obj) {
} }
bool ConfigSettings::requiresAuth() { return this->Security.type != security_types::None; } bool ConfigSettings::requiresAuth() { return this->Security.type != security_types::None; }
bool ConfigSettings::fromJSON(JsonObject &obj) { bool ConfigSettings::fromJSON(JsonObject &obj) {
if(obj.containsKey("ssdpBroadcast")) this->ssdpBroadcast = obj["ssdpBroadcast"]; if(!obj["ssdpBroadcast"].isNull()) this->ssdpBroadcast = obj["ssdpBroadcast"];
if(obj.containsKey("hostname")) this->parseValueString(obj, "hostname", this->hostname, sizeof(this->hostname)); if(!obj["hostname"].isNull()) this->parseValueString(obj, "hostname", this->hostname, sizeof(this->hostname));
if(obj.containsKey("connType")) this->connType = static_cast<conn_types_t>(obj["connType"].as<uint8_t>()); if(!obj["connType"].isNull()) this->connType = static_cast<conn_types_t>(obj["connType"].as<uint8_t>());
if(obj.containsKey("checkForUpdate")) this->checkForUpdate = obj["checkForUpdate"]; if(!obj["checkForUpdate"].isNull()) this->checkForUpdate = obj["checkForUpdate"];
return true; return true;
} }
void ConfigSettings::print() { void ConfigSettings::print() {
@ -309,15 +309,15 @@ bool MQTTSettings::toJSON(JsonObject &obj) {
return true; return true;
} }
bool MQTTSettings::fromJSON(JsonObject &obj) { bool MQTTSettings::fromJSON(JsonObject &obj) {
if(obj.containsKey("enabled")) this->enabled = obj["enabled"]; if(!obj["enabled"].isNull()) this->enabled = obj["enabled"];
if(obj.containsKey("pubDisco")) this->pubDisco = obj["pubDisco"]; if(!obj["pubDisco"].isNull()) this->pubDisco = obj["pubDisco"];
this->parseValueString(obj, "protocol", this->protocol, sizeof(this->protocol)); this->parseValueString(obj, "protocol", this->protocol, sizeof(this->protocol));
this->parseValueString(obj, "hostname", this->hostname, sizeof(this->hostname)); this->parseValueString(obj, "hostname", this->hostname, sizeof(this->hostname));
this->parseValueString(obj, "username", this->username, sizeof(this->username)); this->parseValueString(obj, "username", this->username, sizeof(this->username));
this->parseValueString(obj, "password", this->password, sizeof(this->password)); this->parseValueString(obj, "password", this->password, sizeof(this->password));
this->parseValueString(obj, "rootTopic", this->rootTopic, sizeof(this->rootTopic)); this->parseValueString(obj, "rootTopic", this->rootTopic, sizeof(this->rootTopic));
this->parseValueString(obj, "discoTopic", this->discoTopic, sizeof(this->discoTopic)); 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; return true;
} }
bool MQTTSettings::save() { bool MQTTSettings::save() {
@ -409,7 +409,7 @@ bool IPSettings::begin() {
return true; return true;
} }
bool IPSettings::fromJSON(JsonObject &obj) { 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, "ip", &this->ip);
this->parseIPAddress(obj, "gateway", &this->gateway); this->parseIPAddress(obj, "gateway", &this->gateway);
this->parseIPAddress(obj, "subnet", &this->subnet); this->parseIPAddress(obj, "subnet", &this->subnet);
@ -472,11 +472,11 @@ bool SecuritySettings::begin() {
return true; return true;
} }
bool SecuritySettings::fromJSON(JsonObject &obj) { bool SecuritySettings::fromJSON(JsonObject &obj) {
if(obj.containsKey("type")) this->type = static_cast<security_types>(obj["type"].as<uint8_t>()); if(!obj["type"].isNull()) this->type = static_cast<security_types>(obj["type"].as<uint8_t>());
this->parseValueString(obj, "username", this->username, sizeof(this->username)); this->parseValueString(obj, "username", this->username, sizeof(this->username));
this->parseValueString(obj, "password", this->password, sizeof(this->password)); this->parseValueString(obj, "password", this->password, sizeof(this->password));
this->parseValueString(obj, "pin", this->pin, sizeof(this->pin)); 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; return true;
} }
bool SecuritySettings::toJSON(JsonObject &obj) { bool SecuritySettings::toJSON(JsonObject &obj) {
@ -521,8 +521,8 @@ bool WifiSettings::begin() {
bool WifiSettings::fromJSON(JsonObject &obj) { bool WifiSettings::fromJSON(JsonObject &obj) {
this->parseValueString(obj, "ssid", this->ssid, sizeof(this->ssid)); this->parseValueString(obj, "ssid", this->ssid, sizeof(this->ssid));
this->parseValueString(obj, "passphrase", this->passphrase, sizeof(this->passphrase)); this->parseValueString(obj, "passphrase", this->passphrase, sizeof(this->passphrase));
if(obj.containsKey("roaming")) this->roaming = obj["roaming"]; if(!obj["roaming"].isNull()) this->roaming = obj["roaming"];
if(obj.containsKey("hidden")) this->hidden = obj["hidden"]; if(!obj["hidden"].isNull()) this->hidden = obj["hidden"];
return true; return true;
} }
bool WifiSettings::toJSON(JsonObject &obj) { bool WifiSettings::toJSON(JsonObject &obj) {
@ -596,13 +596,13 @@ bool EthernetSettings::begin() {
return true; return true;
} }
bool EthernetSettings::fromJSON(JsonObject &obj) { bool EthernetSettings::fromJSON(JsonObject &obj) {
if(obj.containsKey("boardType")) this->boardType = obj["boardType"]; if(!obj["boardType"].isNull()) this->boardType = obj["boardType"];
if(obj.containsKey("phyAddress")) this->phyAddress = obj["phyAddress"]; if(!obj["phyAddress"].isNull()) this->phyAddress = obj["phyAddress"];
if(obj.containsKey("CLKMode")) this->CLKMode = static_cast<eth_clock_mode_t>(obj["CLKMode"]); if(!obj["CLKMode"].isNull()) this->CLKMode = static_cast<eth_clock_mode_t>(obj["CLKMode"]);
if(obj.containsKey("phyType")) this->phyType = static_cast<eth_phy_type_t>(obj["phyType"]); if(!obj["phyType"].isNull()) this->phyType = static_cast<eth_phy_type_t>(obj["phyType"]);
if(obj.containsKey("PWRPin")) this->PWRPin = obj["PWRPin"]; if(!obj["PWRPin"].isNull()) this->PWRPin = obj["PWRPin"];
if(obj.containsKey("MDCPin")) this->MDCPin = obj["MDCPin"]; if(!obj["MDCPin"].isNull()) this->MDCPin = obj["MDCPin"];
if(obj.containsKey("MDIOPin")) this->MDIOPin = obj["MDIOPin"]; if(!obj["MDIOPin"].isNull()) this->MDIOPin = obj["MDIOPin"];
return true; return true;
} }
bool EthernetSettings::toJSON(JsonObject &obj) { bool EthernetSettings::toJSON(JsonObject &obj) {

View file

@ -3105,7 +3105,7 @@ bool SomfyShade::usesPin(uint8_t pin) {
int8_t SomfyShade::validateJSON(JsonObject &obj) { int8_t SomfyShade::validateJSON(JsonObject &obj) {
int8_t ret = 0; int8_t ret = 0;
shade_types type = this->shadeType; shade_types type = this->shadeType;
if(obj.containsKey("shadeType")) { if(!obj["shadeType"].isNull()) {
if(obj["shadeType"].is<const char *>()) { if(obj["shadeType"].is<const char *>()) {
if(strncmp(obj["shadeType"].as<const char *>(), "roller", 7) == 0) if(strncmp(obj["shadeType"].as<const char *>(), "roller", 7) == 0)
type = shade_types::roller; type = shade_types::roller;
@ -3134,14 +3134,14 @@ int8_t SomfyShade::validateJSON(JsonObject &obj) {
this->shadeType = static_cast<shade_types>(obj["shadeType"].as<uint8_t>()); this->shadeType = static_cast<shade_types>(obj["shadeType"].as<uint8_t>());
} }
} }
if(obj.containsKey("proto")) { if(!obj["proto"].isNull()) {
radio_proto proto = this->proto; radio_proto proto = this->proto;
if(proto == radio_proto::GP_Relay || proto == radio_proto::GP_Remote) { if(proto == radio_proto::GP_Relay || proto == radio_proto::GP_Remote) {
// Check to see if we are using the up and or down // Check to see if we are using the up and or down
// GPIOs anywhere else. // GPIOs anywhere else.
uint8_t upPin = obj.containsKey("gpioUp") ? obj["gpioUp"].as<uint8_t>() : this->gpioUp; uint8_t upPin = !obj["gpioUp"].isNull() ? obj["gpioUp"].as<uint8_t>() : this->gpioUp;
uint8_t downPin = obj.containsKey("gpioDown") ? obj["gpioDown"].as<uint8_t>() : this->gpioDown; uint8_t downPin = !obj["gpioDown"].isNull() ? obj["gpioDown"].as<uint8_t>() : this->gpioDown;
uint8_t myPin = obj.containsKey("gpioMy") ? obj["gpioMy"].as<uint8_t>() : this->gpioMy; uint8_t myPin = !obj["gpioMy"].isNull() ? obj["gpioMy"].as<uint8_t>() : this->gpioMy;
if(type == shade_types::drycontact || if(type == shade_types::drycontact ||
((type == shade_types::garage1 || type == shade_types::lgate1 || type == shade_types::cgate1 || type == shade_types::rgate1) ((type == shade_types::garage1 || type == shade_types::lgate1 || type == shade_types::cgate1 || type == shade_types::rgate1)
&& proto == radio_proto::GP_Remote)) upPin = myPin = 255; && 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 SomfyShade::fromJSON(JsonObject &obj) {
int8_t err = this->validateJSON(obj); int8_t err = this->validateJSON(obj);
if(err == 0) { if(err == 0) {
if(obj.containsKey("name")) strlcpy(this->name, obj["name"], sizeof(this->name)); if(!obj["name"].isNull()) strlcpy(this->name, obj["name"], sizeof(this->name));
if(obj.containsKey("roomId")) this->roomId = obj["roomId"]; if(!obj["roomId"].isNull()) this->roomId = obj["roomId"];
if(obj.containsKey("upTime")) this->upTime = obj["upTime"]; if(!obj["upTime"].isNull()) this->upTime = obj["upTime"];
if(obj.containsKey("downTime")) this->downTime = obj["downTime"]; if(!obj["downTime"].isNull()) this->downTime = obj["downTime"];
if(obj.containsKey("remoteAddress")) this->setRemoteAddress(obj["remoteAddress"]); if(!obj["remoteAddress"].isNull()) this->setRemoteAddress(obj["remoteAddress"]);
if(obj.containsKey("tiltTime")) this->tiltTime = obj["tiltTime"]; if(!obj["tiltTime"].isNull()) this->tiltTime = obj["tiltTime"];
if(obj.containsKey("stepSize")) this->stepSize = obj["stepSize"]; if(!obj["stepSize"].isNull()) this->stepSize = obj["stepSize"];
if(obj.containsKey("hasTilt")) this->tiltType = static_cast<bool>(obj["hasTilt"]) ? tilt_types::none : tilt_types::tiltmotor; if(!obj["hasTilt"].isNull()) this->tiltType = static_cast<bool>(obj["hasTilt"]) ? tilt_types::none : tilt_types::tiltmotor;
if(obj.containsKey("bitLength")) this->bitLength = obj["bitLength"]; if(!obj["bitLength"].isNull()) this->bitLength = obj["bitLength"];
if(obj.containsKey("proto")) this->proto = static_cast<radio_proto>(obj["proto"].as<uint8_t>()); if(!obj["proto"].isNull()) this->proto = static_cast<radio_proto>(obj["proto"].as<uint8_t>());
if(obj.containsKey("sunSensor")) this->setSunSensor(obj["sunSensor"]); if(!obj["sunSensor"].isNull()) this->setSunSensor(obj["sunSensor"]);
if(obj.containsKey("simMy")) this->setSimMy(obj["simMy"]); if(!obj["simMy"].isNull()) this->setSimMy(obj["simMy"]);
if(obj.containsKey("light")) this->setLight(obj["light"]); if(!obj["light"].isNull()) this->setLight(obj["light"]);
if(obj.containsKey("gpioFlags")) this->gpioFlags = obj["gpioFlags"]; if(!obj["gpioFlags"].isNull()) this->gpioFlags = obj["gpioFlags"];
if(obj.containsKey("gpioLLTrigger")) { if(!obj["gpioLLTrigger"].isNull()) {
if(obj["gpioLLTrigger"].as<bool>()) if(obj["gpioLLTrigger"].as<bool>())
this->gpioFlags |= (uint8_t)gpio_flags_t::LowLevelTrigger; this->gpioFlags |= (uint8_t)gpio_flags_t::LowLevelTrigger;
else else
this->gpioFlags &= ~(uint8_t)gpio_flags_t::LowLevelTrigger; this->gpioFlags &= ~(uint8_t)gpio_flags_t::LowLevelTrigger;
} }
if(obj.containsKey("shadeType")) { if(!obj["shadeType"].isNull()) {
if(obj["shadeType"].is<const char *>()) { if(obj["shadeType"].is<const char *>()) {
if(strncmp(obj["shadeType"].as<const char *>(), "roller", 7) == 0) if(strncmp(obj["shadeType"].as<const char *>(), "roller", 7) == 0)
this->shadeType = shade_types::roller; this->shadeType = shade_types::roller;
@ -3228,10 +3228,10 @@ int8_t SomfyShade::fromJSON(JsonObject &obj) {
this->shadeType = static_cast<shade_types>(obj["shadeType"].as<uint8_t>()); this->shadeType = static_cast<shade_types>(obj["shadeType"].as<uint8_t>());
} }
} }
if(obj.containsKey("flipCommands")) this->flipCommands = obj["flipCommands"].as<bool>(); if(!obj["flipCommands"].isNull()) this->flipCommands = obj["flipCommands"].as<bool>();
if(obj.containsKey("flipPosition")) this->flipPosition = obj["flipPosition"].as<bool>(); if(!obj["flipPosition"].isNull()) this->flipPosition = obj["flipPosition"].as<bool>();
if(obj.containsKey("repeats")) this->repeats = obj["repeats"]; if(!obj["repeats"].isNull()) this->repeats = obj["repeats"];
if(obj.containsKey("tiltType")) { if(!obj["tiltType"].isNull()) {
if(obj["tiltType"].is<const char *>()) { if(obj["tiltType"].is<const char *>()) {
if(strncmp(obj["tiltType"].as<const char *>(), "none", 4) == 0) if(strncmp(obj["tiltType"].as<const char *>(), "none", 4) == 0)
this->tiltType = tilt_types::none; this->tiltType = tilt_types::none;
@ -3246,7 +3246,7 @@ int8_t SomfyShade::fromJSON(JsonObject &obj) {
this->tiltType = static_cast<tilt_types>(obj["tiltType"].as<uint8_t>()); this->tiltType = static_cast<tilt_types>(obj["tiltType"].as<uint8_t>());
} }
} }
if(obj.containsKey("linkedAddresses")) { if(!obj["linkedAddresses"].isNull()) {
uint32_t linkedAddresses[SOMFY_MAX_LINKED_REMOTES]; uint32_t linkedAddresses[SOMFY_MAX_LINKED_REMOTES];
memset(linkedAddresses, 0x00, sizeof(linkedAddresses)); memset(linkedAddresses, 0x00, sizeof(linkedAddresses));
JsonArray arr = obj["linkedAddresses"]; JsonArray arr = obj["linkedAddresses"];
@ -3258,15 +3258,15 @@ int8_t SomfyShade::fromJSON(JsonObject &obj) {
this->linkedRemotes[j].setRemoteAddress(linkedAddresses[j]); 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(this->proto == radio_proto::GP_Remote || this->proto == radio_proto::GP_Relay) {
if(obj.containsKey("gpioUp")) this->gpioUp = obj["gpioUp"]; if(!obj["gpioUp"].isNull()) this->gpioUp = obj["gpioUp"];
if(obj.containsKey("gpioDown")) this->gpioDown = obj["gpioDown"]; if(!obj["gpioDown"].isNull()) this->gpioDown = obj["gpioDown"];
pinMode(this->gpioUp, OUTPUT); pinMode(this->gpioUp, OUTPUT);
pinMode(this->gpioDown, OUTPUT); pinMode(this->gpioDown, OUTPUT);
} }
if(this->proto == radio_proto::GP_Remote) { 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); pinMode(this->gpioMy, OUTPUT);
} }
} }
@ -3327,8 +3327,8 @@ bool SomfyShade::toJSON(JsonObject &obj) {
} }
*/ */
bool SomfyRoom::fromJSON(JsonObject &obj) { bool SomfyRoom::fromJSON(JsonObject &obj) {
if(obj.containsKey("name")) strlcpy(this->name, obj["name"], sizeof(this->name)); if(!obj["name"].isNull()) strlcpy(this->name, obj["name"], sizeof(this->name));
if(obj.containsKey("sortOrder")) this->sortOrder = obj["sortOrder"]; if(!obj["sortOrder"].isNull()) this->sortOrder = obj["sortOrder"];
return true; return true;
} }
/* /*
@ -3340,16 +3340,16 @@ bool SomfyRoom::toJSON(JsonObject &obj) {
} }
*/ */
bool SomfyGroup::fromJSON(JsonObject &obj) { bool SomfyGroup::fromJSON(JsonObject &obj) {
if(obj.containsKey("name")) strlcpy(this->name, obj["name"], sizeof(this->name)); if(!obj["name"].isNull()) strlcpy(this->name, obj["name"], sizeof(this->name));
if(obj.containsKey("roomId")) this->roomId = obj["roomId"]; if(!obj["roomId"].isNull()) this->roomId = obj["roomId"];
if(obj.containsKey("remoteAddress")) this->setRemoteAddress(obj["remoteAddress"]); if(!obj["remoteAddress"].isNull()) this->setRemoteAddress(obj["remoteAddress"]);
if(obj.containsKey("bitLength")) this->bitLength = obj["bitLength"]; if(!obj["bitLength"].isNull()) this->bitLength = obj["bitLength"];
if(obj.containsKey("proto")) this->proto = static_cast<radio_proto>(obj["proto"].as<uint8_t>()); if(!obj["proto"].isNull()) this->proto = static_cast<radio_proto>(obj["proto"].as<uint8_t>());
if(obj.containsKey("flipCommands")) this->flipCommands = obj["flipCommands"].as<bool>(); if(!obj["flipCommands"].isNull()) this->flipCommands = obj["flipCommands"].as<bool>();
//if(obj.containsKey("sunSensor")) this->hasSunSensor() = obj["sunSensor"]; This is calculated //if(!obj["sunSensor"].isNull()) this->hasSunSensor() = obj["sunSensor"]; This is calculated
if(obj.containsKey("repeats")) this->repeats = obj["repeats"]; if(!obj["repeats"].isNull()) this->repeats = obj["repeats"];
if(obj.containsKey("linkedShades")) { if(!obj["linkedShades"].isNull()) {
uint8_t linkedShades[SOMFY_MAX_GROUPED_SHADES]; uint8_t linkedShades[SOMFY_MAX_GROUPED_SHADES];
memset(linkedShades, 0x00, sizeof(linkedShades)); memset(linkedShades, 0x00, sizeof(linkedShades));
JsonArray arr = obj["linkedShades"]; JsonArray arr = obj["linkedShades"];
@ -4485,7 +4485,7 @@ bool Transceiver::toJSON(JsonObject& obj) {
} }
*/ */
bool Transceiver::fromJSON(JsonObject& obj) { bool Transceiver::fromJSON(JsonObject& obj) {
if (obj.containsKey("config")) { if (!obj["config"].isNull()) {
JsonObject objConfig = obj["config"]; JsonObject objConfig = obj["config"];
this->config.fromJSON(objConfig); this->config.fromJSON(objConfig);
} }
@ -4514,43 +4514,43 @@ bool Transceiver::end() {
} }
void transceiver_config_t::fromJSON(JsonObject& obj) { void transceiver_config_t::fromJSON(JsonObject& obj) {
//Serial.print("Deserialize Radio JSON "); //Serial.print("Deserialize Radio JSON ");
if(obj.containsKey("type")) this->type = obj["type"]; if(!obj["type"].isNull()) this->type = obj["type"];
if(obj.containsKey("CSNPin")) this->CSNPin = obj["CSNPin"]; if(!obj["CSNPin"].isNull()) this->CSNPin = obj["CSNPin"];
if(obj.containsKey("MISOPin")) this->MISOPin = obj["MISOPin"]; if(!obj["MISOPin"].isNull()) this->MISOPin = obj["MISOPin"];
if(obj.containsKey("MOSIPin")) this->MOSIPin = obj["MOSIPin"]; if(!obj["MOSIPin"].isNull()) this->MOSIPin = obj["MOSIPin"];
if(obj.containsKey("RXPin")) this->RXPin = obj["RXPin"]; if(!obj["RXPin"].isNull()) this->RXPin = obj["RXPin"];
if(obj.containsKey("SCKPin")) this->SCKPin = obj["SCKPin"]; if(!obj["SCKPin"].isNull()) this->SCKPin = obj["SCKPin"];
if(obj.containsKey("TXPin")) this->TXPin = obj["TXPin"]; if(!obj["TXPin"].isNull()) this->TXPin = obj["TXPin"];
if(obj.containsKey("rxBandwidth")) this->rxBandwidth = obj["rxBandwidth"]; // float if(!obj["rxBandwidth"].isNull()) this->rxBandwidth = obj["rxBandwidth"]; // float
if(obj.containsKey("frequency")) this->frequency = obj["frequency"]; // float if(!obj["frequency"].isNull()) this->frequency = obj["frequency"]; // float
if(obj.containsKey("deviation")) this->deviation = obj["deviation"]; // float if(!obj["deviation"].isNull()) this->deviation = obj["deviation"]; // float
if(obj.containsKey("enabled")) this->enabled = obj["enabled"]; if(!obj["enabled"].isNull()) this->enabled = obj["enabled"];
if(obj.containsKey("txPower")) this->txPower = obj["txPower"]; if(!obj["txPower"].isNull()) this->txPower = obj["txPower"];
if(obj.containsKey("proto")) this->proto = static_cast<radio_proto>(obj["proto"].as<uint8_t>()); if(!obj["proto"].isNull()) this->proto = static_cast<radio_proto>(obj["proto"].as<uint8_t>());
/* /*
if (obj.containsKey("internalCCMode")) this->internalCCMode = obj["internalCCMode"]; if (!obj["internalCCMode"].isNull()) this->internalCCMode = obj["internalCCMode"];
if (obj.containsKey("modulationMode")) this->modulationMode = obj["modulationMode"]; if (!obj["modulationMode"].isNull()) this->modulationMode = obj["modulationMode"];
if (obj.containsKey("channel")) this->channel = obj["channel"]; if (!obj["channel"].isNull()) this->channel = obj["channel"];
if (obj.containsKey("channelSpacing")) this->channelSpacing = obj["channelSpacing"]; // float if (!obj["channelSpacing"].isNull()) this->channelSpacing = obj["channelSpacing"]; // float
if (obj.containsKey("dataRate")) this->dataRate = obj["dataRate"]; // float if (!obj["dataRate"].isNull()) this->dataRate = obj["dataRate"]; // float
if (obj.containsKey("syncMode")) this->syncMode = obj["syncMode"]; if (!obj["syncMode"].isNull()) this->syncMode = obj["syncMode"];
if (obj.containsKey("syncWordHigh")) this->syncWordHigh = obj["syncWordHigh"]; if (!obj["syncWordHigh"].isNull()) this->syncWordHigh = obj["syncWordHigh"];
if (obj.containsKey("syncWordLow")) this->syncWordLow = obj["syncWordLow"]; if (!obj["syncWordLow"].isNull()) this->syncWordLow = obj["syncWordLow"];
if (obj.containsKey("addrCheckMode")) this->addrCheckMode = obj["addrCheckMode"]; if (!obj["addrCheckMode"].isNull()) this->addrCheckMode = obj["addrCheckMode"];
if (obj.containsKey("checkAddr")) this->checkAddr = obj["checkAddr"]; if (!obj["checkAddr"].isNull()) this->checkAddr = obj["checkAddr"];
if (obj.containsKey("dataWhitening")) this->dataWhitening = obj["dataWhitening"]; if (!obj["dataWhitening"].isNull()) this->dataWhitening = obj["dataWhitening"];
if (obj.containsKey("pktFormat")) this->pktFormat = obj["pktFormat"]; if (!obj["pktFormat"].isNull()) this->pktFormat = obj["pktFormat"];
if (obj.containsKey("pktLengthMode")) this->pktLengthMode = obj["pktLengthMode"]; if (!obj["pktLengthMode"].isNull()) this->pktLengthMode = obj["pktLengthMode"];
if (obj.containsKey("pktLength")) this->pktLength = obj["pktLength"]; if (!obj["pktLength"].isNull()) this->pktLength = obj["pktLength"];
if (obj.containsKey("useCRC")) this->useCRC = obj["useCRC"]; if (!obj["useCRC"].isNull()) this->useCRC = obj["useCRC"];
if (obj.containsKey("autoFlushCRC")) this->autoFlushCRC = obj["autoFlushCRC"]; if (!obj["autoFlushCRC"].isNull()) this->autoFlushCRC = obj["autoFlushCRC"];
if (obj.containsKey("disableDCFilter")) this->disableDCFilter = obj["disableCRCFilter"]; if (!obj["disableDCFilter"].isNull()) this->disableDCFilter = obj["disableCRCFilter"];
if (obj.containsKey("enableManchester")) this->enableManchester = obj["enableManchester"]; if (!obj["enableManchester"].isNull()) this->enableManchester = obj["enableManchester"];
if (obj.containsKey("enableFEC")) this->enableFEC = obj["enableFEC"]; if (!obj["enableFEC"].isNull()) this->enableFEC = obj["enableFEC"];
if (obj.containsKey("minPreambleBytes")) this->minPreambleBytes = obj["minPreambleBytes"]; if (!obj["minPreambleBytes"].isNull()) this->minPreambleBytes = obj["minPreambleBytes"];
if (obj.containsKey("pqtThreshold")) this->pqtThreshold = obj["pqtThreshold"]; if (!obj["pqtThreshold"].isNull()) this->pqtThreshold = obj["pqtThreshold"];
if (obj.containsKey("appendStatus")) this->appendStatus = obj["appendStatus"]; if (!obj["appendStatus"].isNull()) this->appendStatus = obj["appendStatus"];
if (obj.containsKey("printBuffer")) this->printBuffer = obj["printBuffer"]; 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); 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);
} }

View file

@ -463,9 +463,9 @@ void Web::handleLogin(AsyncWebServerRequest *request, JsonVariant &json) {
// Override from JSON body if present // Override from JSON body if present
if(!json.isNull()) { if(!json.isNull()) {
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("username")) strlcpy(username, obj["username"], sizeof(username)); if(!obj["username"].isNull()) strlcpy(username, obj["username"], sizeof(username));
if(obj.containsKey("password")) strlcpy(password, obj["password"], sizeof(password)); if(!obj["password"].isNull()) strlcpy(password, obj["password"], sizeof(password));
if(obj.containsKey("pin")) strlcpy(pin, obj["pin"], sizeof(pin)); if(!obj["pin"].isNull()) strlcpy(pin, obj["pin"], sizeof(pin));
} }
bool success = false; bool success = false;
if(settings.Security.type == security_types::PinEntry) { if(settings.Security.type == security_types::PinEntry) {
@ -511,12 +511,12 @@ void Web::handleShadeCommand(AsyncWebServerRequest *request, JsonVariant &json)
} }
else if(!json.isNull()) { else if(!json.isNull()) {
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
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; } 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); } if(!obj["command"].isNull()) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); }
else if(obj.containsKey("target")) target = obj["target"].as<uint8_t>(); else if(!obj["target"].isNull()) target = obj["target"].as<uint8_t>();
if(obj.containsKey("repeat")) repeat = obj["repeat"].as<uint8_t>(); if(!obj["repeat"].isNull()) repeat = obj["repeat"].as<uint8_t>();
if(obj.containsKey("stepSize")) stepSize = obj["stepSize"].as<uint8_t>(); if(!obj["stepSize"].isNull()) stepSize = obj["stepSize"].as<uint8_t>();
} }
else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade object supplied.\"}")); return; } else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade object supplied.\"}")); return; }
SomfyShade *shade = somfy.getShadeById(shadeId); SomfyShade *shade = somfy.getShadeById(shadeId);
@ -547,11 +547,11 @@ void Web::handleGroupCommand(AsyncWebServerRequest *request, JsonVariant &json)
} }
else if(!json.isNull()) { else if(!json.isNull()) {
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
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; } 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["command"].isNull()) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); }
if(obj.containsKey("repeat")) repeat = obj["repeat"].as<uint8_t>(); if(!obj["repeat"].isNull()) repeat = obj["repeat"].as<uint8_t>();
if(obj.containsKey("stepSize")) stepSize = obj["stepSize"].as<uint8_t>(); if(!obj["stepSize"].isNull()) stepSize = obj["stepSize"].as<uint8_t>();
} }
else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No group object supplied.\"}")); return; } else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No group object supplied.\"}")); return; }
SomfyGroup *group = somfy.getGroupById(groupId); SomfyGroup *group = somfy.getGroupById(groupId);
@ -579,10 +579,10 @@ void Web::handleTiltCommand(AsyncWebServerRequest *request, JsonVariant &json) {
} }
else if(!json.isNull()) { else if(!json.isNull()) {
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
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; } 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); } if(!obj["command"].isNull()) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); }
else if(obj.containsKey("target")) target = obj["target"].as<uint8_t>(); else if(!obj["target"].isNull()) target = obj["target"].as<uint8_t>();
} }
else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade object supplied.\"}")); return; } else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade object supplied.\"}")); return; }
SomfyShade *shade = somfy.getShadeById(shadeId); 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(asyncHasParam(request, "stepSize")) stepSize = asyncParam(request, "stepSize").toInt();
if(shadeId == 255 && groupId == 255 && !json.isNull()) { if(shadeId == 255 && groupId == 255 && !json.isNull()) {
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("shadeId")) shadeId = obj["shadeId"]; if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"];
if(obj.containsKey("groupId")) groupId = obj["groupId"]; if(!obj["groupId"].isNull()) groupId = obj["groupId"];
if(obj.containsKey("stepSize")) stepSize = obj["stepSize"]; if(!obj["stepSize"].isNull()) stepSize = obj["stepSize"];
if(obj.containsKey("command")) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); } if(!obj["command"].isNull()) { String scmd = obj["command"]; command = translateSomfyCommand(scmd); }
if(obj.containsKey("repeat")) repeat = obj["repeat"].as<uint8_t>(); if(!obj["repeat"].isNull()) repeat = obj["repeat"].as<uint8_t>();
} }
if(shadeId != 255) { if(shadeId != 255) {
SomfyShade *shade = somfy.getShadeById(shadeId); 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; int8_t tiltPos = asyncHasParam(request, "tiltPosition") ? asyncParam(request, "tiltPosition").toInt() : -1;
if(!json.isNull()) { if(!json.isNull()) {
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("shadeId")) shadeId = obj["shadeId"]; if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"];
if(obj.containsKey("position")) pos = obj["position"]; if(!obj["position"].isNull()) pos = obj["position"];
if(obj.containsKey("tiltPosition")) tiltPos = obj["tiltPosition"]; if(!obj["tiltPosition"].isNull()) tiltPos = obj["tiltPosition"];
} }
if(shadeId != 255) { if(shadeId != 255) {
SomfyShade *shade = somfy.getShadeById(shadeId); 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; int8_t repeat = asyncHasParam(request, "repeat") ? asyncParam(request, "repeat").toInt() : -1;
if(!json.isNull()) { if(!json.isNull()) {
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("shadeId")) shadeId = obj["shadeId"].as<uint8_t>(); if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"].as<uint8_t>();
if(obj.containsKey("groupId")) groupId = obj["groupId"].as<uint8_t>(); if(!obj["groupId"].isNull()) groupId = obj["groupId"].as<uint8_t>();
if(obj.containsKey("sunny")) { if(!obj["sunny"].isNull()) {
if(obj["sunny"].is<bool>()) sunny = obj["sunny"].as<bool>() ? 1 : 0; if(obj["sunny"].is<bool>()) sunny = obj["sunny"].as<bool>() ? 1 : 0;
else sunny = obj["sunny"].as<int8_t>(); else sunny = obj["sunny"].as<int8_t>();
} }
if(obj.containsKey("windy")) { if(!obj["windy"].isNull()) {
if(obj["windy"].is<bool>()) windy = obj["windy"].as<bool>() ? 1 : 0; if(obj["windy"].is<bool>()) windy = obj["windy"].as<bool>() ? 1 : 0;
else windy = obj["windy"].as<int8_t>(); else windy = obj["windy"].as<int8_t>();
} }
if(obj.containsKey("repeat")) repeat = obj["repeat"].as<uint8_t>(); if(!obj["repeat"].isNull()) repeat = obj["repeat"].as<uint8_t>();
} }
if(shadeId != 255) { if(shadeId != 255) {
SomfyShade *shade = somfy.getShadeById(shadeId); 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; } if(json.isNull()) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No room object supplied.\"}")); return; }
ESP_LOGD(TAG, "Updating a room"); ESP_LOGD(TAG, "Updating a room");
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("roomId")) { if(!obj["roomId"].isNull()) {
SomfyRoom* room = somfy.getRoomById(obj["roomId"]); SomfyRoom* room = somfy.getRoomById(obj["roomId"]);
if(room) { if(room) {
room->fromJSON(obj); 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; } if(json.isNull()) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade object supplied.\"}")); return; }
ESP_LOGD(TAG, "Updating a shade"); ESP_LOGD(TAG, "Updating a shade");
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("shadeId")) { if(!obj["shadeId"].isNull()) {
SomfyShade* shade = somfy.getShadeById(obj["shadeId"]); SomfyShade* shade = somfy.getShadeById(obj["shadeId"]);
if(shade) { if(shade) {
int8_t err = shade->fromJSON(obj); 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; } if(json.isNull()) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No group object supplied.\"}")); return; }
ESP_LOGD(TAG, "Updating a group"); ESP_LOGD(TAG, "Updating a group");
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("groupId")) { if(!obj["groupId"].isNull()) {
SomfyGroup* group = somfy.getGroupById(obj["groupId"]); SomfyGroup* group = somfy.getGroupById(obj["groupId"]);
if(group) { if(group) {
group->fromJSON(obj); group->fromJSON(obj);
@ -1289,10 +1289,10 @@ void Web::begin() {
int8_t tilt = -1; int8_t tilt = -1;
if(!json.isNull()) { if(!json.isNull()) {
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
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; } else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade id was supplied.\"}")); return; }
if(obj.containsKey("pos")) pos = obj["pos"].as<int8_t>(); if(!obj["pos"].isNull()) pos = obj["pos"].as<int8_t>();
if(obj.containsKey("tilt")) tilt = obj["tilt"].as<int8_t>(); if(!obj["tilt"].isNull()) tilt = obj["tilt"].as<int8_t>();
} }
SomfyShade* shade = somfy.getShadeById(shadeId); SomfyShade* shade = somfy.getShadeById(shadeId);
if(shade) { if(shade) {
@ -1346,8 +1346,8 @@ void Web::begin() {
uint16_t rollingCode = 0; uint16_t rollingCode = 0;
if(!json.isNull()) { if(!json.isNull()) {
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("shadeId")) shadeId = obj["shadeId"]; if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"];
if(obj.containsKey("rollingCode")) rollingCode = obj["rollingCode"]; if(!obj["rollingCode"].isNull()) rollingCode = obj["rollingCode"];
} }
SomfyShade* shade = nullptr; SomfyShade* shade = nullptr;
if(shadeId != 255) shade = somfy.getShadeById(shadeId); if(shadeId != 255) shade = somfy.getShadeById(shadeId);
@ -1394,8 +1394,8 @@ void Web::begin() {
bool paired = false; bool paired = false;
if(!json.isNull()) { if(!json.isNull()) {
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("shadeId")) shadeId = obj["shadeId"]; if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"];
if(obj.containsKey("paired")) paired = obj["paired"]; if(!obj["paired"].isNull()) paired = obj["paired"];
} }
SomfyShade* shade = nullptr; SomfyShade* shade = nullptr;
if(shadeId != 255) shade = somfy.getShadeById(shadeId); if(shadeId != 255) shade = somfy.getShadeById(shadeId);
@ -1443,7 +1443,7 @@ void Web::begin() {
uint8_t shadeId = 255; uint8_t shadeId = 255;
if(!json.isNull()) { if(!json.isNull()) {
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("shadeId")) shadeId = obj["shadeId"]; if(!obj["shadeId"].isNull()) shadeId = obj["shadeId"];
} }
SomfyShade* shade = nullptr; SomfyShade* shade = nullptr;
if(shadeId != 255) shade = somfy.getShadeById(shadeId); if(shadeId != 255) shade = somfy.getShadeById(shadeId);
@ -1497,8 +1497,8 @@ void Web::begin() {
if(!json.isNull()) { if(!json.isNull()) {
ESP_LOGD(TAG, "Linking a repeater"); ESP_LOGD(TAG, "Linking a repeater");
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("address")) address = obj["address"]; if(!obj["address"].isNull()) address = obj["address"];
else if(obj.containsKey("remoteAddress")) address = obj["remoteAddress"]; else if(!obj["remoteAddress"].isNull()) address = obj["remoteAddress"];
} }
if(address == 0) { if(address == 0) {
request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No repeater address was supplied.\"}")); request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No repeater address was supplied.\"}"));
@ -1538,8 +1538,8 @@ void Web::begin() {
if(!json.isNull()) { if(!json.isNull()) {
ESP_LOGD(TAG, "Unlinking a repeater"); ESP_LOGD(TAG, "Unlinking a repeater");
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("address")) address = obj["address"]; if(!obj["address"].isNull()) address = obj["address"];
else if(obj.containsKey("remoteAddress")) address = obj["remoteAddress"]; else if(!obj["remoteAddress"].isNull()) address = obj["remoteAddress"];
} }
if(address == 0) { if(address == 0) {
request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No repeater address was supplied.\"}")); 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) { [](AsyncWebServerRequest *request, JsonVariant &json) {
if(json.isNull()) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No remote object supplied.\"}")); return; } if(json.isNull()) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No remote object supplied.\"}")); return; }
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("shadeId")) { if(!obj["shadeId"].isNull()) {
SomfyShade* shade = somfy.getShadeById(obj["shadeId"]); SomfyShade* shade = somfy.getShadeById(obj["shadeId"]);
if(shade) { if(shade) {
if(obj.containsKey("remoteAddress")) { if(!obj["remoteAddress"].isNull()) {
shade->unlinkRemote(obj["remoteAddress"]); shade->unlinkRemote(obj["remoteAddress"]);
} }
else { 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; } if(json.isNull()) { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No remote object supplied.\"}")); return; }
ESP_LOGD(TAG, "Linking a remote"); ESP_LOGD(TAG, "Linking a remote");
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("shadeId")) { if(!obj["shadeId"].isNull()) {
SomfyShade* shade = somfy.getShadeById(obj["shadeId"]); SomfyShade* shade = somfy.getShadeById(obj["shadeId"]);
if(shade) { if(shade) {
if(obj.containsKey("remoteAddress")) { if(!obj["remoteAddress"].isNull()) {
if(obj.containsKey("rollingCode")) shade->linkRemote(obj["remoteAddress"], obj["rollingCode"]); if(!obj["rollingCode"].isNull()) shade->linkRemote(obj["remoteAddress"], obj["rollingCode"]);
else shade->linkRemote(obj["remoteAddress"]); else shade->linkRemote(obj["remoteAddress"]);
} }
else { 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; } 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"); ESP_LOGD(TAG, "Linking a shade to a group");
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
uint8_t shadeId = obj.containsKey("shadeId") ? obj["shadeId"] : 0; uint8_t shadeId = !obj["shadeId"].isNull() ? obj["shadeId"] : 0;
uint8_t groupId = obj.containsKey("groupId") ? obj["groupId"] : 0; uint8_t groupId = !obj["groupId"].isNull() ? obj["groupId"] : 0;
if(groupId == 0) { if(groupId == 0) {
request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"Group id not provided.\"}")); request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"Group id not provided.\"}"));
return; 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; } 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"); ESP_LOGD(TAG, "Unlinking a shade from a group");
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
uint8_t shadeId = obj.containsKey("shadeId") ? obj["shadeId"] : 0; uint8_t shadeId = !obj["shadeId"].isNull() ? obj["shadeId"] : 0;
uint8_t groupId = obj.containsKey("groupId") ? obj["groupId"] : 0; uint8_t groupId = !obj["groupId"].isNull() ? obj["groupId"] : 0;
if(groupId == 0) { if(groupId == 0) {
request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"Group id not provided.\"}")); request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"Group id not provided.\"}"));
return; return;
@ -1703,7 +1703,7 @@ void Web::begin() {
if(!json.isNull()) { if(!json.isNull()) {
ESP_LOGD(TAG, "Deleting a Room"); ESP_LOGD(TAG, "Deleting a Room");
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
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; } else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No room id was supplied.\"}")); return; }
} }
SomfyRoom* room = somfy.getRoomById(roomId); SomfyRoom* room = somfy.getRoomById(roomId);
@ -1734,7 +1734,7 @@ void Web::begin() {
if(!json.isNull()) { if(!json.isNull()) {
ESP_LOGD(TAG, "Deleting a shade"); ESP_LOGD(TAG, "Deleting a shade");
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
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; } else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade id was supplied.\"}")); return; }
} }
SomfyShade* shade = somfy.getShadeById(shadeId); SomfyShade* shade = somfy.getShadeById(shadeId);
@ -1771,7 +1771,7 @@ void Web::begin() {
if(!json.isNull()) { if(!json.isNull()) {
ESP_LOGD(TAG, "Deleting a group"); ESP_LOGD(TAG, "Deleting a group");
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
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; } else { request->send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No group id was supplied.\"}")); return; }
} }
SomfyGroup *group = somfy.getGroupById(groupId); SomfyGroup *group = somfy.getGroupById(groupId);
@ -2000,11 +2000,11 @@ void Web::begin() {
if(!json.isNull()) { if(!json.isNull()) {
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
String scmd; String scmd;
if(obj.containsKey("address")) frame.remoteAddress = obj["address"]; if(!obj["address"].isNull()) frame.remoteAddress = obj["address"];
if(obj.containsKey("command")) scmd = obj["command"].as<String>(); if(!obj["command"].isNull()) scmd = obj["command"].as<String>();
if(obj.containsKey("repeats")) repeats = obj["repeats"]; if(!obj["repeats"].isNull()) repeats = obj["repeats"];
if(obj.containsKey("rcode")) frame.rollingCode = obj["rcode"]; if(!obj["rcode"].isNull()) frame.rollingCode = obj["rcode"];
if(obj.containsKey("encKey")) frame.encKey = obj["encKey"]; if(!obj["encKey"].isNull()) frame.encKey = obj["encKey"];
frame.cmd = translateSomfyCommand(scmd.c_str()); frame.cmd = translateSomfyCommand(scmd.c_str());
} }
if(frame.remoteAddress > 0 && frame.rollingCode > 0) { if(frame.remoteAddress > 0 && frame.rollingCode > 0) {
@ -2040,14 +2040,14 @@ void Web::begin() {
return; return;
} }
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
if(obj.containsKey("hostname") || obj.containsKey("ssdpBroadcast") || obj.containsKey("checkForUpdate")) { if(!obj["hostname"].isNull() || !obj["ssdpBroadcast"].isNull() || !obj["checkForUpdate"].isNull()) {
bool checkForUpdate = settings.checkForUpdate; bool checkForUpdate = settings.checkForUpdate;
settings.fromJSON(obj); settings.fromJSON(obj);
settings.save(); settings.save();
if(settings.checkForUpdate != checkForUpdate) git.emitUpdateCheck(); 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.fromJSON(obj);
settings.NTP.save(); settings.NTP.save();
} }
@ -2063,25 +2063,25 @@ void Web::begin() {
} }
JsonObject obj = json.as<JsonObject>(); JsonObject obj = json.as<JsonObject>();
bool reboot = false; bool reboot = false;
if(obj.containsKey("connType") && obj["connType"].as<uint8_t>() != static_cast<uint8_t>(settings.connType)) { if(!obj["connType"].isNull() && obj["connType"].as<uint8_t>() != static_cast<uint8_t>(settings.connType)) {
settings.connType = static_cast<conn_types_t>(obj["connType"].as<uint8_t>()); settings.connType = static_cast<conn_types_t>(obj["connType"].as<uint8_t>());
settings.save(); settings.save();
reboot = true; reboot = true;
} }
if(obj.containsKey("wifi")) { if(!obj["wifi"].isNull()) {
JsonObject objWifi = obj["wifi"]; JsonObject objWifi = obj["wifi"];
if(settings.connType == conn_types_t::wifi) { if(settings.connType == conn_types_t::wifi) {
if(objWifi.containsKey("ssid") && objWifi["ssid"].as<String>().compareTo(settings.WIFI.ssid) != 0) { if(!objWifi["ssid"].isNull() && objWifi["ssid"].as<String>().compareTo(settings.WIFI.ssid) != 0) {
if(WiFi.softAPgetStationNum() == 0) reboot = true; if(WiFi.softAPgetStationNum() == 0) reboot = true;
} }
if(objWifi.containsKey("passphrase") && objWifi["passphrase"].as<String>().compareTo(settings.WIFI.passphrase) != 0) { if(!objWifi["passphrase"].isNull() && objWifi["passphrase"].as<String>().compareTo(settings.WIFI.passphrase) != 0) {
if(WiFi.softAPgetStationNum() == 0) reboot = true; if(WiFi.softAPgetStationNum() == 0) reboot = true;
} }
} }
settings.WIFI.fromJSON(objWifi); settings.WIFI.fromJSON(objWifi);
settings.WIFI.save(); settings.WIFI.save();
} }
if(obj.containsKey("ethernet")) { if(!obj["ethernet"].isNull()) {
JsonObject objEth = obj["ethernet"]; JsonObject objEth = obj["ethernet"];
if(settings.connType == conn_types_t::ethernet || settings.connType == conn_types_t::ethernetpref) if(settings.connType == conn_types_t::ethernet || settings.connType == conn_types_t::ethernetpref)
reboot = true; reboot = true;
@ -2121,8 +2121,8 @@ void Web::begin() {
ESP_LOGD(TAG, "Settings WIFI connection..."); ESP_LOGD(TAG, "Settings WIFI connection...");
String ssid = ""; String ssid = "";
String passphrase = ""; String passphrase = "";
if(obj.containsKey("ssid")) ssid = obj["ssid"].as<String>(); if(!obj["ssid"].isNull()) ssid = obj["ssid"].as<String>();
if(obj.containsKey("passphrase")) passphrase = obj["passphrase"].as<String>(); if(!obj["passphrase"].isNull()) passphrase = obj["passphrase"].as<String>();
bool reboot = false; bool reboot = false;
if(ssid.compareTo(settings.WIFI.ssid) != 0) reboot = true; if(ssid.compareTo(settings.WIFI.ssid) != 0) reboot = true;
if(passphrase.compareTo(settings.WIFI.passphrase) != 0) reboot = true; if(passphrase.compareTo(settings.WIFI.passphrase) != 0) reboot = true;