iobroker.iot 5.0.13 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +6 -6
  2. package/admin/assets/index-39e7CNHj.js +705 -0
  3. package/admin/index_m.html +1 -1
  4. package/admin/rules/@mf-types/compiled-types/ActionVisu.d.ts +1 -1
  5. package/admin/rules/@mf-types.zip +0 -0
  6. package/admin/rules/assets/{ActionVisu-BN0Kjfo9.js → ActionVisu-BCZFwf_Y.js} +1 -1
  7. package/admin/rules/assets/{index-FrXvyqvW.js → index-DYx5xsZT.js} +76 -76
  8. package/admin/rules/assets/{localSharedImportMap-8wECk2hR.js → localSharedImportMap-CNn4MUou.js} +1 -1
  9. package/admin/rules/assets/{virtualExposes-b6CxLzZb.js → virtualExposes-B2aPQUg7.js} +1 -1
  10. package/admin/rules/customRuleBlocks.js +2 -2
  11. package/admin/rules/mf-stats.json +1 -1
  12. package/build/lib/AlexaSmartHomeV3/Alexa/Directives/Discovery.js +2 -1
  13. package/build/lib/AlexaSmartHomeV3/Alexa/Directives/Discovery.js.map +1 -1
  14. package/build/lib/AlexaSmartHomeV3/Controls/AirCondition.js +2 -2
  15. package/build/lib/AlexaSmartHomeV3/Controls/AirCondition.js.map +1 -1
  16. package/build/lib/AlexaSmartHomeV3/Controls/Ct.js +1 -1
  17. package/build/lib/AlexaSmartHomeV3/Controls/Ct.js.map +1 -1
  18. package/build/lib/AlexaSmartHomeV3/Controls/Rgb.js +1 -1
  19. package/build/lib/AlexaSmartHomeV3/Controls/Rgb.js.map +1 -1
  20. package/build/lib/AlexaSmartHomeV3/Controls/RgbSingle.js +1 -1
  21. package/build/lib/AlexaSmartHomeV3/Controls/RgbSingle.js.map +1 -1
  22. package/build/lib/AlexaSmartHomeV3/Controls/RgbwSingle.js +1 -1
  23. package/build/lib/AlexaSmartHomeV3/Controls/RgbwSingle.js.map +1 -1
  24. package/build/lib/AlexaSmartHomeV3/Controls/Thermostat.js +1 -1
  25. package/build/lib/AlexaSmartHomeV3/Controls/Thermostat.js.map +1 -1
  26. package/build/lib/AlexaSmartHomeV3/Controls/Volume.js +2 -2
  27. package/build/lib/AlexaSmartHomeV3/Controls/Volume.js.map +1 -1
  28. package/build/lib/AlexaSmartHomeV3/DeviceManager.js +18 -9
  29. package/build/lib/AlexaSmartHomeV3/DeviceManager.js.map +1 -1
  30. package/build/lib/AlexaSmartHomeV3/Helpers/DiscoveryValidator.js +283 -0
  31. package/build/lib/AlexaSmartHomeV3/Helpers/DiscoveryValidator.js.map +1 -0
  32. package/build/lib/AlexaSmartHomeV3/Helpers/Utils.js +4 -0
  33. package/build/lib/AlexaSmartHomeV3/Helpers/Utils.js.map +1 -1
  34. package/build/lib/alisa.js +15 -14
  35. package/build/lib/googleHome.js +151 -207
  36. package/io-package.json +14 -14
  37. package/package.json +1 -1
  38. package/admin/assets/index-DCr4hGKK.js +0 -705
@@ -490,8 +490,8 @@ class GoogleHome {
490
490
  }
491
491
 
492
492
  _subscribeAllIds(ids, cb) {
493
- if (!ids || !ids.length) {
494
- cb && cb();
493
+ if (!ids?.length) {
494
+ cb?.();
495
495
  } else {
496
496
  const id = ids.shift();
497
497
  if (!id) {
@@ -504,8 +504,8 @@ class GoogleHome {
504
504
  }
505
505
 
506
506
  _unsubscribeAllIds(ids, cb) {
507
- if (!ids || !ids.length) {
508
- cb && cb();
507
+ if (!ids?.length) {
508
+ cb?.();
509
509
  } else {
510
510
  const id = ids.shift();
511
511
  if (!id) {
@@ -522,16 +522,17 @@ class GoogleHome {
522
522
  this.smartDevices &&
523
523
  Object.keys(this.smartDevices).forEach(devId => {
524
524
  const custom = this.smartDevices[devId].customData;
525
- custom &&
525
+ if (custom) {
526
526
  Object.keys(custom).forEach(attr => {
527
- attr && attr.startsWith('get_') && !ids.includes(custom[attr]) && ids.push(custom[attr]);
527
+ attr?.startsWith('get_') && !ids.includes(custom[attr]) && ids.push(custom[attr]);
528
528
  });
529
+ }
529
530
  });
530
531
 
531
532
  this.adapter.log.debug(`[GHOME] Unsubscribe ${ids.length} states for google home`);
532
533
  this._unsubscribeAllIds(ids, () => {
533
534
  this.adapter.log.debug(`[GHOME] Unsubscribe done`);
534
- cb && cb();
535
+ cb?.();
535
536
  });
536
537
  }
537
538
 
@@ -540,18 +541,19 @@ class GoogleHome {
540
541
  this.smartDevices &&
541
542
  Object.keys(this.smartDevices).forEach(devId => {
542
543
  const custom = this.smartDevices[devId].customData;
543
- custom &&
544
+ if (custom) {
544
545
  Object.keys(custom).forEach(
545
546
  attr =>
546
- attr && attr.startsWith('get_') && !ids.includes(custom[attr]) && ids.push(custom[attr]),
547
+ attr?.startsWith('get_') && !ids.includes(custom[attr]) && ids.push(custom[attr]),
547
548
  );
549
+ }
548
550
  });
549
551
 
550
552
  this.adapter.log.debug(`[GHOME] Subscribe ${ids.length} states for google home`);
551
553
 
552
554
  this._subscribeAllIds(ids, () => {
553
555
  this.adapter.log.debug(`[GHOME] Subscribe done`);
554
- cb && cb();
556
+ cb?.();
555
557
  });
556
558
  }
557
559
 
@@ -561,27 +563,19 @@ class GoogleHome {
561
563
  if (!onlySimpleName) {
562
564
  if (this.adapter.config.noCommon) {
563
565
  if (
564
- obj.common &&
565
- obj.common.custom &&
566
- obj.common.custom[this.adapter.namespace] &&
567
- obj.common.custom[this.adapter.namespace].smartName &&
566
+ obj.common?.custom?.[this.adapter.namespace]?.smartName &&
568
567
  obj.common.custom[this.adapter.namespace].smartName !== 'ignore'
569
568
  ) {
570
569
  name = obj.common.custom[this.adapter.namespace].smartName;
571
570
  }
572
571
  } else {
573
- if (
574
- obj.common &&
575
- obj.common.smartName &&
576
- obj.common.smartName !== true &&
577
- obj.common.smartName !== 'ignore'
578
- ) {
572
+ if (obj.common?.smartName && obj.common.smartName !== true && obj.common.smartName !== 'ignore') {
579
573
  name = obj.common.smartName;
580
574
  }
581
575
  }
582
576
  }
583
577
  // if no smart name found, get the normal key
584
- if (!name && obj && obj.common && obj.common.name) {
578
+ if (!name && obj?.common?.name) {
585
579
  name = obj.common.name;
586
580
  }
587
581
 
@@ -598,7 +592,7 @@ class GoogleHome {
598
592
 
599
593
  checkName(name, obj, room, func) {
600
594
  if (!name) {
601
- name = name || this.getObjectName(obj) || '';
595
+ name ||= this.getObjectName(obj) || '';
602
596
  name = name.replace(/[^a-zA-ZöäüßÖÄÜа-яА-Я0-9ÉéÈèÀàÂâÊêÙùÛûÇçÎîËëÏïŸÿÔôŒœãõìòáíóú]/g, ' ');
603
597
  let _name = name.toLowerCase();
604
598
  let pos;
@@ -622,10 +616,10 @@ class GoogleHome {
622
616
 
623
617
  processSocket(id, control, name, room, func, obj) {
624
618
  const setOnOffState = control.states.find(state => state.name === 'SET' && state.id);
625
- const set_on = setOnOffState && setOnOffState.id;
619
+ const set_on = setOnOffState?.id;
626
620
 
627
621
  const getOnOffState = control.states.find(state => state.name === 'ACTUAL' && state.id);
628
- const get_on = (getOnOffState && getOnOffState.id) || set_on;
622
+ const get_on = getOnOffState?.id || set_on;
629
623
 
630
624
  name = this.checkName(name, obj, room, func);
631
625
 
@@ -653,10 +647,10 @@ class GoogleHome {
653
647
 
654
648
  processLight(id, control, name, room, func, obj) {
655
649
  const setOnOffState = control.states.find(state => state.name === 'SET' && state.id);
656
- const set_on = setOnOffState && setOnOffState.id;
650
+ const set_on = setOnOffState?.id;
657
651
 
658
652
  const getOnOffState = control.states.find(state => state.name === 'ACTUAL' && state.id);
659
- const get_on = (getOnOffState && getOnOffState.id) || set_on;
653
+ const get_on = getOnOffState?.id || set_on;
660
654
 
661
655
  const traits = ['action.devices.traits.OnOff'];
662
656
  name = this.checkName(name, obj, room, func);
@@ -685,7 +679,7 @@ class GoogleHome {
685
679
 
686
680
  processInfo(id, control, name, room, func, obj) {
687
681
  const getOnOffState = control.states.find(state => state.name === 'ACTUAL' && state.id);
688
- const get_on = getOnOffState && getOnOffState.id;
682
+ const get_on = getOnOffState?.id;
689
683
 
690
684
  name = this.checkName(name, obj, room, func);
691
685
 
@@ -732,10 +726,10 @@ class GoogleHome {
732
726
 
733
727
  processButton(id, control, name, room, func, obj) {
734
728
  const setOnOffState = control.states.find(state => state.name === 'SET' && state.id);
735
- const set_on = setOnOffState && setOnOffState.id;
729
+ const set_on = setOnOffState?.id;
736
730
 
737
731
  const getOnOffState = control.states.find(state => state.name === 'ACTUAL' && state.id);
738
- const get_on = (getOnOffState && getOnOffState.id) || set_on;
732
+ const get_on = getOnOffState?.id || set_on;
739
733
 
740
734
  const traits = ['action.devices.traits.OnOff'];
741
735
  name = this.checkName(name, obj, room, func);
@@ -764,21 +758,21 @@ class GoogleHome {
764
758
 
765
759
  processDimmer(id, control, name, room, func, obj) {
766
760
  const setBrightnessState = control.states.find(state => state.name === 'SET' && state.id);
767
- let set_brightness = setBrightnessState && setBrightnessState.id;
768
- if (set_brightness.indexOf('.dimspeed') !== -1) {
761
+ let set_brightness = setBrightnessState?.id;
762
+ if (set_brightness?.includes('.dimspeed')) {
769
763
  let idArray = set_brightness.split('.');
770
764
  idArray.pop();
771
765
  idArray.push('bri');
772
766
  set_brightness = idArray.join('.');
773
767
  }
774
768
  const getBrightnessState = control.states.find(state => state.name === 'ACTUAL' && state.id);
775
- const get_brightness = (getBrightnessState && getBrightnessState.id) || set_brightness;
769
+ const get_brightness = getBrightnessState?.id || set_brightness;
776
770
 
777
771
  const setOnOffState = control.states.find(state => state.name === 'ON_SET' && state.id);
778
- const set_on = (setOnOffState && setOnOffState.id) || set_brightness;
772
+ const set_on = setOnOffState?.id || set_brightness;
779
773
 
780
774
  const getOnOffState = control.states.find(state => state.name === 'ON_ACTUAL' && state.id);
781
- const get_on = (getOnOffState && getOnOffState.id) || set_on;
775
+ const get_on = getOnOffState?.id || set_on;
782
776
 
783
777
  const traits = [];
784
778
 
@@ -822,27 +816,27 @@ class GoogleHome {
822
816
  if (!setBrightnessState) {
823
817
  setBrightnessState = control.states.find(state => state.name === 'DIMMER' && state.id);
824
818
  }
825
- const set_brightness = setBrightnessState && setBrightnessState.id;
819
+ const set_brightness = setBrightnessState?.id;
826
820
  const get_brightness = set_brightness;
827
821
 
828
822
  let setOnOffState = control.states.find(state => state.name === 'ON' && state.id);
829
823
 
830
- const set_on = (setOnOffState && setOnOffState.id) || set_brightness;
824
+ const set_on = setOnOffState?.id || set_brightness;
831
825
  const get_on = set_on;
832
826
 
833
827
  let setHueState = control.states.find(state => state.name === 'HUE' && state.id);
834
828
 
835
- const set_color_hue = setHueState && setHueState.id;
829
+ const set_color_hue = setHueState?.id;
836
830
  const get_color_hue = set_color_hue;
837
831
 
838
832
  let setSaturationState = control.states.find(state => state.name === 'SATURATION' && state.id);
839
833
 
840
- const set_color_saturation = setSaturationState && setSaturationState.id;
834
+ const set_color_saturation = setSaturationState?.id;
841
835
  const get_color_saturation = set_color_saturation;
842
836
 
843
837
  let setTempState = control.states.find(state => state.name === 'TEMPERATURE' && state.id);
844
838
 
845
- const set_color_temperature = setTempState && setTempState.id;
839
+ const set_color_temperature = setTempState?.id;
846
840
  const get_color_temperature = set_color_temperature;
847
841
 
848
842
  const traits = [];
@@ -910,24 +904,24 @@ class GoogleHome {
910
904
  if (!setBrightnessState) {
911
905
  setBrightnessState = control.states.find(state => state.name === 'DIMMER' && state.id);
912
906
  }
913
- const set_brightness = setBrightnessState && setBrightnessState.id;
907
+ const set_brightness = setBrightnessState?.id;
914
908
  const get_brightness = set_brightness;
915
909
 
916
910
  let setOnOffState = control.states.find(state => state.name === 'ON_LIGHT' && state.id);
917
911
  if (!setOnOffState) {
918
912
  setOnOffState = control.states.find(state => state.name === 'ON' && state.id);
919
913
  }
920
- const set_on = (setOnOffState && setOnOffState.id) || set_brightness;
914
+ const set_on = setOnOffState?.id || set_brightness;
921
915
  const get_on = set_on;
922
916
 
923
917
  let setRGBState = control.states.find(state => state.name === 'RGB' && state.id);
924
918
 
925
- const set_color_spectrumRGB = setRGBState && setRGBState.id;
919
+ const set_color_spectrumRGB = setRGBState?.id;
926
920
  const get_color_spectrumRGB = set_color_spectrumRGB;
927
921
 
928
922
  let setTempState = control.states.find(state => state.name === 'TEMPERATURE' && state.id);
929
923
 
930
- const set_color_temperature = setTempState && setTempState.id;
924
+ const set_color_temperature = setTempState?.id;
931
925
  const get_color_temperature = set_color_temperature;
932
926
 
933
927
  const traits = [];
@@ -995,34 +989,34 @@ class GoogleHome {
995
989
  if (!setBrightnessState) {
996
990
  setBrightnessState = control.states.find(state => state.name === 'DIMMER' && state.id);
997
991
  }
998
- const set_brightness = setBrightnessState && setBrightnessState.id;
992
+ const set_brightness = setBrightnessState?.id;
999
993
  const get_brightness = set_brightness;
1000
994
 
1001
995
  let setOnOffState = control.states.find(state => state.name === 'ON_LIGHT' && state.id);
1002
996
  if (!setOnOffState) {
1003
997
  setOnOffState = control.states.find(state => state.name === 'ON' && state.id);
1004
998
  }
1005
- const set_on = (setOnOffState && setOnOffState.id) || set_brightness;
999
+ const set_on = setOnOffState?.id || set_brightness;
1006
1000
  const get_on = set_on;
1007
1001
 
1008
1002
  let setTempState = control.states.find(state => state.name === 'TEMPERATURE' && state.id);
1009
1003
 
1010
- const set_color_temperature = setTempState && setTempState.id;
1004
+ const set_color_temperature = setTempState?.id;
1011
1005
  const get_color_temperature = set_color_temperature;
1012
1006
 
1013
1007
  let setRState = control.states.find(state => state.name === 'RED' && state.id);
1014
1008
 
1015
- const set_color_R = setRState && setRState.id;
1009
+ const set_color_R = setRState?.id;
1016
1010
  const get_color_R = set_color_R;
1017
1011
 
1018
1012
  let setGState = control.states.find(state => state.name === 'GREEN' && state.id);
1019
1013
 
1020
- const set_color_G = setGState && setGState.id;
1014
+ const set_color_G = setGState?.id;
1021
1015
  const get_color_G = set_color_G;
1022
1016
 
1023
1017
  let setBState = control.states.find(state => state.name === 'BLUE' && state.id);
1024
1018
 
1025
- const set_color_B = setBState && setBState.id;
1019
+ const set_color_B = setBState?.id;
1026
1020
  const get_color_B = set_color_B;
1027
1021
 
1028
1022
  const traits = [];
@@ -1092,19 +1086,19 @@ class GoogleHome {
1092
1086
  if (!setBrightnessState) {
1093
1087
  setBrightnessState = control.states.find(state => state.name === 'DIMMER' && state.id);
1094
1088
  }
1095
- const set_brightness = setBrightnessState && setBrightnessState.id;
1089
+ const set_brightness = setBrightnessState?.id;
1096
1090
  const get_brightness = set_brightness;
1097
1091
 
1098
1092
  let setOnOffState = control.states.find(state => state.name === 'ON' && state.id);
1099
1093
  if (!setOnOffState) {
1100
1094
  setOnOffState = control.states.find(state => state.name === 'ON_LIGHT' && state.id);
1101
1095
  }
1102
- const set_on = (setOnOffState && setOnOffState.id) || set_brightness;
1096
+ const set_on = setOnOffState?.id || set_brightness;
1103
1097
  const get_on = set_on;
1104
1098
 
1105
1099
  let setTempState = control.states.find(state => state.name === 'TEMPERATURE' && state.id);
1106
1100
 
1107
- const set_color_temperature = setTempState && setTempState.id;
1101
+ const set_color_temperature = setTempState?.id;
1108
1102
  const get_color_temperature = set_color_temperature;
1109
1103
 
1110
1104
  const traits = [];
@@ -1164,8 +1158,8 @@ class GoogleHome {
1164
1158
 
1165
1159
  processWindowTilt(id, control, name, room, func, obj) {
1166
1160
  const getWindowTile = control.states.find(state => state.name === 'ACTUAL' && state.id);
1167
- const get_isLocked = getWindowTile && getWindowTile.id;
1168
- const set_lock = getWindowTile && getWindowTile.id;
1161
+ const get_isLocked = getWindowTile?.id;
1162
+ const set_lock = getWindowTile?.id;
1169
1163
  const set_openPercent = set_lock;
1170
1164
  const get_openPercent = get_isLocked;
1171
1165
 
@@ -1208,11 +1202,11 @@ class GoogleHome {
1208
1202
 
1209
1203
  processBlind(id, control, name, room, func, obj) {
1210
1204
  const getOpenPercent = control.states.find(state => state.name === 'SET' && state.id);
1211
- const set_openPercent = getOpenPercent && getOpenPercent.id;
1205
+ const set_openPercent = getOpenPercent?.id;
1212
1206
  const get_openPercent = set_openPercent;
1213
1207
 
1214
1208
  const getOpenDirection = control.states.find(state => state.name === 'DIRECTION' && state.id);
1215
- const set_openDirection = getOpenDirection && getOpenDirection.id;
1209
+ const set_openDirection = getOpenDirection?.id;
1216
1210
  const get_openDirection = set_openDirection;
1217
1211
 
1218
1212
  const traits = [];
@@ -1247,16 +1241,14 @@ class GoogleHome {
1247
1241
 
1248
1242
  processTemperature(id, control, name, room, func, obj) {
1249
1243
  const setThermostatTemperatureSetpoint = control.states.find(state => state.name === 'SET' && state.id);
1250
- const set_thermostatTemperatureSetpoint =
1251
- setThermostatTemperatureSetpoint && setThermostatTemperatureSetpoint.id;
1244
+ const set_thermostatTemperatureSetpoint = setThermostatTemperatureSetpoint?.id;
1252
1245
 
1253
1246
  const getThermostatTemperatureAmbient = control.states.find(state => state.name === 'ACTUAL' && state.id);
1254
1247
  const get_thermostatTemperatureAmbient =
1255
- (getThermostatTemperatureAmbient && getThermostatTemperatureAmbient.id) ||
1256
- set_thermostatTemperatureSetpoint;
1248
+ getThermostatTemperatureAmbient?.id || set_thermostatTemperatureSetpoint;
1257
1249
 
1258
1250
  const getThermostatHumidityAmbient = control.states.find(state => state.name === 'SECOND' && state.id);
1259
- const get_thermostatHumidityAmbient = getThermostatHumidityAmbient && getThermostatHumidityAmbient.id;
1251
+ const get_thermostatHumidityAmbient = getThermostatHumidityAmbient?.id;
1260
1252
 
1261
1253
  const traits = [];
1262
1254
  traits.push('action.devices.traits.TemperatureSetting');
@@ -1297,16 +1289,14 @@ class GoogleHome {
1297
1289
 
1298
1290
  processThermostat(id, control, name, room, func, obj) {
1299
1291
  const setThermostatTemperatureSetpoint = control.states.find(state => state.name === 'SET' && state.id);
1300
- const set_thermostatTemperatureSetpoint =
1301
- setThermostatTemperatureSetpoint && setThermostatTemperatureSetpoint.id;
1292
+ const set_thermostatTemperatureSetpoint = setThermostatTemperatureSetpoint?.id;
1302
1293
  const get_thermostatTemperatureSetpoint = set_thermostatTemperatureSetpoint;
1303
1294
  const getThermostatTemperatureAmbient = control.states.find(state => state.name === 'ACTUAL' && state.id);
1304
1295
  const get_thermostatTemperatureAmbient =
1305
- (getThermostatTemperatureAmbient && getThermostatTemperatureAmbient.id) ||
1306
- set_thermostatTemperatureSetpoint;
1296
+ getThermostatTemperatureAmbient?.id || set_thermostatTemperatureSetpoint;
1307
1297
 
1308
1298
  const getThermostatHumidityAmbient = control.states.find(state => state.name === 'HUMIDITY' && state.id);
1309
- const get_thermostatHumidityAmbient = getThermostatHumidityAmbient && getThermostatHumidityAmbient.id;
1299
+ const get_thermostatHumidityAmbient = getThermostatHumidityAmbient?.id;
1310
1300
 
1311
1301
  const traits = [];
1312
1302
  traits.push('action.devices.traits.TemperatureSetting');
@@ -1349,26 +1339,26 @@ class GoogleHome {
1349
1339
 
1350
1340
  processMedia(id, control, name, room, func, obj) {
1351
1341
  const setOnOffState = control.states.find(state => state.name === 'STATE' && state.id);
1352
- const set_on = setOnOffState && setOnOffState.id;
1342
+ const set_on = setOnOffState?.id;
1353
1343
  const get_on = set_on;
1354
1344
 
1355
1345
  const setPlayState = control.states.find(state => state.name === 'PLAY' && state.id);
1356
- const set_mediaPlay = (setPlayState && setPlayState.id) || set_on;
1346
+ const set_mediaPlay = setPlayState?.id || set_on;
1357
1347
 
1358
1348
  const setPauseState = control.states.find(state => state.name === 'PAUSE' && state.id);
1359
- const set_mediaPause = setPauseState && setPauseState.id;
1349
+ const set_mediaPause = setPauseState?.id;
1360
1350
 
1361
1351
  const setStopState = control.states.find(state => state.name === 'STOP' && state.id);
1362
- const set_mediaStop = setStopState && setStopState.id;
1352
+ const set_mediaStop = setStopState?.id;
1363
1353
 
1364
1354
  const setNextState = control.states.find(state => state.name === 'NEXT' && state.id);
1365
- const set_mediaNext = setNextState && setNextState.id;
1355
+ const set_mediaNext = setNextState?.id;
1366
1356
 
1367
1357
  const setPrevState = control.states.find(state => state.name === 'PREV' && state.id);
1368
- const set_mediaPrev = setPrevState && setPrevState.id;
1358
+ const set_mediaPrev = setPrevState?.id;
1369
1359
 
1370
1360
  const setVolumeState = control.states.find(state => state.name === 'VOLUME' && state.id);
1371
- const set_brightness = setVolumeState && setVolumeState.id;
1361
+ const set_brightness = setVolumeState?.id;
1372
1362
 
1373
1363
  const traits = [
1374
1364
  'action.devices.traits.OnOff',
@@ -1422,17 +1412,14 @@ class GoogleHome {
1422
1412
  return null;
1423
1413
  }
1424
1414
  } else {
1425
- return states && states.common && states.common.custom && states.common.custom[this.adapter.namespace]
1415
+ return states?.common?.custom?.[this.adapter.namespace]
1426
1416
  ? states.common.custom[this.adapter.namespace].smartName
1427
1417
  : undefined;
1428
1418
  }
1429
1419
  } else if (!this.adapter.config.noCommon) {
1430
- return states[id] && states[id].common ? states[id].common.smartName : null;
1420
+ return states[id]?.common ? states[id].common.smartName : null;
1431
1421
  } else {
1432
- return states[id] &&
1433
- states[id].common &&
1434
- states[id].common.custom &&
1435
- states[id].common.custom[this.adapter.namespace]
1422
+ return states[id]?.common?.custom?.[this.adapter.namespace]
1436
1423
  ? states[id].common.custom[this.adapter.namespace].smartName || null
1437
1424
  : null;
1438
1425
  }
@@ -1499,21 +1486,20 @@ class GoogleHome {
1499
1486
  result[id]['displayConv2iob'] = smartName.ghConv2iob;
1500
1487
  }
1501
1488
  }
1502
- if ((typeof smartName === 'object' && smartName && smartName.ghType && smartName.ghTraits) || parentId) {
1503
- if (smartName && smartName.ghType) {
1489
+ if ((typeof smartName === 'object' && smartName?.ghType && smartName.ghTraits) || parentId) {
1490
+ if (smartName?.ghType) {
1504
1491
  result[id].type = smartName.ghType;
1505
1492
  }
1506
- if (smartName && smartName.ghTraits && smartName.ghTraits.length > 0 && smartName.ghTraits[0]) {
1493
+ if (smartName?.ghTraits?.length > 0 && smartName.ghTraits[0]) {
1507
1494
  result[id].traits = [smartName.ghTraits[0].split('_')[0]];
1508
1495
  result[id].displayTraits = [smartName.ghTraits[0]];
1509
1496
  }
1510
1497
  try {
1511
- if (smartName && smartName.ghAttributes) {
1498
+ if (smartName?.ghAttributes) {
1512
1499
  result[id].attributes = JSON.parse(smartName.ghAttributes);
1513
1500
  result[id].displayAttributes = JSON.stringify(result[id].attributes);
1514
1501
  }
1515
1502
  } catch (error) {
1516
- this.adapter.log.error(`[GHOME] Cannot parse attributes ${error} ${smartName.ghAttributes}`);
1517
1503
  this.adapter.log.error(`[GHOME] Cannot parse attributes ${error} ${smartName.ghAttributes}`);
1518
1504
  result[id].attributes = {};
1519
1505
  result[id].displayAttributes = smartName.ghAttributes;
@@ -1536,8 +1522,6 @@ class GoogleHome {
1536
1522
  };
1537
1523
 
1538
1524
  const controls = this.detector.detect(options);
1539
- // if (id.indexOf('deconz.0.Lights.27') !== -1)
1540
- // debugger
1541
1525
  if (controls) {
1542
1526
  let control = controls[0];
1543
1527
  if (controls[0].type === 'socket' && controls[1] && controls[1].type !== 'info') {
@@ -1555,9 +1539,9 @@ class GoogleHome {
1555
1539
  funcName,
1556
1540
  objects[id],
1557
1541
  );
1558
- result[id].displayTraits = result[id].displayTraits || result[id].traits;
1542
+ result[id].displayTraits ||= result[id].traits;
1559
1543
 
1560
- if (typeof smartName === 'object' && smartName && smartName.ghAttributes) {
1544
+ if (typeof smartName === 'object' && smartName?.ghAttributes) {
1561
1545
  result[id].attributes = JSON.parse(smartName.ghAttributes);
1562
1546
  result[id].displayAttributes = JSON.stringify(result[id].attributes);
1563
1547
  }
@@ -1570,7 +1554,7 @@ class GoogleHome {
1570
1554
  const briState = await this.adapter.getForeignObjectAsync(
1571
1555
  result[id].customData.set_brightness,
1572
1556
  );
1573
- if (briState && briState.common && briState.common.max && briState.common.max >= 101) {
1557
+ if (briState?.common?.max && briState.common.max >= 101) {
1574
1558
  result[id]['conv2GH'][result[id].customData.set_brightness] =
1575
1559
  'return value/' + briState.common.max / 100;
1576
1560
  result[id]['conv2iob'][result[id].customData.set_brightness] =
@@ -1581,11 +1565,7 @@ class GoogleHome {
1581
1565
  const set_color_temperature = await this.adapter.getForeignObjectAsync(
1582
1566
  result[id].customData.set_color_temperature,
1583
1567
  );
1584
- if (
1585
- set_color_temperature &&
1586
- set_color_temperature.common &&
1587
- set_color_temperature.common.max <= 500
1588
- ) {
1568
+ if (set_color_temperature?.common?.max <= 500) {
1589
1569
  result[id]['conv2GH'][result[id].customData.set_color_temperature] =
1590
1570
  'return 1000000/value';
1591
1571
  result[id]['conv2iob'][result[id].customData.set_color_temperature] =
@@ -1601,8 +1581,6 @@ class GoogleHome {
1601
1581
 
1602
1582
  // childStates.forEach((child) => {
1603
1583
  Object.keys(result[id].customData).forEach(element => {
1604
- // if (element.indexOf('get_') !== -1) {
1605
-
1606
1584
  const childID = result[id].customData[element];
1607
1585
 
1608
1586
  if (!childID) {
@@ -1662,7 +1640,7 @@ class GoogleHome {
1662
1640
  this.adapter.log.error(`[GHOME] ${e.stack}`);
1663
1641
  }
1664
1642
  return;
1665
- } else if (typeof smartName === 'object' && smartName && smartName.smartType) {
1643
+ } else if (typeof smartName === 'object' && smartName?.smartType) {
1666
1644
  //SMARTTYPES = ['LIGHT', 'SWITCH', 'THERMOSTAT', 'ACTIVITY_TRIGGER', 'SCENE_TRIGGER', 'SMARTPLUG', 'SMARTLOCK', 'CAMERA'];
1667
1645
  switch (smartName.smartType) {
1668
1646
  case 'LIGHT':
@@ -1683,7 +1661,7 @@ class GoogleHome {
1683
1661
  break;
1684
1662
  }
1685
1663
 
1686
- result[id].displayTraits = result[id].displayTraits || result[id].traits;
1664
+ result[id].displayTraits ||= result[id].traits;
1687
1665
  result[id].ioType = objects[id].type;
1688
1666
  result[id].smartEnum = 'X';
1689
1667
 
@@ -1744,9 +1722,7 @@ class GoogleHome {
1744
1722
  },
1745
1723
  ];
1746
1724
  if (
1747
- smartName &&
1748
- smartName.ghTraits &&
1749
- smartName.ghTraits.length > 0 &&
1725
+ smartName?.ghTraits?.length > 0 &&
1750
1726
  smartName.ghTraits[0] &&
1751
1727
  traitEnum[smartName.ghTraits[0]]
1752
1728
  ) {
@@ -1778,9 +1754,7 @@ class GoogleHome {
1778
1754
  result[id].attributes = JSON.parse(defaultAttributes);
1779
1755
  const obj = await this.adapter.getForeignObjectAsync(id);
1780
1756
  if (
1781
- !obj.common ||
1782
- !obj.common.smartName ||
1783
- !obj.common.smartName.ghAttributes ||
1757
+ !obj.common?.smartName?.ghAttributes ||
1784
1758
  obj.common.smartName.ghAttributes !== defaultAttributes
1785
1759
  ) {
1786
1760
  await this.adapter.extendForeignObjectAsync(id, {
@@ -1797,11 +1771,9 @@ class GoogleHome {
1797
1771
  }
1798
1772
 
1799
1773
  //merge states with same name and room
1800
- if (this.smartNames[friendlyName] && this.smartNames[friendlyName].roomHint === roomName) {
1774
+ if (this.smartNames[friendlyName]?.roomHint === roomName) {
1801
1775
  if (
1802
- smartName &&
1803
- smartName.ghTraits &&
1804
- Array.isArray(smartName.ghTraits) &&
1776
+ Array.isArray(smartName?.ghTraits) &&
1805
1777
  smartName.ghTraits.length > 0 &&
1806
1778
  smartName.ghTraits[0]
1807
1779
  ) {
@@ -1863,42 +1835,39 @@ class GoogleHome {
1863
1835
  this.adapter.getObjectView('system', 'enum', {}, (err, _enums) => {
1864
1836
  const objects = {};
1865
1837
  const enums = {};
1866
- if (_devices && _devices.rows) {
1838
+ if (_devices?.rows) {
1867
1839
  for (let i = 0; i < _devices.rows.length; i++) {
1868
1840
  if (
1869
- _devices.rows[i].value &&
1870
- _devices.rows[i].value._id &&
1841
+ _devices.rows[i].value?._id &&
1871
1842
  !ignoreIds.find(reg => reg.test(_devices.rows[i].value._id))
1872
1843
  ) {
1873
1844
  objects[_devices.rows[i].value._id] = _devices.rows[i].value;
1874
1845
  }
1875
1846
  }
1876
1847
  }
1877
- if (_channels && _channels.rows) {
1848
+ if (_channels?.rows) {
1878
1849
  for (let i = 0; i < _channels.rows.length; i++) {
1879
1850
  if (
1880
- _channels.rows[i].value &&
1881
- _channels.rows[i].value._id &&
1851
+ _channels.rows[i].value?._id &&
1882
1852
  !ignoreIds.find(reg => reg.test(_channels.rows[i].value._id))
1883
1853
  ) {
1884
1854
  objects[_channels.rows[i].value._id] = _channels.rows[i].value;
1885
1855
  }
1886
1856
  }
1887
1857
  }
1888
- if (_states && _states.rows) {
1858
+ if (_states?.rows) {
1889
1859
  for (let i = 0; i < _states.rows.length; i++) {
1890
1860
  if (
1891
- _states.rows[i].value &&
1892
- _states.rows[i].value._id &&
1861
+ _states.rows[i].value?._id &&
1893
1862
  !ignoreIds.find(reg => reg.test(_states.rows[i].value._id))
1894
1863
  ) {
1895
1864
  objects[_states.rows[i].value._id] = _states.rows[i].value;
1896
1865
  }
1897
1866
  }
1898
1867
  }
1899
- if (_enums && _enums.rows) {
1868
+ if (_enums?.rows) {
1900
1869
  for (let i = 0; i < _enums.rows.length; i++) {
1901
- if (_enums.rows[i].value && _enums.rows[i].value._id) {
1870
+ if (_enums.rows[i].value?._id) {
1902
1871
  enums[_enums.rows[i].value._id] = _enums.rows[i].value;
1903
1872
  objects[_enums.rows[i].value._id] = _enums.rows[i].value;
1904
1873
  }
@@ -1948,7 +1917,7 @@ class GoogleHome {
1948
1917
  `[GHOME] Invalid URL Pro key. Status auto-update is disabled you can set states but receive states only manually: ${err}`,
1949
1918
  );
1950
1919
  // call cb otherwise frontend get no results
1951
- cb && cb();
1920
+ cb?.();
1952
1921
  });
1953
1922
  });
1954
1923
  });
@@ -1966,7 +1935,7 @@ class GoogleHome {
1966
1935
  let roomHint = '';
1967
1936
  allRooms.forEach(roomId => {
1968
1937
  const room = enums[roomId];
1969
- if (!room.common || !room.common.members || !room.common.members.length) {
1938
+ if (!room.common?.members?.length) {
1970
1939
  return;
1971
1940
  }
1972
1941
 
@@ -1976,14 +1945,14 @@ class GoogleHome {
1976
1945
  const idArray = id.split('.');
1977
1946
  idArray.pop();
1978
1947
  const parent = idArray.join('.');
1979
- if (objects[parent] && objects[parent].type === 'channel') {
1948
+ if (objects[parent]?.type === 'channel') {
1980
1949
  pos = room.common.members.indexOf(parent);
1981
1950
  }
1982
1951
  }
1983
1952
  if (pos !== -1) {
1984
1953
  // Get the name of function (with language and if name is empty)
1985
1954
  let roomName = this.getSmartName(room);
1986
- roomName = roomName || room.common.name;
1955
+ roomName ||= room.common.name;
1987
1956
  if (roomName && typeof roomName === 'object') {
1988
1957
  roomName = roomName[this.lang] || roomName.en;
1989
1958
  }
@@ -2051,8 +2020,7 @@ class GoogleHome {
2051
2020
  const func = enums[funcId];
2052
2021
 
2053
2022
  if (
2054
- !func.common ||
2055
- !func.common.members ||
2023
+ !func.common?.members ||
2056
2024
  typeof func.common.members !== 'object' ||
2057
2025
  !func.common.members.length
2058
2026
  ) {
@@ -2061,7 +2029,7 @@ class GoogleHome {
2061
2029
  this.adapter.log.debug(`[GHOME] Process ${funcId}`);
2062
2030
  // Get the name of function (with language and if name is empty)
2063
2031
  let funcName = this.getSmartName(func);
2064
- funcName = funcName || func.common.name;
2032
+ funcName ||= func.common.name;
2065
2033
 
2066
2034
  if (funcName && typeof funcName === 'object') {
2067
2035
  funcName = funcName[this.lang] || funcName.en;
@@ -2080,8 +2048,7 @@ class GoogleHome {
2080
2048
  const room = enums[roomId];
2081
2049
 
2082
2050
  if (
2083
- !room.common ||
2084
- !room.common.members ||
2051
+ !room.common?.members ||
2085
2052
  typeof func.common.members !== 'object' ||
2086
2053
  !room.common.members.length
2087
2054
  ) {
@@ -2089,15 +2056,13 @@ class GoogleHome {
2089
2056
  }
2090
2057
 
2091
2058
  // If state or channel is in some room and in some function
2092
- const pos = room.common.members.indexOf(id);
2093
-
2094
- if (pos !== -1) {
2059
+ if (room.common.members.includes(id)) {
2095
2060
  // find name for room if not found earlier
2096
2061
  if (!roomNames[roomId]) {
2097
2062
  // Get the name of function (with language and if name is empty)
2098
2063
  let roomName = this.getSmartName(room);
2099
2064
 
2100
- roomName = roomName || room.common.name;
2065
+ roomName ||= room.common.name;
2101
2066
 
2102
2067
  if (roomName && typeof roomName === 'object') {
2103
2068
  roomName = roomName[this.lang] || roomName.en;
@@ -2109,7 +2074,7 @@ class GoogleHome {
2109
2074
  }
2110
2075
  roomNames[roomId] = roomName;
2111
2076
  }
2112
- if (objects[id] && objects[id].type === 'state') {
2077
+ if (objects[id]?.type === 'state') {
2113
2078
  this.adapter.log.warn(
2114
2079
  `[GHOME] ${id} is a state. It's recommended to add rooms and functionality to channels or devices and not to a state to get auto detected for Google Home. This works only for simple switches.`,
2115
2080
  );
@@ -2183,7 +2148,7 @@ class GoogleHome {
2183
2148
  continue;
2184
2149
  }
2185
2150
  const _attr = attr.substring(4);
2186
- json[devId] = json[devId] || {};
2151
+ json[devId] ||= {};
2187
2152
  json[devId][_attr] = {
2188
2153
  id: custom[attr],
2189
2154
  };
@@ -2195,10 +2160,10 @@ class GoogleHome {
2195
2160
  }
2196
2161
 
2197
2162
  for (const attr in custom) {
2198
- if (custom.hasOwnProperty(attr) && attr && custom[attr] === id && attr.startsWith('get_')) {
2163
+ if (custom.hasOwnProperty(attr) && custom[attr] === id && attr?.startsWith('get_')) {
2199
2164
  const _attr = attr.substring(4);
2200
2165
  let val;
2201
- json[devId] = json[devId] || {};
2166
+ json[devId] ||= {};
2202
2167
 
2203
2168
  try {
2204
2169
  if (_attr === 'on') {
@@ -2232,7 +2197,7 @@ class GoogleHome {
2232
2197
  val = Math.floor(spectrumRgb);
2233
2198
  }
2234
2199
  } else if (_attr === 'color_hue') {
2235
- json[devId].color = json[devId].color ? json[devId].color : {};
2200
+ json[devId].color ||= {};
2236
2201
  const hue = json[devId].color_hue
2237
2202
  ? await this.adapter.getForeignStateAsync(json[devId].color_hue.id)
2238
2203
  : { val: 0 };
@@ -2287,10 +2252,10 @@ class GoogleHome {
2287
2252
  b = q;
2288
2253
  break;
2289
2254
  }
2290
- val = Math.floor((r << (16 + g)) << (8 + b));
2255
+ val = (r << 16) | (g << 8) | b;
2291
2256
  } else if (_attr === 'color_spectrumRGB') {
2292
2257
  const rgb = state.val;
2293
- json[devId].color = json[devId].color ? json[devId].color : {};
2258
+ json[devId].color ||= {};
2294
2259
  if (rgb && rgb.substring) {
2295
2260
  val = parseInt(rgb.substring(1), 16) || 0;
2296
2261
  } else {
@@ -2325,20 +2290,14 @@ class GoogleHome {
2325
2290
  }
2326
2291
 
2327
2292
  // do not send the same state to google
2328
- if (
2329
- (this.reportedStates[devId] &&
2330
- this.reportedStates[devId][_attr] &&
2331
- this.reportedStates[devId][_attr].val !== val) ||
2332
- !this.reportedStates[devId] ||
2333
- !this.reportedStates[devId][_attr]
2334
- ) {
2335
- this.reportedStates[devId] = this.reportedStates[devId] || {};
2336
- this.reportedStates[devId][_attr] = this.reportedStates[devId][_attr] || {};
2293
+ if (this.reportedStates[devId]?.[_attr]?.val !== val) {
2294
+ this.reportedStates[devId] ||= {};
2295
+ this.reportedStates[devId][_attr] ||= {};
2337
2296
  this.reportedStates[devId][_attr].val = val;
2338
2297
  this.reportedStates[devId][_attr].ts = now;
2339
- json[devId] = json[devId] || {};
2298
+ json[devId] ||= {};
2340
2299
  if (_attr.includes('color_')) {
2341
- json[devId].color = json[devId].color ? json[devId].color : {};
2300
+ json[devId].color ||= {};
2342
2301
  if (_attr === 'color_temperature') {
2343
2302
  json[devId].color.temperatureK = Math.floor(val);
2344
2303
  } else {
@@ -2403,13 +2362,13 @@ class GoogleHome {
2403
2362
  );
2404
2363
  })
2405
2364
  .catch(error => {
2406
- if (error.response && error.response.status === 404) {
2365
+ if (error.response?.status === 404) {
2407
2366
  this.adapter.log.error(`[GHOME] device ${id} is unknown to google home`);
2408
2367
  this.unknownDevices[id] = Date.now();
2409
- } else if (error.response && error.response.status === 401) {
2368
+ } else if (error.response?.status === 401) {
2410
2369
  this.adapter.log.error(`[GHOME] auth error: ${JSON.stringify(error.response.body)}`);
2411
2370
  this.urlKeyOk = false; // invalidate urlKey
2412
- } else if (error.response && error.response.status === 410) {
2371
+ } else if (error.response?.status === 410) {
2413
2372
  this.adapter.log.error(
2414
2373
  `[GHOME] invalid protocol version: ${JSON.stringify(error.response.body)}`,
2415
2374
  );
@@ -2441,9 +2400,9 @@ class GoogleHome {
2441
2400
  if (this.smartDevicesSentToGoogle.hasOwnProperty(devId)) {
2442
2401
  const custom = this.smartDevicesSentToGoogle[devId].customData;
2443
2402
  for (const attr in custom) {
2444
- if (custom.hasOwnProperty(attr) && attr && attr.startsWith('get_')) {
2403
+ if (custom.hasOwnProperty(attr) && attr?.startsWith('get_')) {
2445
2404
  const _attr = attr.substring(4);
2446
- json[devId] = json[devId] || {};
2405
+ json[devId] ||= {};
2447
2406
  json[devId][_attr] = {
2448
2407
  id: custom[attr],
2449
2408
  };
@@ -2474,12 +2433,9 @@ class GoogleHome {
2474
2433
  continue;
2475
2434
  }
2476
2435
 
2477
- state = state || { val: false };
2436
+ state ||= { val: false };
2478
2437
 
2479
- if (
2480
- this.smartDevices[devId].conv2GH &&
2481
- this.smartDevices[devId].conv2GH[json[devId][attr].id]
2482
- ) {
2438
+ if (this.smartDevices[devId].conv2GH?.[json[devId][attr].id]) {
2483
2439
  try {
2484
2440
  const conv = new Function(
2485
2441
  'value',
@@ -2502,17 +2458,23 @@ class GoogleHome {
2502
2458
  state.val === true ||
2503
2459
  (typeof state.val === 'number' && state.val > 0);
2504
2460
  } else if (attr === 'color_R' || attr === 'color_G' || attr === 'color_B') {
2505
- const r = await this.adapter.getForeignStateAsync(json[devId].color_R.id);
2506
- const g = await this.adapter.getForeignStateAsync(json[devId].color_G.id);
2507
- const b = await this.adapter.getForeignStateAsync(json[devId].color_B.id);
2508
- const spectrumRgb = (r.val << 16) + (g.val << 8) + b.val;
2509
- json[devId].color = json[devId].color ? json[devId].color : {};
2461
+ const r = json[devId].color_R
2462
+ ? await this.adapter.getForeignStateAsync(json[devId].color_R.id)
2463
+ : { val: 0 };
2464
+ const g = json[devId].color_G
2465
+ ? await this.adapter.getForeignStateAsync(json[devId].color_G.id)
2466
+ : { val: 0 };
2467
+ const b = json[devId].color_B
2468
+ ? await this.adapter.getForeignStateAsync(json[devId].color_B.id)
2469
+ : { val: 0 };
2470
+ const spectrumRgb = ((r?.val || 0) << 16) | ((g?.val || 0) << 8) | (b?.val || 0);
2471
+ json[devId].color ||= {};
2510
2472
  json[devId].color.spectrumRGB = Math.floor(spectrumRgb);
2511
2473
  delete json[devId]['color_R'];
2512
2474
  delete json[devId]['color_G'];
2513
2475
  delete json[devId]['color_B'];
2514
2476
  } else if (attr === 'color_hue') {
2515
- json[devId].color = json[devId].color ? json[devId].color : {};
2477
+ json[devId].color ||= {};
2516
2478
  if (json[devId].color_hue && json[devId].color_saturation && json[devId].brightness) {
2517
2479
  try {
2518
2480
  const hue = await this.adapter.getForeignStateAsync(json[devId].color_hue.id);
@@ -2561,7 +2523,7 @@ class GoogleHome {
2561
2523
  b = q;
2562
2524
  break;
2563
2525
  }
2564
- json[devId].color.spectrumRGB = Math.floor((r << (16 + g)) << (8 + b));
2526
+ json[devId].color.spectrumRGB = (r << 16) | (g << 8) | b;
2565
2527
  } catch (error) {
2566
2528
  this.adapter.log.error(`[GHOME] ${error}`);
2567
2529
  }
@@ -2571,7 +2533,7 @@ class GoogleHome {
2571
2533
  delete json[devId]['brightness'];
2572
2534
  } else if (attr === 'color_spectrumRGB') {
2573
2535
  const rgb = state.val;
2574
- json[devId].color = json[devId].color ? json[devId].color : {};
2536
+ json[devId].color ||= {};
2575
2537
  if (rgb && rgb.substring) {
2576
2538
  json[devId].color.spectrumRGB = parseInt(rgb.substring(1), 16) || 0;
2577
2539
  } else {
@@ -2582,7 +2544,7 @@ class GoogleHome {
2582
2544
  } else if (attr === 'color_temperature') {
2583
2545
  const temp = state.val;
2584
2546
 
2585
- json[devId].color = json[devId].color ? json[devId].color : {};
2547
+ json[devId].color ||= {};
2586
2548
  json[devId].color.temperatureK = Math.floor(temp);
2587
2549
 
2588
2550
  delete json[devId][attr];
@@ -2643,13 +2605,13 @@ class GoogleHome {
2643
2605
  this.adapter.log.debug(`[GHOME] Status reported: ${JSON.stringify(response.data)}`);
2644
2606
  })
2645
2607
  .catch(error => {
2646
- if (error.response && error.response.status === 404) {
2608
+ if (error.response?.status === 404) {
2647
2609
  this.adapter.log.error(`[GHOME] devices are unknown to google home`);
2648
2610
  Object.keys(this.unknownDevices).forEach(id => (this.unknownDevices[id] = Date.now()));
2649
- } else if (error.response && error.response.status === 401) {
2611
+ } else if (error.response?.status === 401) {
2650
2612
  this.adapter.log.error(`[GHOME] auth error: ${JSON.stringify(error.response.data)}`);
2651
2613
  this.urlKeyOk = false; // invalidate urlKey
2652
- } else if (error.response && error.response.status === 410) {
2614
+ } else if (error.response?.status === 410) {
2653
2615
  this.adapter.log.error(
2654
2616
  `[GHOME] invalid protocol version: ${JSON.stringify(error.response.data)}`,
2655
2617
  );
@@ -2727,8 +2689,8 @@ class GoogleHome {
2727
2689
  }
2728
2690
 
2729
2691
  getStates(ids, callback, states) {
2730
- states = states || {};
2731
- if (!ids || !ids.length) {
2692
+ states ||= {};
2693
+ if (!ids?.length) {
2732
2694
  callback(states);
2733
2695
  } else {
2734
2696
  const id = ids.shift();
@@ -2736,7 +2698,7 @@ class GoogleHome {
2736
2698
  setImmediate(() => this.getStates(ids, callback, states));
2737
2699
  } else {
2738
2700
  this.adapter.getForeignState(id, (err, state) => {
2739
- states[id] = state && state.val;
2701
+ states[id] = state?.val;
2740
2702
  setImmediate(() => this.getStates(ids, callback, states));
2741
2703
  });
2742
2704
  }
@@ -2778,11 +2740,8 @@ class GoogleHome {
2778
2740
  const attrs = this.smartDevices[dev.id].customData;
2779
2741
  if (attrs) {
2780
2742
  Object.keys(attrs).forEach(attr => {
2781
- if (attr && attr.startsWith('get_')) {
2782
- if (
2783
- this.smartDevices[dev.id].conv2GH &&
2784
- this.smartDevices[dev.id].conv2GH[attrs[attr]]
2785
- ) {
2743
+ if (attr?.startsWith('get_')) {
2744
+ if (this.smartDevices[dev.id].conv2GH?.[attrs[attr]]) {
2786
2745
  try {
2787
2746
  const conv = new Function(
2788
2747
  'value',
@@ -2806,14 +2765,10 @@ class GoogleHome {
2806
2765
  (states[attrs.get_color_R] << 16) +
2807
2766
  (states[attrs.get_color_G] << 8) +
2808
2767
  states[attrs.get_color_B];
2809
- responseDev[dev.id].color = responseDev[dev.id].color
2810
- ? responseDev[dev.id].color
2811
- : {};
2768
+ responseDev[dev.id].color ||= {};
2812
2769
  responseDev[dev.id].color.spectrumRgb = spectrumRgb;
2813
2770
  } else if (attr === 'get_color_hue') {
2814
- responseDev[dev.id].color = responseDev[dev.id].color
2815
- ? responseDev[dev.id].color
2816
- : {};
2771
+ responseDev[dev.id].color ||= {};
2817
2772
  const h = states[attrs.get_color_hue] / 360;
2818
2773
  const s = states[attrs.get_color_saturation] / 255;
2819
2774
  const v = states[attrs.get_brightness] / 100;
@@ -2855,12 +2810,10 @@ class GoogleHome {
2855
2810
  b = q;
2856
2811
  break;
2857
2812
  }
2858
- responseDev[dev.id].color.spectrumRgb = (r << (16 + g)) << (8 + b);
2813
+ responseDev[dev.id].color.spectrumRgb = (r << 16) | (g << 8) | b;
2859
2814
  } else if (attr === 'get_color_spectrumRGB') {
2860
2815
  const rgb = states[attrs.get_color_spectrumRGB];
2861
- responseDev[dev.id].color = responseDev[dev.id].color
2862
- ? responseDev[dev.id].color
2863
- : {};
2816
+ responseDev[dev.id].color ||= {};
2864
2817
  if (rgb && rgb.substring) {
2865
2818
  responseDev[dev.id].color.spectrumRgb =
2866
2819
  parseInt(rgb.substring(1), 16) || 0;
@@ -2868,14 +2821,8 @@ class GoogleHome {
2868
2821
  responseDev[dev.id].color.spectrumRgb = rgb;
2869
2822
  }
2870
2823
  } else {
2871
- if (responseDev[dev.id][attrArray[0]]) {
2872
- responseDev[dev.id][attrArray[0]][attrArray[1]] =
2873
- states[attrs[attr]];
2874
- } else {
2875
- responseDev[dev.id][attrArray[0]] = {};
2876
- responseDev[dev.id][attrArray[0]][attrArray[1]] =
2877
- states[attrs[attr]];
2878
- }
2824
+ responseDev[dev.id][attrArray[0]] ||= {};
2825
+ responseDev[dev.id][attrArray[0]][attrArray[1]] = states[attrs[attr]];
2879
2826
  }
2880
2827
  } else {
2881
2828
  if (
@@ -2946,8 +2893,8 @@ class GoogleHome {
2946
2893
  }
2947
2894
 
2948
2895
  setStates(tasks, callback, results) {
2949
- results = results || {};
2950
- if (!tasks || !tasks.length) {
2896
+ results ||= {};
2897
+ if (!tasks?.length) {
2951
2898
  callback(results);
2952
2899
  } else {
2953
2900
  const task = tasks.shift();
@@ -2956,9 +2903,9 @@ class GoogleHome {
2956
2903
  if (task.cmd === 'action.devices.commands.SetToggles') {
2957
2904
  this.adapter.getForeignState(task.id, task.val, (error, state) => {
2958
2905
  if (!error) {
2959
- const val = !(state && state.val);
2906
+ const val = !state?.val;
2960
2907
  this.adapter.setForeignState(task.id, val, error => {
2961
- results[task.devId] = results[task.devId] || {};
2908
+ results[task.devId] ||= {};
2962
2909
  results[task.devId][task.param] = val;
2963
2910
  if (error) {
2964
2911
  results[task.devId].error = error;
@@ -2974,7 +2921,7 @@ class GoogleHome {
2974
2921
  });
2975
2922
  } else {
2976
2923
  this.adapter.setForeignState(task.id, task.val, error => {
2977
- results[task.devId] = results[task.devId] || {};
2924
+ results[task.devId] ||= {};
2978
2925
  results[task.devId][task.param] = task.val;
2979
2926
 
2980
2927
  if (error) {
@@ -3122,10 +3069,7 @@ class GoogleHome {
3122
3069
 
3123
3070
  paths.forEach(element => {
3124
3071
  if (attrs[`set_${element.path}`]) {
3125
- if (
3126
- this.smartDevices[dev.id].conv2iob &&
3127
- this.smartDevices[dev.id].conv2iob[attrs[`set_${element.path}`]]
3128
- ) {
3072
+ if (this.smartDevices[dev.id].conv2iob?.[attrs[`set_${element.path}`]]) {
3129
3073
  try {
3130
3074
  const conv = new Function(
3131
3075
  'value',