@@ -206,7 +206,7 @@ void parse_serial_commands() {
206
206
return ;
207
207
}
208
208
209
- if (doc. containsKey ( " command" )) {
209
+ if (! doc[ " command" ]. isNull ( )) {
210
210
String command = doc[" command" ].as <String>();
211
211
212
212
if (command == " reboot" ) {
@@ -220,31 +220,33 @@ void parse_serial_commands() {
220
220
}
221
221
222
222
// Handle device settings updates
223
- if (doc. containsKey ( " settings" )) {
224
- JsonObject settings = doc[" settings" ];
223
+ if (! doc[ " settings" ]. isNull ( )) {
224
+ JsonObject settings = doc[" settings" ]. as <JsonObject>() ;
225
225
226
- if (settings.containsKey (" screen_rot" )) {
227
- deviceData.screen_rotation = settings[" screen_rot" ].as <unsigned int >();
228
- }
226
+ if (!settings.isNull ()) {
227
+ if (!settings[" screen_rot" ].isNull ()) {
228
+ deviceData.screen_rotation = settings[" screen_rot" ].as <unsigned int >();
229
+ }
229
230
230
- if (settings. containsKey ( " sea_pressure" )) {
231
- deviceData.sea_pressure = settings[" sea_pressure" ].as <float >();
232
- }
231
+ if (! settings[ " sea_pressure" ]. isNull ( )) {
232
+ deviceData.sea_pressure = settings[" sea_pressure" ].as <float >();
233
+ }
233
234
234
- if (settings. containsKey ( " metric_temp" )) {
235
- deviceData.metric_temp = settings[" metric_temp" ].as <bool >();
236
- }
235
+ if (! settings[ " metric_temp" ]. isNull ( )) {
236
+ deviceData.metric_temp = settings[" metric_temp" ].as <bool >();
237
+ }
237
238
238
- if (settings. containsKey ( " metric_alt" )) {
239
- deviceData.metric_alt = settings[" metric_alt" ].as <bool >();
240
- }
239
+ if (! settings[ " metric_alt" ]. isNull ( )) {
240
+ deviceData.metric_alt = settings[" metric_alt" ].as <bool >();
241
+ }
241
242
242
- if (settings. containsKey ( " performance_mode" )) {
243
- deviceData.performance_mode = settings[" performance_mode" ].as <int >();
244
- }
243
+ if (! settings[ " performance_mode" ]. isNull ( )) {
244
+ deviceData.performance_mode = settings[" performance_mode" ].as <int >();
245
+ }
245
246
246
- if (settings.containsKey (" theme" )) {
247
- deviceData.theme = settings[" theme" ].as <int >();
247
+ if (!settings[" theme" ].isNull ()) {
248
+ deviceData.theme = settings[" theme" ].as <int >();
249
+ }
248
250
}
249
251
250
252
sanitizeDeviceData ();
0 commit comments