homebridge-melcloud-control 2.3.0-beta.8 → 2.3.1-beta.0

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
@@ -29,15 +29,12 @@ class DeviceErv extends EventEmitter {
29
29
 
30
30
  //external integrations
31
31
  const restFul = account.restFul ?? {};
32
- const restFulEnabled = restFul.enable || false;
33
32
  this.restFulConnected = false;
34
33
  const mqtt = account.mqtt ?? {};
35
- const mqttEnabled = mqtt.enable || false;
36
34
  this.mqttConnected = false;
37
35
 
38
- //variables
36
+ //function
39
37
  this.melCloud = melCloud; //function
40
- this.startPrepareAccessory = true;
41
38
 
42
39
  //buttons configured
43
40
  this.buttonsConfigured = [];
@@ -60,6 +57,19 @@ class DeviceErv extends EventEmitter {
60
57
  }
61
58
  this.buttonsConfiguredCount = this.buttonsConfigured.length || 0;
62
59
 
60
+ //variables
61
+ this.startPrepareAccessory = true;
62
+ this.currentOperationMode = 0;
63
+ this.targetOperationMode = 0;
64
+ this.fanSpeed = 0;
65
+ this.lockPhysicalControl = 0;
66
+ this.useFahrenheit = 0;
67
+
68
+ this.operationModeSetPropsMinValue = 0;
69
+ this.operationModeSetPropsMaxValue = 3;
70
+ this.operationModeSetPropsValidValues = [0];
71
+ this.fanSpeedSetPropsMaxValue = 2;
72
+
63
73
  //melcloud device
64
74
  this.melCloudErv = new MelCloudErv({
65
75
  contextKey: contextKey,
@@ -71,6 +81,7 @@ class DeviceErv extends EventEmitter {
71
81
 
72
82
  this.melCloudErv.on('externalIntegrations', (deviceData, deviceState) => {
73
83
  //RESTFul server
84
+ const restFulEnabled = restFul.enable || false;
74
85
  if (restFulEnabled) {
75
86
  if (!this.restFulConnected) {
76
87
  this.restFul = new RestFul({
@@ -101,6 +112,7 @@ class DeviceErv extends EventEmitter {
101
112
  }
102
113
 
103
114
  //MQTT client
115
+ const mqttEnabled = mqtt.enable || false;
104
116
  if (mqttEnabled) {
105
117
  if (!this.mqttConnected) {
106
118
  this.mqtt = new Mqtt({
@@ -228,96 +240,141 @@ class DeviceErv extends EventEmitter {
228
240
  this.presets = presets;
229
241
  this.presetsCount = this.presetsEnabled ? presets.length : 0;
230
242
 
231
- //operating mode
232
- let currentOperationMode = 0;
233
- let targetOperationMode = 0;
234
- let fanSpeed = 0;
235
- let lockPhysicalControls = 0;
236
-
237
243
  //set temperature
238
244
  const targetTemperature = hasCoolOperationMode || hasHeatOperationMode ? setTemperature : 20;
239
- let operationModeSetPropsMinValue = 0;
240
- let operationModeSetPropsMaxValue = 3;
241
- let operationModeSetPropsValidValues = [0, 1, 2, 3];
242
- let fanSpeedSetPropsMaxValue = 2;
243
245
 
246
+ //operation mode - 0, HEAT, 2, COOL, 4, 5, 6, FAN, AUTO
244
247
  switch (displayMode) {
245
248
  case 0: //Heater Cooler
246
- //operation mode - 0, HEAT, 2, COOL, 4, 5, 6, FAN, AUTO
247
- //ventilation mode - LOSSNAY, BYPASS, AUTO
248
- //actual ventilation mode - LOSSNAY, BYPASS
249
- currentOperationMode = !power ? 0 : [2, 3, [2, 3][actualVentilationMode]][ventilationMode]; //INACTIVE, IDLE, HEATING, COOLING
250
- targetOperationMode = [1, 2, 0][ventilationMode]; //AUTO, HEAT, COOL
251
- operationModeSetPropsMinValue = hasAutoVentilationMode ? 0 : 1;
252
- operationModeSetPropsMaxValue = hasAutoVentilationMode ? 2 : 2;
253
- operationModeSetPropsValidValues = hasAutoVentilationMode ? (hasBypassVentilationMode ? [0, 1, 2] : [0, 2]) : (hasBypassVentilationMode ? [1, 2] : [2]);
249
+ switch (power) {
250
+ case true:
251
+ switch (ventilationMode) {
252
+ case 0: //LOSSNAY
253
+ this.currentOperationMode = 2; //HEATING
254
+ this.targetOperationMode = 1; //HEAT
255
+ break;
256
+ case 1: //BYPASS
257
+ this.currentOperationMode = 3; //COOLING
258
+ this.targetOperationMode = 2; //COOL
259
+ break;
260
+ case 2: //AUTO
261
+ switch (actualVentilationMode) {
262
+ case 0: //LOSSNAY
263
+ this.currentOperationMode = 2; //HEATING
264
+ break;
265
+ case 1: //BYPASS
266
+ this.currentOperationMode = 3; //COOLING
267
+ break;
268
+ default:
269
+ this.emit('warn', `Unknown actual ventilation mode: ${actualVentilationMode}`);
270
+ break;
271
+ };
272
+ this.targetOperationMode = 0; //AUTO
273
+ break;
274
+ default:
275
+ this.emit('warn', `Unknown ventilation mode: ${ventilationMode}`);
276
+ break;
277
+ };
278
+ break;
279
+ case false:
280
+ this.currentOperationMode = 0; //OFF
281
+ break;
282
+ };
283
+
284
+ this.operationModeSetPropsMinValue = hasAutoVentilationMode ? 0 : 1;
285
+ this.operationModeSetPropsMaxValue = hasAutoVentilationMode ? 2 : 2;
286
+ this.operationModeSetPropsValidValues = hasAutoVentilationMode ? (hasBypassVentilationMode ? [0, 1, 2] : [0, 2]) : (hasBypassVentilationMode ? [1, 2] : [2]);
254
287
 
255
288
  //fan speed mode
256
289
  switch (numberOfFanSpeeds) {
257
290
  case 2: //Fan speed mode 2
258
- fanSpeed = hasAutomaticFanSpeed ? [3, 1, 2][setFanSpeed] : [0, 1, 2][setFanSpeed];
259
- fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 3 : 2;
291
+ this.fanSpeed = hasAutomaticFanSpeed ? [3, 1, 2][setFanSpeed] : [0, 1, 2][setFanSpeed];
292
+ this.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 3 : 2;
260
293
  break;
261
294
  case 3: //Fan speed mode 3
262
- fanSpeed = hasAutomaticFanSpeed ? [4, 1, 2, 3][setFanSpeed] : [0, 1, 2, 3][setFanSpeed];
263
- fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 4 : 3;
295
+ this.this.fanSpeed = hasAutomaticFanSpeed ? [4, 1, 2, 3][setFanSpeed] : [0, 1, 2, 3][setFanSpeed];
296
+ this.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 4 : 3;
264
297
  break;
265
298
  case 4: //Fan speed mode 4
266
- fanSpeed = hasAutomaticFanSpeed ? [5, 1, 2, 3, 4][setFanSpeed] : [0, 1, 2, 3, 4][setFanSpeed];
267
- fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 5 : 4;
299
+ this.fanSpeed = hasAutomaticFanSpeed ? [5, 1, 2, 3, 4][setFanSpeed] : [0, 1, 2, 3, 4][setFanSpeed];
300
+ this.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 5 : 4;
268
301
  break;
269
302
  };
270
303
 
271
- //lock physical controls
272
- lockPhysicalControls = 0;
273
-
274
304
  //update characteristics
275
305
  if (this.melCloudService) {
276
306
  this.melCloudService
277
307
  .updateCharacteristic(Characteristic.Active, power)
278
- .updateCharacteristic(Characteristic.CurrentHeaterCoolerState, currentOperationMode)
279
- .updateCharacteristic(Characteristic.TargetHeaterCoolerState, targetOperationMode)
308
+ .updateCharacteristic(Characteristic.CurrentHeaterCoolerState, this.currentOperationMode)
309
+ .updateCharacteristic(Characteristic.TargetHeaterCoolerState, this.targetOperationMode)
280
310
  .updateCharacteristic(Characteristic.CurrentTemperature, roomTemperature)
281
- .updateCharacteristic(Characteristic.RotationSpeed, fanSpeed)
282
- .updateCharacteristic(Characteristic.LockPhysicalControls, lockPhysicalControls)
283
- .updateCharacteristic(Characteristic.TemperatureDisplayUnits, useFahrenheit);
311
+ .updateCharacteristic(Characteristic.RotationSpeed, this.fanSpeed)
312
+ .updateCharacteristic(Characteristic.LockPhysicalControls, this.lockPhysicalControl)
313
+ .updateCharacteristic(Characteristic.TemperatureDisplayUnits, this.useFahrenheit);
284
314
  const updateHOM = hasHeatOperationMode ? this.melCloudService.updateCharacteristic(Characteristic.HeatingThresholdTemperature, targetTemperature) : false;
285
315
  const updateCOM = hasCoolOperationMode ? this.melCloudService.updateCharacteristic(Characteristic.CoolingThresholdTemperature, targetTemperature) : false;
286
316
  };
287
317
  break;
288
318
  case 1: //Thermostat
289
319
  //operation mode - 0, HEAT, 2, COOL, 4, 5, 6, FAN, AUTO
290
- //ventilation mode - LOSSNAY, BYPASS, AUTO
291
- //actual ventilation mode - LOSSNAY, BYPASS
292
- currentOperationMode = !power ? 0 : [1, 2, [1, 2][actualVentilationMode]][ventilationMode]; //OFF, HEAT, COOL
293
- targetOperationMode = !power ? 0 : [1, 2, 3][ventilationMode]; //OFF, HEAT, COOL, AUTO
294
- operationModeSetPropsMinValue = hasAutoVentilationMode ? 0 : 0;
295
- operationModeSetPropsMaxValue = hasAutoVentilationMode ? 3 : 2;
296
- operationModeSetPropsValidValues = hasAutoVentilationMode ? (hasBypassVentilationMode ? [0, 1, 2, 3] : [0, 2, 3]) : (hasBypassVentilationMode ? [0, 1, 2] : [0, 2]);
320
+ switch (power) {
321
+ case true:
322
+ switch (ventilationMode) {
323
+ case 0: //LOSSNAY
324
+ this.currentOperationMode = 1; //HEATING
325
+ this.targetOperationMode = 1; //HEAT
326
+ break;
327
+ case 1: //BYPASS
328
+ this.currentOperationMode = 2; //COOLING
329
+ this.targetOperationMode = 2; //COOL
330
+ break;
331
+ case 2: //AUTO
332
+ switch (actualVentilationMode) {
333
+ case 0: //LOSSNAY
334
+ this.currentOperationMode = 1; //HEATING
335
+ break;
336
+ case 1: //BYPASS
337
+ this.currentOperationMode = 2; //COOLING
338
+ break;
339
+ default:
340
+ this.emit('warn', `Unknown actual ventilation mode: ${actualVentilationMode}`);
341
+ break;
342
+ };
343
+ this.targetOperationMode = 3; //AUTO
344
+ break;
345
+ default:
346
+ this.emit('warn', `Unknown ventilation mode: ${ventilationMode}`);
347
+ break;
348
+ };
349
+ break;
350
+ case false:
351
+ this.currentOperationMode = 0; //OFF
352
+ this.targetOperationMode = 0; //OFF
353
+ break;
354
+ };
355
+ this.operationModeSetPropsMinValue = hasAutoVentilationMode ? 0 : 0;
356
+ this.operationModeSetPropsMaxValue = hasAutoVentilationMode ? 3 : 2;
357
+ this.operationModeSetPropsValidValues = hasAutoVentilationMode ? (hasBypassVentilationMode ? [0, 1, 2, 3] : [0, 2, 3]) : (hasBypassVentilationMode ? [0, 1, 2] : [0, 2]);
297
358
 
298
359
  //update characteristics
299
360
  if (this.melCloudService) {
300
361
  this.melCloudService
301
- .updateCharacteristic(Characteristic.CurrentHeatingCoolingState, currentOperationMode)
302
- .updateCharacteristic(Characteristic.TargetHeatingCoolingState, targetOperationMode)
362
+ .updateCharacteristic(Characteristic.CurrentHeatingCoolingState, this.currentOperationMode)
363
+ .updateCharacteristic(Characteristic.TargetHeatingCoolingState, this.targetOperationMode)
303
364
  .updateCharacteristic(Characteristic.CurrentTemperature, roomTemperature)
304
365
  .updateCharacteristic(Characteristic.TargetTemperature, targetTemperature)
305
- .updateCharacteristic(Characteristic.TemperatureDisplayUnits, useFahrenheit);
366
+ .updateCharacteristic(Characteristic.TemperatureDisplayUnits, this.useFahrenheit);
306
367
  };
307
368
  break;
308
369
  };
309
370
 
310
371
  this.power = power;
311
372
  this.offline = offline;
312
- this.currentOperationMode = currentOperationMode;
313
- this.targetOperationMode = targetOperationMode;
314
373
  this.roomTemperature = roomTemperature;
315
374
  this.supplyTemperature = supplyTemperature;
316
375
  this.outdoorTemperature = outdoorTemperature;
317
376
  this.setTemperature = targetTemperature;
318
- this.fanSpeed = fanSpeed;
319
377
  this.setFanSpeed = setFanSpeed;
320
- this.lockPhysicalControls = lockPhysicalControls;
321
378
 
322
379
  //update temperature sensors
323
380
  if (this.roomTemperatureSensorService) {
@@ -398,7 +455,7 @@ class DeviceErv extends EventEmitter {
398
455
  button.state = power ? (setFanSpeed === 4) : false;
399
456
  break;
400
457
  case 15: //PHYSICAL LOCK CONTROLS
401
- button.state = (lockPhysicalControls === 1);
458
+ button.state = (this.lockPhysicalControl === 1);
402
459
  break;
403
460
  case 16: //ROOM TEMP HIDE
404
461
  button.state = (hideRoomTemperature === true);
@@ -467,12 +524,6 @@ class DeviceErv extends EventEmitter {
467
524
  //start prepare accessory
468
525
  if (this.startPrepareAccessory) {
469
526
  try {
470
- this.operationModeSetPropsMinValue = operationModeSetPropsMinValue;
471
- this.operationModeSetPropsMaxValue = operationModeSetPropsMaxValue;
472
- this.operationModeSetPropsValidValues = operationModeSetPropsValidValues;
473
- this.fanSpeedSetPropsMaxValue = fanSpeedSetPropsMaxValue;
474
-
475
- await new Promise(resolve => setTimeout(resolve, 150));
476
527
  const accessory = await this.prepareAccessory(accountInfo, deviceState, deviceId, deviceTypeText, deviceName, accountName);
477
528
  this.emit('publishAccessory', accessory);
478
529
  this.startPrepareAccessory = false;
@@ -756,7 +807,7 @@ class DeviceErv extends EventEmitter {
756
807
  };
757
808
  //this.melCloudService.getCharacteristic(Characteristic.LockPhysicalControls)
758
809
  // .onGet(async () => {
759
- // const value = this.lockPhysicalControls;
810
+ // const value = this.lockPhysicalControl;
760
811
  // const info = this.disableLogInfo ? false : this.emit('message', `Lock physical controls: ${value ? 'LOCKED' : 'UNLOCKED'}`);
761
812
  // return value;
762
813
  // })
package/src/melcloud.js CHANGED
@@ -35,7 +35,7 @@ class MelCloud extends EventEmitter {
35
35
  try {
36
36
  await this.chackDevicesList();
37
37
  } catch (error) {
38
- this.emit('error', `Scheck devices list: ${error}.`);
38
+ this.emit('error', `Check devices list: ${error}.`);
39
39
  };
40
40
  }).on('state', (state) => { });
41
41
 
@@ -52,7 +52,7 @@ class MelCloud extends EventEmitter {
52
52
  const axiosInstanceLogin = axios.create({
53
53
  method: 'POST',
54
54
  baseURL: CONSTANTS.ApiUrls.BaseURL,
55
- timeout: 25000,
55
+ timeout: 5000,
56
56
  withCredentials: true,
57
57
  maxContentLength: 100000000,
58
58
  maxBodyLength: 1000000000,
@@ -90,7 +90,7 @@ class MelCloud extends EventEmitter {
90
90
  this.axiosInstanceGet = axios.create({
91
91
  method: 'GET',
92
92
  baseURL: CONSTANTS.ApiUrls.BaseURL,
93
- timeout: 15000,
93
+ timeout: 5000,
94
94
  headers: {
95
95
  'X-MitsContextKey': contextKey
96
96
  },
@@ -107,7 +107,7 @@ class MelCloud extends EventEmitter {
107
107
  this.axiosInstancePost = axios.create({
108
108
  method: 'POST',
109
109
  baseURL: CONSTANTS.ApiUrls.BaseURL,
110
- timeout: 15000,
110
+ timeout: 5000,
111
111
  headers: {
112
112
  'X-MitsContextKey': contextKey,
113
113
  'content-type': 'application/json'
@@ -202,10 +202,10 @@ class MelCloud extends EventEmitter {
202
202
  async saveData(path, data) {
203
203
  try {
204
204
  await fsPromises.writeFile(path, JSON.stringify(data, null, 2));
205
- const debug3 = this.enableDebugMode ? this.emit('debug', `Data saved to path: ${path}.`) : false;
205
+ const debug3 = this.enableDebugMode ? this.emit('debug', `Data saved to: ${path}.`) : false;
206
206
  return true;
207
207
  } catch (error) {
208
- throw new Error(`Save data to path: ${path}, error: ${error.message ?? error}`);
208
+ throw new Error(`Save data to: ${path}, error: ${error.message ?? error}`);
209
209
  }
210
210
  }
211
211
 
@@ -14,7 +14,7 @@ class MelCloudAta extends EventEmitter {
14
14
  const accountInfoFile = config.accountInfoFile;
15
15
  const deviceInfoFile = config.deviceInfoFile;
16
16
  const debugLog = config.debugLog;
17
- const refreshInterval= config.refreshInterval;
17
+ const refreshInterval = config.refreshInterval;
18
18
 
19
19
  //set default values
20
20
  this.deviceData = {};
@@ -127,13 +127,13 @@ class MelCloudAta extends EventEmitter {
127
127
  const legacyDevice = device.LegacyDevice;
128
128
  const unitSupportsStandbyMode = device.UnitSupportsStandbyMode;
129
129
  const isSplitSystem = device.IsSplitSystem;
130
- const hasHalfDegreeIncrements = device.HasHalfDegreeIncrements ?? false;
131
- const hasOutdoorTemperature = device.HasOutdoorTemperature ?? false
130
+ const hasHalfDegreeIncrements = device.HasHalfDegreeIncrements;
131
+ const hasOutdoorTemperature = device.HasOutdoorTemperature;
132
132
  const modelIsAirCurtain = device.ModelIsAirCurtain;
133
- const modelSupportsFanSpeed = device.ModelSupportsFanSpeed ?? false;
134
- const modelSupportsAuto = device.ModelSupportsAuto ?? false;
135
- const modelSupportsHeat = device.ModelSupportsHeat ?? false;
136
- const modelSupportsDry = device.ModelSupportsDry ?? false;
133
+ const modelSupportsFanSpeed = device.ModelSupportsFanSpeed;
134
+ const modelSupportsAuto = device.ModelSupportsAuto;
135
+ const modelSupportsHeat = device.ModelSupportsHeat;
136
+ const modelSupportsDry = device.ModelSupportsDry;
137
137
  const modelSupportsVaneVertical = device.ModelSupportsVaneVertical;
138
138
  const modelSupportsVaneHorizontal = device.ModelSupportsVaneHorizontal;
139
139
  const modelSupportsWideVane = device.ModelSupportsWideVane;