@@ -13,12 +13,12 @@ static const char *TAG = "Config";
1313Preferences pref;
1414
1515void restore_options_t::fromJSON (JsonObject &obj) {
16- if (obj. containsKey ( " shades" )) this ->shades = obj[" shades" ];
17- if (obj. containsKey ( " settings" )) this ->settings = obj[" settings" ];
18- if (obj. containsKey ( " network" )) this ->network = obj[" network" ];
19- if (obj. containsKey ( " transceiver" )) this ->transceiver = obj[" transceiver" ];
20- if (obj. containsKey ( " repeaters" )) this ->repeaters = obj[" repeaters" ];
21- if (obj. containsKey ( " mqtt" )) this ->mqtt = obj[" mqtt" ];
16+ if (! obj[ " shades" ]. isNull ( )) this ->shades = obj[" shades" ];
17+ if (! obj[ " settings" ]. isNull ( )) this ->settings = obj[" settings" ];
18+ if (! obj[ " network" ]. isNull ( )) this ->network = obj[" network" ];
19+ if (! obj[ " transceiver" ]. isNull ( )) this ->transceiver = obj[" transceiver" ];
20+ if (! obj[ " repeaters" ]. isNull ( )) this ->repeaters = obj[" repeaters" ];
21+ if (! obj[ " mqtt" ]. isNull ( )) this ->mqtt = obj[" mqtt" ];
2222}
2323int8_t appver_t::compare (appver_t &ver) {
2424 if (this ->major == ver.major && this ->minor == ver.minor && this ->build == ver.build ) return 0 ;
@@ -125,23 +125,23 @@ bool BaseSettings::saveFile(const char *filename) {
125125 return true ;
126126}
127127bool BaseSettings::parseValueString (JsonObject &obj, const char *prop, char *pdest, size_t size) {
128- if (obj. containsKey (prop )) strlcpy (pdest, obj[prop], size);
128+ if (! obj[prop]. isNull ( )) strlcpy (pdest, obj[prop], size);
129129 return true ;
130130}
131131bool BaseSettings::parseIPAddress (JsonObject &obj, const char *prop, IPAddress *pdest) {
132- if (obj. containsKey (prop )) {
132+ if (! obj[prop]. isNull ( )) {
133133 char buff[16 ];
134134 strlcpy (buff, obj[prop], sizeof (buff));
135135 pdest->fromString (buff);
136136 }
137137 return true ;
138138}
139139int BaseSettings::parseValueInt (JsonObject &obj, const char *prop, int defVal) {
140- if (obj. containsKey (prop )) return obj[prop];
140+ if (! obj[prop]. isNull ( )) return obj[prop];
141141 return defVal;
142142}
143143double BaseSettings::parseValueDouble (JsonObject &obj, const char *prop, double defVal) {
144- if (obj. containsKey (prop )) return obj[prop];
144+ if (! obj[prop]. isNull ( )) return obj[prop];
145145 return defVal;
146146}
147147bool ConfigSettings::begin () {
@@ -247,10 +247,10 @@ bool ConfigSettings::toJSON(JsonObject &obj) {
247247}
248248bool ConfigSettings::requiresAuth () { return this ->Security .type != security_types::None; }
249249bool ConfigSettings::fromJSON (JsonObject &obj) {
250- if (obj. containsKey ( " ssdpBroadcast" )) this ->ssdpBroadcast = obj[" ssdpBroadcast" ];
251- if (obj. containsKey ( " hostname" )) this ->parseValueString (obj, " hostname" , this ->hostname , sizeof (this ->hostname ));
252- if (obj. containsKey ( " connType" )) this ->connType = static_cast <conn_types_t >(obj[" connType" ].as <uint8_t >());
253- if (obj. containsKey ( " checkForUpdate" )) this ->checkForUpdate = obj[" checkForUpdate" ];
250+ if (! obj[ " ssdpBroadcast" ]. isNull ( )) this ->ssdpBroadcast = obj[" ssdpBroadcast" ];
251+ if (! obj[ " hostname" ]. isNull ( )) this ->parseValueString (obj, " hostname" , this ->hostname , sizeof (this ->hostname ));
252+ if (! obj[ " connType" ]. isNull ( )) this ->connType = static_cast <conn_types_t >(obj[" connType" ].as <uint8_t >());
253+ if (! obj[ " checkForUpdate" ]. isNull ( )) this ->checkForUpdate = obj[" checkForUpdate" ];
254254 return true ;
255255}
256256void ConfigSettings::print () {
@@ -309,15 +309,15 @@ bool MQTTSettings::toJSON(JsonObject &obj) {
309309 return true ;
310310}
311311bool MQTTSettings::fromJSON (JsonObject &obj) {
312- if (obj. containsKey ( " enabled" )) this ->enabled = obj[" enabled" ];
313- if (obj. containsKey ( " pubDisco" )) this ->pubDisco = obj[" pubDisco" ];
312+ if (! obj[ " enabled" ]. isNull ( )) this ->enabled = obj[" enabled" ];
313+ if (! obj[ " pubDisco" ]. isNull ( )) this ->pubDisco = obj[" pubDisco" ];
314314 this ->parseValueString (obj, " protocol" , this ->protocol , sizeof (this ->protocol ));
315315 this ->parseValueString (obj, " hostname" , this ->hostname , sizeof (this ->hostname ));
316316 this ->parseValueString (obj, " username" , this ->username , sizeof (this ->username ));
317317 this ->parseValueString (obj, " password" , this ->password , sizeof (this ->password ));
318318 this ->parseValueString (obj, " rootTopic" , this ->rootTopic , sizeof (this ->rootTopic ));
319319 this ->parseValueString (obj, " discoTopic" , this ->discoTopic , sizeof (this ->discoTopic ));
320- if (obj. containsKey ( " port" )) this ->port = obj[" port" ];
320+ if (! obj[ " port" ]. isNull ( )) this ->port = obj[" port" ];
321321 return true ;
322322}
323323bool MQTTSettings::save () {
@@ -409,7 +409,7 @@ bool IPSettings::begin() {
409409 return true ;
410410}
411411bool IPSettings::fromJSON (JsonObject &obj) {
412- if (obj. containsKey ( " dhcp" )) this ->dhcp = obj[" dhcp" ];
412+ if (! obj[ " dhcp" ]. isNull ( )) this ->dhcp = obj[" dhcp" ];
413413 this ->parseIPAddress (obj, " ip" , &this ->ip );
414414 this ->parseIPAddress (obj, " gateway" , &this ->gateway );
415415 this ->parseIPAddress (obj, " subnet" , &this ->subnet );
@@ -472,11 +472,11 @@ bool SecuritySettings::begin() {
472472 return true ;
473473}
474474bool SecuritySettings::fromJSON (JsonObject &obj) {
475- if (obj. containsKey ( " type" )) this ->type = static_cast <security_types>(obj[" type" ].as <uint8_t >());
475+ if (! obj[ " type" ]. isNull ( )) this ->type = static_cast <security_types>(obj[" type" ].as <uint8_t >());
476476 this ->parseValueString (obj, " username" , this ->username , sizeof (this ->username ));
477477 this ->parseValueString (obj, " password" , this ->password , sizeof (this ->password ));
478478 this ->parseValueString (obj, " pin" , this ->pin , sizeof (this ->pin ));
479- if (obj. containsKey ( " permissions" )) this ->permissions = obj[" permissions" ];
479+ if (! obj[ " permissions" ]. isNull ( )) this ->permissions = obj[" permissions" ];
480480 return true ;
481481}
482482bool SecuritySettings::toJSON (JsonObject &obj) {
@@ -521,8 +521,8 @@ bool WifiSettings::begin() {
521521bool WifiSettings::fromJSON (JsonObject &obj) {
522522 this ->parseValueString (obj, " ssid" , this ->ssid , sizeof (this ->ssid ));
523523 this ->parseValueString (obj, " passphrase" , this ->passphrase , sizeof (this ->passphrase ));
524- if (obj. containsKey ( " roaming" )) this ->roaming = obj[" roaming" ];
525- if (obj. containsKey ( " hidden" )) this ->hidden = obj[" hidden" ];
524+ if (! obj[ " roaming" ]. isNull ( )) this ->roaming = obj[" roaming" ];
525+ if (! obj[ " hidden" ]. isNull ( )) this ->hidden = obj[" hidden" ];
526526 return true ;
527527}
528528bool WifiSettings::toJSON (JsonObject &obj) {
@@ -596,13 +596,13 @@ bool EthernetSettings::begin() {
596596 return true ;
597597}
598598bool EthernetSettings::fromJSON (JsonObject &obj) {
599- if (obj. containsKey ( " boardType" )) this ->boardType = obj[" boardType" ];
600- if (obj. containsKey ( " phyAddress" )) this ->phyAddress = obj[" phyAddress" ];
601- if (obj. containsKey ( " CLKMode" )) this ->CLKMode = static_cast <eth_clock_mode_t >(obj[" CLKMode" ]);
602- if (obj. containsKey ( " phyType" )) this ->phyType = static_cast <eth_phy_type_t >(obj[" phyType" ]);
603- if (obj. containsKey ( " PWRPin" )) this ->PWRPin = obj[" PWRPin" ];
604- if (obj. containsKey ( " MDCPin" )) this ->MDCPin = obj[" MDCPin" ];
605- if (obj. containsKey ( " MDIOPin" )) this ->MDIOPin = obj[" MDIOPin" ];
599+ if (! obj[ " boardType" ]. isNull ( )) this ->boardType = obj[" boardType" ];
600+ if (! obj[ " phyAddress" ]. isNull ( )) this ->phyAddress = obj[" phyAddress" ];
601+ if (! obj[ " CLKMode" ]. isNull ( )) this ->CLKMode = static_cast <eth_clock_mode_t >(obj[" CLKMode" ]);
602+ if (! obj[ " phyType" ]. isNull ( )) this ->phyType = static_cast <eth_phy_type_t >(obj[" phyType" ]);
603+ if (! obj[ " PWRPin" ]. isNull ( )) this ->PWRPin = obj[" PWRPin" ];
604+ if (! obj[ " MDCPin" ]. isNull ( )) this ->MDCPin = obj[" MDCPin" ];
605+ if (! obj[ " MDIOPin" ]. isNull ( )) this ->MDIOPin = obj[" MDIOPin" ];
606606 return true ;
607607}
608608bool EthernetSettings::toJSON (JsonObject &obj) {
0 commit comments