homebridge-melcloud-control 4.0.0-beta.119 → 4.0.0-beta.120

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.0.0-beta.119",
4
+ "version": "4.0.0-beta.120",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/constants.js CHANGED
@@ -46,7 +46,7 @@ export const AirConditioner = {
46
46
  "SPLIT", "9", "10", "11", "SWING"
47
47
  ],
48
48
  AirDirection: ["AUTO", "SWING"],
49
- FanSpeed: [
49
+ FanSpeedMapHomekit: [
50
50
  "AUTO", "1", "QUIET", "WEAK", "4",
51
51
  "STRONG", "VERY STRONG", "OFF"
52
52
  ],
package/src/deviceata.js CHANGED
@@ -353,31 +353,32 @@ class DeviceAta extends EventEmitter {
353
353
  .onSet(async (value) => {
354
354
  try {
355
355
  let fanSpeedModeText = '';
356
+ const key = this.accountType === 'melcloud' ? 'FanSpeed' : 'SetFanSpeed';
356
357
  switch (numberOfFanSpeeds) {
357
358
  case 2: //Fan speed mode 2
358
359
  fanSpeedModeText = hasAutomaticFanSpeed ? [7, 1, 2, 0][value] : [7, 1, 2][value];
359
- deviceData.Device.FanSpeed = hasAutomaticFanSpeed ? [0, 1, 2, 0][value] : [1, 1, 2][value];
360
+ deviceData.Device[key] = hasAutomaticFanSpeed ? [0, 1, 2, 0][value] : [1, 1, 2][value];
360
361
  break;
361
362
  case 3: //Fan speed mode 3
362
363
  fanSpeedModeText = hasAutomaticFanSpeed ? [7, 1, 2, 3, 0][value] : [7, 1, 2, 3][value];
363
- deviceData.Device.FanSpeed = hasAutomaticFanSpeed ? [0, 1, 2, 3, 0][value] : [1, 1, 2, 3][value];
364
+ deviceData.Device[key] = hasAutomaticFanSpeed ? [0, 1, 2, 3, 0][value] : [1, 1, 2, 3][value];
364
365
  break;
365
366
  case 4: //Fan speed mode 4
366
367
  fanSpeedModeText = hasAutomaticFanSpeed ? [7, 1, 2, 3, 4, 0][value] : [7, 1, 2, 3, 4][value];
367
- deviceData.Device.FanSpeed = hasAutomaticFanSpeed ? [0, 1, 2, 3, 4, 0][value] : [1, 1, 2, 3, 4][value];
368
+ deviceData.Device[key] = hasAutomaticFanSpeed ? [0, 1, 2, 3, 4, 0][value] : [1, 1, 2, 3, 4][value];
368
369
  break;
369
370
  case 5: //Fan speed mode 5
370
371
  5; fanSpeedModeText = hasAutomaticFanSpeed ? [7, 1, 2, 3, 4, 5, 0][value] : [7, 1, 2, 3, 4, 5][value];
371
- deviceData.Device.FanSpeed = hasAutomaticFanSpeed ? [0, 1, 2, 3, 4, 5, 0][value] : [1, 1, 2, 3, 4, 5][value];
372
+ deviceData.Device[key] = hasAutomaticFanSpeed ? [0, 1, 2, 3, 4, 5, 0][value] : [1, 1, 2, 3, 4, 5][value];
372
373
  break;
373
374
  case 6: //Fan speed mode 6
374
375
  fanSpeedModeText = hasAutomaticFanSpeed ? [7, 1, 2, 3, 4, 5, 6, 0][value] : [7, 1, 2, 3, 4, 5, 6][value];
375
- deviceData.Device.FanSpeed = hasAutomaticFanSpeed ? [0, 1, 2, 3, 4, 5, 6, 0][value] : [1, 1, 2, 3, 4, 5, 6][value];
376
+ deviceData.Device[key] = hasAutomaticFanSpeed ? [0, 1, 2, 3, 4, 5, 6, 0][value] : [1, 1, 2, 3, 4, 5, 6][value];
376
377
  break;
377
378
  };
378
379
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.SetFanSpeed;
379
380
  await this.melCloudAta.send(this.accountType, deviceData, this.displayMode);
380
- if (this.logInfo) this.emit('info', `Set fan speed mode: ${AirConditioner.FanSpeed[fanSpeedModeText]}`);
381
+ if (this.logInfo) this.emit('info', `Set fan speed mode: ${AirConditioner.FanSpeedMapHomekit[fanSpeedModeText]}`);
381
382
  } catch (error) {
382
383
  if (this.logWarn) this.emit('warn', `Set fan speed mode error: ${error}`);
383
384
  };
@@ -636,6 +637,7 @@ class DeviceAta extends EventEmitter {
636
637
  })
637
638
  .onSet(async (state) => {
638
639
  try {
640
+ const key = this.accountType === 'melcloud' ? 'FanSpeed' : 'SetFanSpeed';
639
641
  switch (state) {
640
642
  case true:
641
643
  preset.previousSettings = deviceData.Device;
@@ -644,7 +646,7 @@ class DeviceAta extends EventEmitter {
644
646
  deviceData.Device.SetTemperature = presetData.SetTemperature;
645
647
  deviceData.Device.VaneHorizontalDirection = presetData.VaneHorizontal;
646
648
  deviceData.Device.VaneVerticalDirection = presetData.VaneVertical;
647
- deviceData.Device.FanSpeed = presetData.FanSpeed;
649
+ deviceData.Device[key] = presetData[key];
648
650
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.Presets;
649
651
  break;
650
652
  case false:
@@ -653,7 +655,7 @@ class DeviceAta extends EventEmitter {
653
655
  deviceData.Device.SetTemperature = preset.previousSettings.SetTemperature;
654
656
  deviceData.Device.VaneHorizontalDirection = preset.previousSettings.VaneHorizontalDirection;
655
657
  deviceData.Device.VaneVerticalDirection = preset.previousSettings.VaneVerticalDirection;
656
- deviceData.Device.FanSpeed = preset.previousSettings.FanSpeed;
658
+ deviceData.Device[key] = preset.previousSettings[key];
657
659
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.Presets;
658
660
  break;
659
661
  };
@@ -696,6 +698,7 @@ class DeviceAta extends EventEmitter {
696
698
  })
697
699
  .onSet(async (state) => {
698
700
  try {
701
+ const key = this.accountType === 'melcloud' ? 'FanSpeed' : 'SetFanSpeed';
699
702
  switch (mode) {
700
703
  case 0: //POWER ON,OFF
701
704
  deviceData.Device.Power = state;
@@ -834,45 +837,45 @@ class DeviceAta extends EventEmitter {
834
837
  deviceData.HideVaneControls = state;
835
838
  break;
836
839
  case 30: //FAN SPEED MODE AUTO
837
- button.previousValue = state ? deviceData.Device.FanSpeed : button.previousValue ?? deviceData.Device.FanSpeed;
840
+ button.previousValue = state ? deviceData.Device[key] : button.previousValue ?? deviceData.Device[key];
838
841
  deviceData.Device.Power = true;
839
- deviceData.Device.FanSpeed = state ? 0 : button.previousValue;
842
+ deviceData.Device[key] = state ? 0 : button.previousValue;
840
843
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.PowerSetFanSpeed;
841
844
  break;
842
845
  case 31: //FAN SPEED MODE 1
843
- button.previousValue = state ? deviceData.Device.FanSpeed : button.previousValue ?? deviceData.Device.FanSpeed;
846
+ button.previousValue = state ? deviceData.Device[key] : button.previousValue ?? deviceData.Device[key];
844
847
  deviceData.Device.Power = true;
845
- deviceData.Device.FanSpeed = state ? 1 : button.previousValue;
848
+ deviceData.Device[key] = state ? 1 : button.previousValue;
846
849
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.PowerSetFanSpeed;
847
850
  break;
848
851
  case 32: //FAN SPEED MODE 2
849
- button.previousValue = state ? deviceData.Device.FanSpeed : button.previousValue ?? deviceData.Device.FanSpeed;
852
+ button.previousValue = state ? deviceData.Device[key] : button.previousValue ?? deviceData.Device[key];
850
853
  deviceData.Device.Power = true;
851
- deviceData.Device.FanSpeed = state ? 2 : button.previousValue;
854
+ deviceData.Device[key] = state ? 2 : button.previousValue;
852
855
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.PowerSetFanSpeed;
853
856
  break;
854
857
  case 33: //FAN SPEED MODE 3
855
- button.previousValue = state ? deviceData.Device.FanSpeed : button.previousValue ?? deviceData.Device.FanSpeed;
858
+ button.previousValue = state ? deviceData.Device[key] : button.previousValue ?? deviceData.Device[key];
856
859
  deviceData.Device.Power = true;
857
- deviceData.Device.FanSpeed = state ? 3 : button.previousValue;
860
+ deviceData.Device[key] = state ? 3 : button.previousValue;
858
861
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.PowerSetFanSpeed;
859
862
  break;
860
863
  case 34: //FAN MODE 4
861
- button.previousValue = state ? deviceData.Device.FanSpeed : button.previousValue ?? deviceData.Device.FanSpeed;
864
+ button.previousValue = state ? deviceData.Device[key] : button.previousValue ?? deviceData.Device[key];
862
865
  deviceData.Device.Power = true;
863
- deviceData.Device.FanSpeed = state ? 4 : button.previousValue;
866
+ deviceData.Device[key] = state ? 4 : button.previousValue;
864
867
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.PowerSetFanSpeed;
865
868
  break;
866
869
  case 35: //FAN SPEED MODE 5
867
- button.previousValue = state ? deviceData.Device.FanSpeed : button.previousValue ?? deviceData.Device.FanSpeed;
870
+ button.previousValue = state ? deviceData.Device[key] : button.previousValue ?? deviceData.Device[key];
868
871
  deviceData.Device.Power = true;
869
- deviceData.Device.FanSpeed = state ? 5 : button.previousValue;
872
+ deviceData.Device[key] = state ? 5 : button.previousValue;
870
873
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.PowerSetFanSpeed;
871
874
  break;
872
875
  case 36: //FAN SPEED MODE 6
873
- button.previousValue = state ? deviceData.Device.FanSpeed : button.previousValue ?? deviceData.Device.FanSpeed;
876
+ button.previousValue = state ? deviceData.Device[key] : button.previousValue ?? deviceData.Device[key];
874
877
  deviceData.Device.Power = true;
875
- deviceData.Device.FanSpeed = state ? 6 : button.previousValue;
878
+ deviceData.Device[key] = state ? 6 : button.previousValue;
876
879
  deviceData.Device.EffectiveFlags = AirConditioner.EffectiveFlags.PowerSetFanSpeed;
877
880
  break;
878
881
  case 37: //PHYSICAL LOCK CONTROLS
@@ -936,10 +939,10 @@ class DeviceAta extends EventEmitter {
936
939
  //accessory info
937
940
  this.manufacturer = manufacturer;
938
941
  this.model = modelIndoor ? modelIndoor : modelOutdoor ? modelOutdoor : `${this.deviceTypeText} ${this.deviceId}`;
939
- this.serialNumber = serialNumber;
940
- this.firmwareRevision = firmwareAppVersion;
942
+ this.serialNumber = serialNumber.toString();
943
+ this.firmwareRevision = firmwareAppVersion.toString();
941
944
 
942
- this.informationService?.setCharacteristic(Characteristic.FirmwareRevision, firmwareAppVersion);
945
+ this.informationService?.setCharacteristic(Characteristic.FirmwareRevision, this.firmwareAppVersion);
943
946
  })
944
947
  .on('deviceState', async (deviceData) => {
945
948
  if (this.accountType === 'melcloudhome') deviceData.Device.OperationMode = AirConditioner.OperationModeMapStringToEnum[deviceData.Device.OperationMode];
@@ -971,6 +974,7 @@ class DeviceAta extends EventEmitter {
971
974
  const maxTempCoolDry = 31;
972
975
 
973
976
  //device state
977
+ const key = this.accountType === 'melcloud' ? 'FanSpeed' : 'SetFanSpeed';
974
978
  const power = deviceData.Device.Power ?? false;
975
979
  const inStandbyMode = deviceData.Device.InStandbyMode ?? false;
976
980
  const roomTemperature = deviceData.Device.RoomTemperature;
@@ -979,7 +983,7 @@ class DeviceAta extends EventEmitter {
979
983
  const defaultCoolingSetTemperature = deviceData.Device.DefaultCoolingSetTemperature ?? 23;
980
984
  const actualFanSpeed = deviceData.Device.ActualFanSpeed;
981
985
  const automaticFanSpeed = deviceData.Device.AutomaticFanSpeed;
982
- const fanSpeed = this.accountMelcloud ? deviceData.Device.FanSpeed : deviceData.Device.SetFanSpeed;
986
+ const fanSpeed = deviceData.Device[key];
983
987
  const operationMode = deviceData.Device.OperationMode;
984
988
  const vaneVerticalDirection = deviceData.Device.VaneVerticalDirection;
985
989
  const vaneVerticalSwing = deviceData.Device.VaneVerticalSwing;
@@ -1183,7 +1187,7 @@ class DeviceAta extends EventEmitter {
1183
1187
  && presetData.OperationMode === operationMode
1184
1188
  && presetData.VaneHorizontal === vaneHorizontalDirection
1185
1189
  && presetData.VaneVertical === vaneVerticalDirection
1186
- && presetData.FanSpeed === fanSpeed) : false;
1190
+ && presetData[key] === fanSpeed) : false;
1187
1191
 
1188
1192
  const characteristicType = preset.characteristicType;
1189
1193
  this.presetsServices?.[i]?.updateCharacteristic(characteristicType, preset.state);
@@ -1319,8 +1323,8 @@ class DeviceAta extends EventEmitter {
1319
1323
  this.emit('info', `Target temperature: ${setTemperature}${obj.temperatureUnit}`);
1320
1324
  this.emit('info', `Current temperature: ${roomTemperature}${obj.temperatureUnit}`);
1321
1325
  const info = hasOutdoorTemperature && outdoorTemperature !== null ? this.emit('info', `Outdoor temperature: ${outdoorTemperature}${obj.temperatureUnit}`) : false;
1322
- const info3 = modelSupportsFanSpeed ? this.emit('info', `Target fan speed: ${AirConditioner.FanSpeed[fanSpeed]}`) : false;
1323
- const info4 = modelSupportsFanSpeed ? this.emit('info', `Current fan speed: ${AirConditioner.FanSpeed[actualFanSpeed]}`) : false;
1326
+ const info3 = modelSupportsFanSpeed ? this.emit('info', `Target fan speed: ${AirConditioner.FanSpeedMapHomekit[fanSpeed]}`) : false;
1327
+ const info4 = modelSupportsFanSpeed ? this.emit('info', `Current fan speed: ${AirConditioner.FanSpeedMapHomekit[actualFanSpeed]}`) : false;
1324
1328
  const info5 = vaneHorizontalDirection !== null ? this.emit('info', `Vane horizontal: ${AirConditioner.HorizontalVane[vaneHorizontalDirection] ?? vaneHorizontalDirection}`) : false;
1325
1329
  const info6 = vaneVerticalDirection !== null ? this.emit('info', `Vane vertical: ${AirConditioner.VerticalVane[vaneVerticalDirection] ?? vaneVerticalDirection}`) : false;
1326
1330
  const info7 = swingFunction ? this.emit('info', `Air direction: ${AirConditioner.AirDirection[obj.swingMode]}`) : false;
package/src/melcloud.js CHANGED
@@ -47,7 +47,7 @@ class MelCloud extends EventEmitter {
47
47
  this.impulseGenerator = new ImpulseGenerator()
48
48
  .on('connect', async () => {
49
49
  try {
50
- await this.connect();
50
+ await this.connect(true);
51
51
  } catch (error) {
52
52
  this.emit('error', `Impulse generator error: ${error}`);
53
53
  }
@@ -278,7 +278,7 @@ class MelCloud extends EventEmitter {
278
278
  }
279
279
  }
280
280
 
281
- async connectToMelCloudHome() {
281
+ async connectToMelCloudHome(refresh = false) {
282
282
  if (this.logDebug) this.emit('debug', `Connecting to MELCloud Home`);
283
283
 
284
284
  const browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] });
@@ -330,7 +330,7 @@ class MelCloud extends EventEmitter {
330
330
  this.contextKey = contextKey;
331
331
 
332
332
  await this.functions.saveData(this.accountFile, accountInfo);
333
- this.emit('success', `Connect to MELCloud Home Success`);
333
+ if (!refresh) this.emit('success', `Connect to MELCloud Home Success`);
334
334
 
335
335
  return accountInfo;
336
336
  } catch (error) {
@@ -354,14 +354,14 @@ class MelCloud extends EventEmitter {
354
354
  }
355
355
  }
356
356
 
357
- async connect() {
357
+ async connect(refresh) {
358
358
  let response = {};
359
359
  switch (this.accountType) {
360
360
  case "melcloud":
361
361
  response = await this.connectToMelCloud();
362
362
  return response
363
363
  case "melcloudhome":
364
- response = await this.connectToMelCloudHome();
364
+ response = await this.connectToMelCloudHome(refresh);
365
365
  return response
366
366
  default:
367
367
  return response
@@ -70,7 +70,7 @@ class MelCloudAta extends EventEmitter {
70
70
  //device info
71
71
  const hideVaneControls = deviceData.HideVaneControls ?? false;
72
72
  const hideDryModeControl = deviceData.HideDryModeControl ?? false;
73
- const serialNumber = deviceData.SerialNumber || deviceData.DeviceID || 'Undefined';
73
+ const serialNumber = deviceData.SerialNumber || deviceData.DeviceID || '4.0.0';
74
74
 
75
75
  //device
76
76
  const device = deviceData.Device ?? {};
@@ -83,6 +83,7 @@ class MelCloudAta extends EventEmitter {
83
83
  const setTemperature = device.SetTemperature;
84
84
  const actualFanSpeed = device.ActualFanSpeed;
85
85
  const fanSpeed = device.FanSpeed;
86
+ const setFanSpeed = device.SetFanSpeed; // melcloud home only
86
87
  const automaticFanSpeed = device.AutomaticFanSpeed;
87
88
  const vaneVerticalDirection = device.VaneVerticalDirection;
88
89
  const vaneVerticalSwing = device.VaneVerticalSwing;
@@ -147,7 +148,7 @@ class MelCloudAta extends EventEmitter {
147
148
 
148
149
  //display info if units are not configured in MELCloud service
149
150
  if (unitsCount === 0) {
150
- if (this.logWarn) this.emit('warn', `Units are not configured in MELCloud service`);
151
+ if (this.logDebug) this.emit('debug', `Units are not configured in MELCloud service`);
151
152
  };
152
153
 
153
154
  const deviceState = {
@@ -158,6 +159,7 @@ class MelCloudAta extends EventEmitter {
158
159
  SetTemperature: setTemperature,
159
160
  ActualFanSpeed: actualFanSpeed,
160
161
  FanSpeed: fanSpeed,
162
+ SetFanSpeed: setFanSpeed,
161
163
  AutomaticFanSpeed: automaticFanSpeed,
162
164
  OperationMode: operationMode,
163
165
  VaneVerticalDirection: vaneVerticalDirection,
@@ -201,12 +203,6 @@ class MelCloudAta extends EventEmitter {
201
203
  };
202
204
  };
203
205
 
204
- updateData(deviceData) {
205
- setTimeout(() => {
206
- this.emit('deviceState', deviceData);
207
- }, 500);
208
- }
209
-
210
206
  async send(accountType, deviceData, displayMode) {
211
207
  switch (accountType) {
212
208
  case "melcloud":
@@ -279,7 +275,7 @@ class MelCloudAta extends EventEmitter {
279
275
  }
280
276
 
281
277
  await axiosInstancePost(ApiUrls.SetAta, payload);
282
- this.updateData(deviceData);
278
+ this.emit('deviceState', deviceData);
283
279
  return true;
284
280
  } catch (error) {
285
281
  throw new Error(`Send data error: ${error}`);
@@ -324,7 +320,7 @@ class MelCloudAta extends EventEmitter {
324
320
  case 8: //AUTO
325
321
  deviceData.Device.SetTemperature = (deviceData.Device.DefaultCoolingSetTemperature + deviceData.Device.DefaultHeatingSetTemperature) / 2;
326
322
  break;
327
- case 9: //HISEE HEAT
323
+ case 9: //ISEE HEAT
328
324
  deviceData.Device.SetTemperature = deviceData.Device.DefaultHeatingSetTemperature;
329
325
  break;
330
326
  case 10: //ISEE DRY
@@ -342,12 +338,12 @@ class MelCloudAta extends EventEmitter {
342
338
  deviceData.Device.OperationMode = AirConditioner.OperationModeMapEnumToString[deviceData.Device.OperationMode];
343
339
  const payload = {
344
340
  data: {
345
- power: deviceData.Device.Power,
346
- setTemperature: deviceData.Device.SetTemperature,
347
- setFanSpeed: deviceData.Device.FanSpeed,
348
- operationMode: deviceData.Device.OperationMode,
349
- vaneHorizontalDirection: deviceData.Device.VaneHorizontalDirection,
350
- vaneVerticalDirection: deviceData.Device.VaneVerticalDirection
341
+ Power: deviceData.Device.Power,
342
+ SetTemperature: deviceData.Device.SetTemperature,
343
+ SetFanSpeed: deviceData.Device.SetFanSpeed,
344
+ OperationMode: deviceData.Device.OperationMode,
345
+ VaneHorizontalDirection: deviceData.Device.VaneHorizontalDirection,
346
+ VaneVerticalDirection: deviceData.Device.VaneVerticalDirection
351
347
  }
352
348
  }
353
349