homebridge-melcloud-control 4.2.5-beta.0 → 4.2.5-beta.10

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.
package/src/deviceerv.js CHANGED
@@ -82,8 +82,8 @@ class DeviceErv extends EventEmitter {
82
82
  //buttons configured
83
83
  for (const button of this.buttons) {
84
84
  button.name = button.name || 'Button'
85
- button.serviceType = [null, Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][button.displayType];
86
- button.characteristicType = [null, Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][button.displayType];
85
+ button.serviceType = serviceType[button.displayType];
86
+ button.characteristicType = characteristicType[button.displayType];
87
87
  button.state = false;
88
88
  button.previousValue = null;
89
89
  }
@@ -320,8 +320,8 @@ class DeviceErv extends EventEmitter {
320
320
  .onSet(async (state) => {
321
321
  try {
322
322
  deviceData.Device.Power = state ? true : false;
323
- await this.melCloudErv.send(this.accountType, this.displayType, deviceData, Ventilation.EffectiveFlags.Power);
324
323
  if (this.logInfo) this.emit('info', `Set power: ${state ? 'On' : 'Off'}`);
324
+ await this.melCloudErv.send(this.accountType, this.displayType, deviceData, Ventilation.EffectiveFlags.Power);
325
325
  } catch (error) {
326
326
  if (this.logWarn) this.emit('warn', `Set power error: ${error}`);
327
327
  };
@@ -355,9 +355,8 @@ class DeviceErv extends EventEmitter {
355
355
  break;
356
356
  };
357
357
 
358
+ if (this.logInfo) this.emit('info', `Set operation mode: ${Ventilation.VentilationModeMapEnumToString[deviceData.Device.VentilationMode]}`);
358
359
  await this.melCloudErv.send(this.accountType, this.displayType, deviceData, Ventilation.EffectiveFlags.VentilationMode);
359
- const operationModeText = Ventilation.VentilationModeMapEnumToString[deviceData.Device.VentilationMode];
360
- if (this.logInfo) this.emit('info', `Set operation mode: ${operationModeText}`);
361
360
  } catch (error) {
362
361
  if (this.logWarn) this.emit('warn', `Set operation mode error: ${error}`);
363
362
  };
@@ -395,9 +394,9 @@ class DeviceErv extends EventEmitter {
395
394
  break;;
396
395
  };
397
396
 
398
- deviceData.Device.SetFanSpeed = value
399
- await this.melCloudErv.send(this.accountType, this.displayType, deviceData, Ventilation.EffectiveFlags.SetFanSpeed);
397
+ deviceData.Device.SetFanSpeed = value;
400
398
  if (this.logInfo) this.emit('info', `Set fan speed mode: ${Ventilation.FanSpeedMapEnumToString[value]}`);
399
+ await this.melCloudErv.send(this.accountType, this.displayType, deviceData, Ventilation.EffectiveFlags.SetFanSpeed);
401
400
  } catch (error) {
402
401
  if (this.logWarn) this.emit('warn', `Set fan speed mode error: ${error}`);
403
402
  };
@@ -418,8 +417,8 @@ class DeviceErv extends EventEmitter {
418
417
  .onSet(async (value) => {
419
418
  try {
420
419
  deviceData.Device.DefaultCoolingSetTemperature = value;
421
- await this.melCloudErv.send(this.accountType, this.displayType, deviceData, Ventilation.EffectiveFlags.SetTemperature);
422
420
  if (this.logInfo) this.emit('info', `Set cooling threshold temperature: ${value}${this.accessory.temperatureUnit}`);
421
+ await this.melCloudErv.send(this.accountType, this.displayType, deviceData, Ventilation.EffectiveFlags.SetTemperature);
423
422
  } catch (error) {
424
423
  if (this.logWarn) this.emit('warn', `Set cooling threshold temperature error: ${error}`);
425
424
  };
@@ -440,29 +439,13 @@ class DeviceErv extends EventEmitter {
440
439
  .onSet(async (value) => {
441
440
  try {
442
441
  deviceData.Device.DefaultHeatingSetTemperature = value;
443
- await this.melCloudErv.send(this.accountType, this.displayType, deviceData, Ventilation.EffectiveFlags.SetTemperature);
444
442
  if (this.logInfo) this.emit('info', `Set heating threshold temperature: ${value}${this.accessory.temperatureUnit}`);
443
+ await this.melCloudErv.send(this.accountType, this.displayType, deviceData, Ventilation.EffectiveFlags.SetTemperature);
445
444
  } catch (error) {
446
445
  if (this.logWarn) this.emit('warn', `Set heating threshold temperature error: ${error}`);
447
446
  };
448
447
  });
449
448
  };
450
- //this.melCloudService.getCharacteristic(Characteristic.LockPhysicalControls)
451
- // .onGet(async () => {
452
- // const value = this.accessory.lockPhysicalControl;
453
- // if (this.logInfo) this.emit('info', `Lock physical controls: ${value ? 'LOCKED' : 'UNLOCKED'}`);
454
- // return value;
455
- // })
456
- // .onSet(async (value) => {
457
- // try {
458
- // value = value ? true : false;
459
- // deviceData.Device = deviceData.Device;
460
- // await this.melCloudErv.send(this.accountType, this.displayType, deviceData, Ventilation.EffectiveFlags.Prohibit);
461
- // if (this.logInfo) this.emit('info', `Set local physical controls: ${value ? 'LOCK' : 'UNLOCK'}`);
462
- // } catch (error) {
463
- // if (this.logWarn) this.emit('warn', `Set lock physical controls error: ${error}`);
464
- // };
465
- // });
466
449
  this.melCloudService.getCharacteristic(Characteristic.TemperatureDisplayUnits)
467
450
  .onGet(async () => {
468
451
  const value = this.accessory.useFahrenheit;
@@ -474,8 +457,8 @@ class DeviceErv extends EventEmitter {
474
457
  try {
475
458
  value = [false, true][value];
476
459
  this.accessory.useFahrenheit = value;
477
- this.emit('melCloud', 'UseFahrenheit', value);
478
460
  if (this.logInfo) this.emit('info', `Set temperature display unit: ${TemperatureDisplayUnits[value]}`);
461
+ this.emit('melCloud', 'UseFahrenheit', value);
479
462
  } catch (error) {
480
463
  if (this.logWarn) this.emit('warn', `Set temperature display unit error: ${error}`);
481
464
  };
@@ -526,9 +509,8 @@ class DeviceErv extends EventEmitter {
526
509
  break;
527
510
  };
528
511
 
512
+ if (this.logInfo) this.emit('info', `Set operation mode: ${Ventilation.VentilationModeMapEnumToString[deviceData.Device.VentilationMode]}`);
529
513
  await this.melCloudErv.send(this.accountType, this.displayType, deviceData, flag);
530
- const operationModeText = Ventilation.VentilationModeMapEnumToString[deviceData.Device.VentilationMode];
531
- if (this.logInfo) this.emit('info', `Set operation mode: ${operationModeText}`);
532
514
  } catch (error) {
533
515
  if (this.logWarn) this.emit('warn', `Set operation mode error: ${error}`);
534
516
  };
@@ -551,8 +533,8 @@ class DeviceErv extends EventEmitter {
551
533
  .onSet(async (value) => {
552
534
  try {
553
535
  deviceData.Device.SetTemperature = value;
554
- await this.melCloudErv.send(this.accountType, this.displayType, deviceData, Ventilation.EffectiveFlags.SetTemperature);
555
536
  if (this.logInfo) this.emit('info', `Set temperature: ${value}${this.accessory.temperatureUnit}`);
537
+ await this.melCloudErv.send(this.accountType, this.displayType, deviceData, Ventilation.EffectiveFlags.SetTemperature);
556
538
  } catch (error) {
557
539
  if (this.logWarn) this.emit('warn', `Set temperature error: ${error}`);
558
540
  };
@@ -568,8 +550,8 @@ class DeviceErv extends EventEmitter {
568
550
  try {
569
551
  value = [false, true][value];
570
552
  this.accessory.useFahrenheit = value;
571
- this.emit('melCloud', 'UseFahrenheit', value);
572
553
  if (this.logInfo) this.emit('info', `Set temperature display unit: ${TemperatureDisplayUnits[value]}`);
554
+ this.emit('melCloud', 'UseFahrenheit', value);
573
555
  } catch (error) {
574
556
  if (this.logWarn) this.emit('warn', `Set temperature display unit error: ${error}`);
575
557
  };
@@ -759,8 +741,8 @@ class DeviceErv extends EventEmitter {
759
741
  .onSet(async (state) => {
760
742
  try {
761
743
  deviceData.HolidayMode.Enabled = state;
762
- await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'holidaymode');
763
- if (this.logInfo) this.emit('info', `Holiday mode: ${state ? 'Enabled' : 'Disabled'}`);
744
+ if (this.logInfo) this.emit('info', `Holiday mode: ${state ? 'Enable' : 'Disable'}`);
745
+ await this.melCloudErv.send(this.accountType, this.displayType, deviceData, 'holidaymode');
764
746
  } catch (error) {
765
747
  if (this.logWarn) this.emit('warn', `Set holiday mode error: ${error}`);
766
748
  };
@@ -841,8 +823,8 @@ class DeviceErv extends EventEmitter {
841
823
  break;
842
824
  };
843
825
 
844
- await this.melCloudAta.send(this.accountType, this.displayType, deviceData, AirConditioner.EffectiveFlags.Presets);
845
- if (this.logInfo) this.emit('info', `Preset ${name}: ${state ? 'Set:' : 'Unset:'} ${name}`);
826
+ if (this.logInfo) this.emit('info', `Preset ${name}: ${state ? 'Set:' : 'Unset:'}`);
827
+ await this.melCloudErv.send(this.accountType, this.displayType, deviceData, AirConditioner.EffectiveFlags.Presets);
846
828
  } catch (error) {
847
829
  if (this.logWarn) this.emit('warn', `Set preset error: ${error}`);
848
830
  };
@@ -898,10 +880,10 @@ class DeviceErv extends EventEmitter {
898
880
  .onSet(async (state) => {
899
881
  try {
900
882
  deviceData.ScheduleEnabled = state;
901
- await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'schedule');
902
- if (this.logInfo) this.emit('info', `Schedule ${name}: ${state ? 'Enabled' : 'Disabled'}`);
883
+ if (this.logInfo) this.emit('info', `Schedules: ${state ? 'Enable' : 'Disable'}`);
884
+ await this.melCloudErv.send(this.accountType, this.displayType, deviceData, 'schedule');
903
885
  } catch (error) {
904
- if (this.logWarn) this.emit('warn', `Set schedule error: ${error}`);
886
+ if (this.logWarn) this.emit('warn', `Set schedule serror: ${error}`);
905
887
  };
906
888
  });
907
889
  accessory.addService(this.scheduleControlService);
@@ -967,8 +949,8 @@ class DeviceErv extends EventEmitter {
967
949
  .onSet(async (state) => {
968
950
  try {
969
951
  sceneData.Enabled = state;
970
- await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'scene', sceneData);
971
- if (this.logInfo) this.emit('info', `Scene ${name}: ${state ? 'Enabled' : 'Disabled'}`);
952
+ if (this.logInfo) this.emit('info', `Scene ${name}: ${state ? 'Enable' : 'Disable'}`);
953
+ await this.melCloudErv.send(this.accountType, this.displayType, deviceData, 'scene', sceneData);
972
954
  } catch (error) {
973
955
  if (this.logWarn) this.emit('warn', `Set scene error: ${error}`);
974
956
  };
@@ -993,116 +975,135 @@ class DeviceErv extends EventEmitter {
993
975
 
994
976
  //buttons services
995
977
  if (this.buttons.length > 0) {
996
- if (this.logDebug) this.emit('debug', `Prepare buttons services`);
997
- this.buttonsServices = [];
978
+ if (this.logDebug) this.emit('debug', `Prepare buttons / sensors services`);
979
+ this.buttonControlServices = [];
980
+ this.buttonControlSensorServices = [];
998
981
  this.buttons.forEach((button, i) => {
999
982
  //get button mode
1000
983
  const mode = button.mode;
1001
984
 
1002
985
  //get button name
1003
- const buttonName = button.name;
986
+ const name = button.name;
1004
987
 
1005
988
  //get button name prefix
1006
989
  const namePrefix = button.namePrefix;
1007
990
 
1008
- const serviceName1 = namePrefix ? `${accessoryName} ${buttonName}` : buttonName;
991
+ const serviceName1 = namePrefix ? `${accessoryName} ${name}` : name;
1009
992
  const serviceType = button.serviceType;
1010
993
  const characteristicType = button.characteristicType;
1011
- const buttonService = new serviceType(serviceName1, `Button ${deviceId} ${i}`);
1012
- buttonService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1013
- buttonService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
1014
- buttonService.getCharacteristic(characteristicType)
994
+
995
+ //control
996
+ if (button.displayType > 3) {
997
+ if (this.logDebug) this.emit('debug', `Prepare button control ${name} service`);
998
+ const buttonControlService = new serviceType(serviceName1, `buttonControlService${deviceId} ${i}`);
999
+ buttonControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1000
+ buttonControlService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
1001
+ buttonControlService.getCharacteristic(Characteristic.On)
1002
+ .onGet(async () => {
1003
+ const state = button.state;
1004
+ return state;
1005
+ })
1006
+ .onSet(async (state) => {
1007
+ try {
1008
+ let flag = null;
1009
+ switch (mode) {
1010
+ case 0: //POWER ON,OFF
1011
+ deviceData.Device.Power = state;
1012
+ flag = Ventilation.EffectiveFlags.Power;
1013
+ break;
1014
+ case 1: //OPERATING MODE RECOVERY
1015
+ button.previousValue = state ? deviceData.Device.VentilationMode : button.previousValue ?? deviceData.Device.VentilationMode;
1016
+ deviceData.Device.Power = true;
1017
+ deviceData.Device.VentilationMode = state ? 0 : button.previousValue;
1018
+ flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.VentilationMode;
1019
+ break;
1020
+ case 2: //OPERATING MODE BYPASS
1021
+ button.previousValue = state ? deviceData.Device.VentilationMode : button.previousValue ?? deviceData.Device.VentilationMode;
1022
+ deviceData.Device.Power = true;
1023
+ deviceData.Device.VentilationMode = state ? 1 : button.previousValue;
1024
+ flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.VentilationMode;
1025
+ break
1026
+ case 3: //OPERATING MODE AUTO
1027
+ button.previousValue = state ? deviceData.Device.VentilationMode : button.previousValue ?? deviceData.Device.VentilationMode;
1028
+ deviceData.Device.Power = true;
1029
+ deviceData.Device.VentilationMode = state ? 2 : button.previousValue;
1030
+ flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.VentilationMode;
1031
+ break;
1032
+ case 4: //NIGHT PURGE MODE
1033
+ deviceData.Device.Power = true;
1034
+ deviceData.Device.NightPurgeMode = state;
1035
+ flag = Ventilation.EffectiveFlags.Power
1036
+ break;
1037
+ case 10: //FAN SPEED MODE AUTO
1038
+ button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
1039
+ deviceData.Device.Power = true;
1040
+ deviceData.Device.SetFanSpeed = state ? 0 : button.previousValue;
1041
+ flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
1042
+ break;
1043
+ case 11: //FAN SPEED MODE 1
1044
+ button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
1045
+ deviceData.Device.Power = true;
1046
+ deviceData.Device.SetFanSpeed = state ? 1 : button.previousValue;
1047
+ flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
1048
+ break;
1049
+ case 12: //FAN SPEED MODE 2
1050
+ button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
1051
+ deviceData.Device.Power = true;
1052
+ deviceData.Device.SetFanSpeed = state ? 2 : button.previousValue;
1053
+ flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
1054
+ break;
1055
+ case 13: //FAN SPEED MODE 3
1056
+ button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
1057
+ deviceData.Device.Power = true;
1058
+ deviceData.Device.SetFanSpeed = state ? 3 : button.previousValue;
1059
+ flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
1060
+ break;
1061
+ case 14: //FAN MODE 4
1062
+ button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
1063
+ deviceData.Device.Power = true;
1064
+ deviceData.Device.SetFanSpeed = state ? 4 : button.previousValue;
1065
+ flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
1066
+ break;
1067
+ case 15: //PHYSICAL LOCK CONTROLS
1068
+ deviceData.Device = deviceData.Device;
1069
+ flag = Ventilation.EffectiveFlags.Prohibit;
1070
+ break;
1071
+ case 16: //ROOM TEMP HIDE
1072
+ deviceData.HideRoomTemperature = state;
1073
+ break;
1074
+ case 17: //SUPPLY TEMP HIDE
1075
+ deviceData.HideSupplyTemperature = state;
1076
+ break;
1077
+ case 18: //OUTDOOR EMP HIDE
1078
+ deviceData.hideOutdoorTemperature = state;
1079
+ break;
1080
+ default:
1081
+ if (this.logWarn) this.emit('warn', `Unknown button mode: ${mode}`);
1082
+ break;
1083
+ };
1084
+
1085
+ if (this.logInfo) this.emit('info', `${state ? `Set: ${name}` : `Unset: ${name}, Set: ${button.previousValue}`}`);
1086
+ await this.melCloudErv.send(this.accountType, this.displayType, deviceData, flag);
1087
+ } catch (error) {
1088
+ if (this.logWarn) this.emit('warn', `Set button error: ${error}`);
1089
+ };
1090
+ });
1091
+ this.buttonControlServices.push(buttonControlService);
1092
+ accessory.addService(buttonControlService);
1093
+ }
1094
+
1095
+ //sensor
1096
+ if (this.logDebug) this.emit('debug', `Prepare button control sensor ${name} service`);
1097
+ const buttonControlSensorService = new serviceType(serviceName1, `buttonControlSensorService${deviceId} ${i}`);
1098
+ buttonControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1099
+ buttonControlSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
1100
+ buttonControlSensorService.getCharacteristic(characteristicType)
1015
1101
  .onGet(async () => {
1016
1102
  const state = button.state;
1017
1103
  return state;
1018
1104
  })
1019
- .onSet(async (state) => {
1020
- try {
1021
- let flag = null;
1022
- switch (mode) {
1023
- case 0: //POWER ON,OFF
1024
- deviceData.Device.Power = state;
1025
- flag = Ventilation.EffectiveFlags.Power;
1026
- break;
1027
- case 1: //OPERATING MODE RECOVERY
1028
- button.previousValue = state ? deviceData.Device.VentilationMode : button.previousValue ?? deviceData.Device.VentilationMode;
1029
- deviceData.Device.Power = true;
1030
- deviceData.Device.VentilationMode = state ? 0 : button.previousValue;
1031
- flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.VentilationMode;
1032
- break;
1033
- case 2: //OPERATING MODE BYPASS
1034
- button.previousValue = state ? deviceData.Device.VentilationMode : button.previousValue ?? deviceData.Device.VentilationMode;
1035
- deviceData.Device.Power = true;
1036
- deviceData.Device.VentilationMode = state ? 1 : button.previousValue;
1037
- flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.VentilationMode;
1038
- break
1039
- case 3: //OPERATING MODE AUTO
1040
- button.previousValue = state ? deviceData.Device.VentilationMode : button.previousValue ?? deviceData.Device.VentilationMode;
1041
- deviceData.Device.Power = true;
1042
- deviceData.Device.VentilationMode = state ? 2 : button.previousValue;
1043
- flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.VentilationMode;
1044
- break;
1045
- case 4: //NIGHT PURGE MODE
1046
- deviceData.Device.Power = true;
1047
- deviceData.Device.NightPurgeMode = state;
1048
- flag = Ventilation.EffectiveFlags.Power
1049
- break;
1050
- case 10: //FAN SPEED MODE AUTO
1051
- button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
1052
- deviceData.Device.Power = true;
1053
- deviceData.Device.SetFanSpeed = state ? 0 : button.previousValue;
1054
- flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
1055
- break;
1056
- case 11: //FAN SPEED MODE 1
1057
- button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
1058
- deviceData.Device.Power = true;
1059
- deviceData.Device.SetFanSpeed = state ? 1 : button.previousValue;
1060
- flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
1061
- break;
1062
- case 12: //FAN SPEED MODE 2
1063
- button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
1064
- deviceData.Device.Power = true;
1065
- deviceData.Device.SetFanSpeed = state ? 2 : button.previousValue;
1066
- flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
1067
- break;
1068
- case 13: //FAN SPEED MODE 3
1069
- button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
1070
- deviceData.Device.Power = true;
1071
- deviceData.Device.SetFanSpeed = state ? 3 : button.previousValue;
1072
- flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
1073
- break;
1074
- case 14: //FAN MODE 4
1075
- button.previousValue = state ? deviceData.Device.SetFanSpeed : button.previousValue ?? deviceData.Device.SetFanSpeed;
1076
- deviceData.Device.Power = true;
1077
- deviceData.Device.SetFanSpeed = state ? 4 : button.previousValue;
1078
- flag = Ventilation.EffectiveFlags.Power + Ventilation.EffectiveFlags.SetFanSpeed;
1079
- break;
1080
- case 15: //PHYSICAL LOCK CONTROLS
1081
- deviceData.Device = deviceData.Device;
1082
- flag = Ventilation.EffectiveFlags.Prohibit;
1083
- break;
1084
- case 16: //ROOM TEMP HIDE
1085
- deviceData.HideRoomTemperature = state;
1086
- break;
1087
- case 17: //SUPPLY TEMP HIDE
1088
- deviceData.HideSupplyTemperature = state;
1089
- break;
1090
- case 18: //OUTDOOR EMP HIDE
1091
- deviceData.hideOutdoorTemperature = state;
1092
- break;
1093
- default:
1094
- if (this.logWarn) this.emit('warn', `Unknown button mode: ${mode}`);
1095
- break;
1096
- };
1097
-
1098
- await this.melCloudErv.send(this.accountType, this.displayType, deviceData, flag);
1099
- if (this.logInfo) this.emit('info', `${state ? `Set: ${buttonName}` : `Unset: ${buttonName}, Set: ${button.previousValue}`}`);
1100
- } catch (error) {
1101
- if (this.logWarn) this.emit('warn', `Set button error: ${error}`);
1102
- };
1103
- });
1104
- this.buttonsServices.push(buttonService);
1105
- accessory.addService(buttonService);
1105
+ this.buttonControlSensorServices.push(buttonControlSensorService);
1106
+ accessory.addService(buttonControlSensorService);
1106
1107
  });
1107
1108
  };
1108
1109
 
@@ -1518,9 +1519,14 @@ class DeviceErv extends EventEmitter {
1518
1519
  break;
1519
1520
  };
1520
1521
 
1521
- //update services
1522
- const characteristicType = button.characteristicType;
1523
- this.buttonsServices?.[i]?.updateCharacteristic(characteristicType, button.state);
1522
+ //control
1523
+ if (button.displayType > 3) {
1524
+ this.buttonControlServices?.[i]?.updateCharacteristic(Characteristic.On, button.state);
1525
+ }
1526
+
1527
+ //sensor
1528
+ const characteristicType = scene.characteristicType;
1529
+ this.buttonControlSensorServices?.[i]?.updateCharacteristic(characteristicType, button.state);
1524
1530
  });
1525
1531
  };
1526
1532
 
package/src/melcloud.js CHANGED
@@ -57,12 +57,7 @@ class MelCloud extends EventEmitter {
57
57
  try {
58
58
  const devicesList = { State: false, Info: null, Devices: [], Scenes: [] }
59
59
  if (this.logDebug) this.emit('debug', `Scanning for devices...`);
60
- const listDevicesData = await axios(ApiUrls.ListDevices, {
61
- method: 'GET',
62
- baseURL: ApiUrls.BaseURL,
63
- timeout: 15000,
64
- headers: this.headers
65
- });
60
+ const listDevicesData = await this.axiosInstance(ApiUrls.ListDevices, { method: 'GET', });
66
61
 
67
62
  if (!listDevicesData || !listDevicesData.data) {
68
63
  devicesList.Info = 'Invalid or empty response from MELCloud API'
@@ -168,15 +163,20 @@ class MelCloud extends EventEmitter {
168
163
  return accountInfo;
169
164
  }
170
165
 
171
- this.headers = {
166
+ const headers = {
172
167
  'X-MitsContextKey': contextKey,
173
168
  'Content-Type': 'application/json'
174
169
  };
170
+ this.headers = headers;
171
+ this.axiosInstance = axios.create({
172
+ baseURL: ApiUrls.BaseURL,
173
+ timeout: 30000,
174
+ headers: headers
175
+ });
175
176
 
176
177
  accountInfo.State = true;
177
178
  accountInfo.Info = 'Connect to MELCloud Success';
178
179
  accountInfo.LoginData = loginData;
179
- accountInfo.Headers = this.headers;
180
180
  await this.functions.saveData(this.accountFile, accountInfo);
181
181
 
182
182
  return accountInfo
@@ -188,13 +188,7 @@ class MelCloud extends EventEmitter {
188
188
  async send(accountInfo) {
189
189
  try {
190
190
  const payload = { data: accountInfo.LoginData };
191
- await axios(ApiUrls.UpdateApplicationOptions, {
192
- method: 'POST',
193
- baseURL: ApiUrls.BaseURL,
194
- timeout: 15000,
195
- headers: accountInfo.Headers,
196
- data: payload
197
- });
191
+ await this.axiosInstance(ApiUrls.UpdateApplicationOptions, { method: 'POST', data: payload });
198
192
  await this.functions.saveData(this.accountFile, accountInfo);
199
193
  return true;
200
194
  } catch (error) {
@@ -23,7 +23,7 @@ class MelCloudAta extends EventEmitter {
23
23
 
24
24
  //set default values
25
25
  this.deviceData = {};
26
- this.headers = {};
26
+ this.baseURL = this.accountType === 'melcloud' ? ApiUrls.BaseURL : ApiUrlsHome.BaseURL;
27
27
 
28
28
  //lock flag
29
29
  this.locks = true;
@@ -53,12 +53,15 @@ class MelCloudAta extends EventEmitter {
53
53
  try {
54
54
  //read device info from file
55
55
  const devicesData = await this.functions.readData(this.devicesFile, true);
56
- this.headers = devicesData.Headers;
57
- const scenes = devicesData.Scenes ?? [];
58
- const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
56
+ this.axiosInstance = axios.create({
57
+ baseURL: this.baseURL,
58
+ timeout: 30000,
59
+ headers: devicesData.Headers
60
+ });
59
61
 
62
+ const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
60
63
  if (this.accountType === 'melcloudhome') {
61
- deviceData.Scenes = scenes;
64
+ deviceData.Scenes = devicesData.Scenes ?? [];
62
65
  deviceData.Device.OperationMode = AirConditioner.OperationModeMapStringToEnum[deviceData.Device.OperationMode] ?? deviceData.Device.OperationMode;
63
66
  deviceData.Device.ActualFanSpeed = AirConditioner.FanSpeedMapStringToEnum[deviceData.Device.ActualFanSpeed] ?? deviceData.Device.ActualFanSpeed;
64
67
  deviceData.Device.SetFanSpeed = AirConditioner.FanSpeedMapStringToEnum[deviceData.Device.SetFanSpeed] ?? deviceData.Device.SetFanSpeed;
@@ -163,13 +166,7 @@ class MelCloudAta extends EventEmitter {
163
166
  };
164
167
 
165
168
  if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}`);
166
- await axios(ApiUrls.SetAta, {
167
- method: 'POST',
168
- baseURL: ApiUrls.BaseURL,
169
- timeout: 10000,
170
- headers: this.headers,
171
- data: payload
172
- });
169
+ await this.axiosInstance(path, { method: 'POST', data: payload });
173
170
  this.updateData(deviceData);
174
171
  return true;
175
172
  case "melcloudhome":
@@ -195,7 +192,7 @@ class MelCloudAta extends EventEmitter {
195
192
  };
196
193
  method = 'POST';
197
194
  path = ApiUrlsHome.PostProtectionFrost;
198
- this.headers.Referer = ApiUrlsHome.Referers.PostProtectionFrost.replace('deviceid', deviceData.DeviceID);
195
+ //this.headers.Referer = ApiUrlsHome.Referers.PostProtectionFrost.replace('deviceid', deviceData.DeviceID);
199
196
  break;
200
197
  case 'overheatprotection':
201
198
  payload = {
@@ -206,7 +203,7 @@ class MelCloudAta extends EventEmitter {
206
203
  };
207
204
  method = 'POST';
208
205
  path = ApiUrlsHome.PostProtectionOverheat;
209
- this.headers.Referer = ApiUrlsHome.Referers.PostProtectionOverheat.replace('deviceid', deviceData.DeviceID);
206
+ //this.headers.Referer = ApiUrlsHome.Referers.PostProtectionOverheat.replace('deviceid', deviceData.DeviceID);
210
207
  break;
211
208
  case 'holidaymode':
212
209
  payload = {
@@ -217,19 +214,19 @@ class MelCloudAta extends EventEmitter {
217
214
  };
218
215
  method = 'POST';
219
216
  path = ApiUrlsHome.PostHolidayMode;
220
- this.headers.Referer = ApiUrlsHome.Referers.PostHolidayMode.replace('deviceid', deviceData.DeviceID);
217
+ //this.headers.Referer = ApiUrlsHome.Referers.PostHolidayMode.replace('deviceid', deviceData.DeviceID);
221
218
  break;
222
219
  case 'schedule':
223
220
  payload = { enabled: deviceData.ScheduleEnabled };
224
221
  method = 'PUT';
225
222
  path = ApiUrlsHome.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
226
- this.headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
223
+ //this.headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
227
224
  break;
228
225
  case 'scene':
229
226
  method = 'PUT';
230
227
  const state = flagData.Enabled ? 'Enable' : 'Disable';
231
228
  path = ApiUrlsHome.PutScene[state].replace('sceneid', flagData.Id);
232
- this.headers.Referer = ApiUrlsHome.Referers.GetPutScenes;
229
+ //this.headers.Referer = ApiUrlsHome.Referers.GetPutScenes;
233
230
  break;
234
231
  default:
235
232
  payload = {
@@ -244,20 +241,14 @@ class MelCloudAta extends EventEmitter {
244
241
  };
245
242
  method = 'PUT';
246
243
  path = ApiUrlsHome.PutAta.replace('deviceid', deviceData.DeviceID);
247
- this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
244
+ //this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings;
248
245
  break
249
246
  }
250
247
 
251
- this.headers['Content-Type'] = 'application/json; charset=utf-8';
252
- this.headers.Origin = ApiUrlsHome.Origin;
248
+ //this.headers['Content-Type'] = 'application/json; charset=utf-8';
249
+ //this.headers.Origin = ApiUrlsHome.Origin;
253
250
  if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}, Headers: ${JSON.stringify(this.headers, null, 2)}`);
254
- await axios(path, {
255
- method: method,
256
- baseURL: ApiUrlsHome.BaseURL,
257
- timeout: 10000,
258
- headers: this.headers,
259
- data: payload
260
- });
251
+ await this.axiosInstance(path, { method: method, data: payload });
261
252
  this.updateData(deviceData);
262
253
  return true;
263
254
  default: