homebridge-melcloud-control 2.3.0-beta.9 → 2.3.1-beta.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.
package/src/deviceata.js CHANGED
@@ -22,6 +22,7 @@ class DeviceAta extends EventEmitter {
22
22
  this.temperatureSensorOutdoor = account.ataTemperatureSensorOutdoor || false;
23
23
  this.presetsEnabled = account.ataPresets || false;
24
24
  this.heatDryFanMode = account.ataHeatDryFanMode || 1; //NONE, HEAT, DRY, FAN
25
+ this.coolDryFanMode = account.ataCoolDryFanMode || 1; //NONE, COOL, DRY, FAN
25
26
  this.autoDryFanMode = account.ataAutoDryFanMode || 1; //NONE, AUTO, DRY, FAN
26
27
  this.buttons = account.ataButtons || [];
27
28
  this.disableLogInfo = account.disableLogInfo || false;
@@ -30,17 +31,12 @@ class DeviceAta extends EventEmitter {
30
31
 
31
32
  //external integrations
32
33
  const restFul = account.restFul ?? {};
33
- const restFulEnabled = restFul.enable || false;
34
34
  this.restFulConnected = false;
35
-
36
- //mqtt
37
35
  const mqtt = account.mqtt ?? {};
38
- const mqttEnabled = mqtt.enable || false;
39
36
  this.mqttConnected = false;
40
37
 
41
- //variables
38
+ //function
42
39
  this.melCloud = melCloud; //function
43
- this.startPrepareAccessory = true;
44
40
 
45
41
  //buttons configured
46
42
  this.buttonsConfigured = [];
@@ -63,6 +59,10 @@ class DeviceAta extends EventEmitter {
63
59
  }
64
60
  this.buttonsConfiguredCount = this.buttonsConfigured.length || 0;
65
61
 
62
+ //accessory
63
+ this.startPrepareAccessory = true;
64
+ this.accessory = {};
65
+
66
66
  //melcloud device
67
67
  this.melCloudAta = new MelCloudAta({
68
68
  contextKey: contextKey,
@@ -74,6 +74,7 @@ class DeviceAta extends EventEmitter {
74
74
 
75
75
  this.melCloudAta.on('externalIntegrations', (deviceData, deviceState) => {
76
76
  //RESTFul server
77
+ const restFulEnabled = restFul.enable || false;
77
78
  if (restFulEnabled) {
78
79
  if (!this.restFulConnected) {
79
80
  this.restFul = new RestFul({
@@ -104,6 +105,7 @@ class DeviceAta extends EventEmitter {
104
105
  }
105
106
 
106
107
  //MQTT client
108
+ const mqttEnabled = mqtt.enable || false;
107
109
  if (mqttEnabled) {
108
110
  if (!this.mqttConnected) {
109
111
  this.mqtt = new Mqtt({
@@ -170,22 +172,13 @@ class DeviceAta extends EventEmitter {
170
172
  const modelSupportsFanSpeed = deviceData.Device.ModelSupportsFanSpeed ?? false;
171
173
  const modelSupportsHeat1 = deviceData.Device.ModelSupportsHeat ?? false;
172
174
  const modelSupportsHeat = this.heatDryFanMode >= 1 && modelSupportsHeat1;
175
+ const modelSupportsCool = this.coolDryFanMode >= 1;
173
176
  const modelSupportsAuto1 = deviceData.Device.ModelSupportsAuto ?? false;
174
177
  const modelSupportsAuto = this.autoDryFanMode >= 1 && modelSupportsAuto1;
175
178
  const modelSupportsDry = deviceData.Device.ModelSupportsDry ?? false;
176
179
  const temperatureIncrement = deviceData.Device.TemperatureIncrement ?? 1;
177
180
  const outdoorTemperature = deviceData.Device.OutdoorTemperature;
178
-
179
- this.hasAutomaticFanSpeed = hasAutomaticFanSpeed;
180
- this.airDirectionFunction = airDirectionFunction;
181
- this.hasOutdoorTemperature = hasOutdoorTemperature;
182
- this.swingFunction = swingFunction;
183
- this.numberOfFanSpeeds = numberOfFanSpeeds;
184
- this.modelSupportsFanSpeed = modelSupportsFanSpeed;
185
- this.modelSupportsDry = modelSupportsDry;
186
- this.temperatureIncrement = temperatureIncrement;
187
- this.temperatureUnit = CONSTANTS.TemperatureDisplayUnits[useFahrenheit];
188
- this.useFahrenheit = useFahrenheit;
181
+ const temperatureUnit = CONSTANTS.TemperatureDisplayUnits[useFahrenheit];
189
182
 
190
183
  //device state
191
184
  const roomTemperature = deviceState.RoomTemperature;
@@ -205,111 +198,206 @@ class DeviceAta extends EventEmitter {
205
198
 
206
199
  //presets
207
200
  const presets = deviceData.Presets ?? [];
208
- this.presets = presets;
209
201
  this.presetsCount = this.presetsEnabled ? presets.length : 0;
210
202
 
211
- //operating mode
212
- let currentOperationMode = 0;
213
- let targetOperationMode = 0;
214
- let fanSpeed = 0;
215
- let swingMode = 0;
216
- let lockPhysicalControls = 0;
217
-
218
- let operationModeSetPropsMinValue = 0;
219
- let operationModeSetPropsMaxValue = 3;
220
- let operationModeSetPropsValidValues = [0];
221
- let fanSpeedSetPropsMaxValue = 2;
203
+ //accessory
204
+ this.accessory.power = power;
205
+ this.accessory.offline = offline;
206
+ this.accessory.roomTemperature = roomTemperature;
207
+ this.accessory.outdoorTemperature = outdoorTemperature;
208
+ this.accessory.setTemperature = setTemperature;
209
+ this.accessory.fanSpeed = 0;
210
+ this.accessory.setFanSpeed = setFanSpeed;
211
+ this.accessory.currentOperationMode = 0;
212
+ this.accessory.targetOperationMode = 0;
213
+ this.accessory.vaneHorizontal = vaneHorizontal;
214
+ this.accessory.vaneVertical = vaneVertical;
215
+ this.accessory.temperatureIncrement = temperatureIncrement;
216
+ this.accessory.useFahrenheit = useFahrenheit;
217
+ this.accessory.hasAutomaticFanSpeed = hasAutomaticFanSpeed;
218
+ this.accessory.airDirectionFunction = airDirectionFunction;
219
+ this.accessory.hasOutdoorTemperature = hasOutdoorTemperature;
220
+ this.accessory.swingFunction = swingFunction;
221
+ this.accessory.numberOfFanSpeeds = numberOfFanSpeeds;
222
+ this.accessory.modelSupportsFanSpeed = modelSupportsFanSpeed;
223
+ this.accessory.modelSupportsDry = modelSupportsDry;
224
+ this.accessory.presets = presets;
222
225
 
226
+ //operating mode
223
227
  switch (displayMode) {
224
228
  case 0: //Heater Cooler
225
229
  //operating mode 0, HEAT, DRY, COOL, 4, 5, 6, FAN, AUTO, ISEE HEAT, ISEE DRY, ISEE COOL
226
- currentOperationMode = !power ? 0 : inStandbyMode ? 1 : [0, 2, 3, 3, 1, 1, 1, 1, (setTemperature < roomTemperature) ? 3 : 2, 2, 1, 3][operationMode]; //INACTIVE, IDLE, HEATING, COOLING
227
- targetOperationMode = [operationMode, 1, [1, 1, 1, 1][this.heatDryFanMode], 2, 2, 2, 2, [0, 0, 0, 0][this.autoDryFanMode], 0, 1, 1, 2][operationMode]; //AUTO, HEAT, COOL
228
- operationModeSetPropsMinValue = modelSupportsAuto && modelSupportsHeat ? 0 : !modelSupportsAuto && modelSupportsHeat ? 1 : modelSupportsAuto && !modelSupportsHeat ? 0 : 2;
229
- operationModeSetPropsMaxValue = 2
230
- operationModeSetPropsValidValues = modelSupportsAuto && modelSupportsHeat ? [0, 1, 2] : !modelSupportsAuto && modelSupportsHeat ? [1, 2] : modelSupportsAuto && !modelSupportsHeat ? [0, 2] : [2];
230
+ switch (power) {
231
+ case true:
232
+ switch (!inStandbyMode) {
233
+ case true:
234
+ switch (operationMode) {
235
+ case 1: //HEAT
236
+ this.accessory.currentOperationMode = 2; //INACTIVE, IDLE, HEATING, COOLING
237
+ this.accessory.targetOperationMode = 1; //AUTO, HEAT, COOL
238
+ break;
239
+ case 2: //DRY
240
+ this.accessory.currentOperationMode = 3;
241
+ this.accessory.targetOperationMode = 2;
242
+ break;
243
+ case 3: //COOL
244
+ this.accessory.currentOperationMode = 3;
245
+ this.accessory.targetOperationMode = 2;
246
+ break;
247
+ case 7: //FAN
248
+ this.accessory.currentOperationMode = 3;
249
+ this.accessory.targetOperationMode = 2;
250
+ break;
251
+ case 8: //AUTO
252
+ this.accessory.currentOperationMode = setTemperature < roomTemperature ? 3 : 2;
253
+ this.accessory.targetOperationMode = 0;
254
+ break;
255
+ case 9: //ISEE HEAT
256
+ this.accessory.currentOperationMode = 2
257
+ this.accessory.targetOperationMode = 1;
258
+ break;
259
+ case 10: //ISEE DRY
260
+ this.accessory.currentOperationMode = 3;
261
+ this.accessory.targetOperationMode = 2;
262
+ break;
263
+ case 11: //ISEE COOL;
264
+ this.accessory.currentOperationMode = 3;
265
+ this.accessory.targetOperationMode = 2;
266
+ break;
267
+ default:
268
+ this.emit('warn', `Unknown operating mode: ${operationMode}`);
269
+ break;
270
+ };
271
+ break;
272
+ case false:
273
+ this.accessory.currentOperationMode = 1;
274
+ break;
275
+ };
276
+ break;
277
+ case false:
278
+ this.accessory.currentOperationMode = 0;
279
+ break;
280
+ };
281
+ this.accessory.operationModeSetPropsMinValue = modelSupportsAuto && modelSupportsHeat ? 0 : !modelSupportsAuto && modelSupportsHeat ? 1 : modelSupportsAuto && !modelSupportsHeat ? 0 : 2;
282
+ this.accessory.operationModeSetPropsMaxValue = 2
283
+ this.accessory.operationModeSetPropsValidValues = modelSupportsAuto && modelSupportsHeat ? [0, 1, 2] : !modelSupportsAuto && modelSupportsHeat ? [1, 2] : modelSupportsAuto && !modelSupportsHeat ? [0, 2] : [2];
231
284
 
232
285
  //fan speed mode
233
286
  if (modelSupportsFanSpeed) {
234
287
  switch (numberOfFanSpeeds) {
235
288
  case 2: //Fan speed mode 2
236
- fanSpeed = hasAutomaticFanSpeed ? [3, 1, 2][setFanSpeed] : [0, 1, 2][setFanSpeed];
237
- fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 3 : 2;
289
+ this.accessory.fanSpeed = hasAutomaticFanSpeed ? [3, 1, 2][setFanSpeed] : [0, 1, 2][setFanSpeed];
290
+ this.accessory.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 3 : 2;
238
291
  break;
239
292
  case 3: //Fan speed mode 3
240
- fanSpeed = hasAutomaticFanSpeed ? [4, 1, 2, 3][setFanSpeed] : [0, 1, 2, 3][setFanSpeed];
241
- fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 4 : 3;
293
+ this.accessory.fanSpeed = hasAutomaticFanSpeed ? [4, 1, 2, 3][setFanSpeed] : [0, 1, 2, 3][setFanSpeed];
294
+ this.accessory.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 4 : 3;
242
295
  break;
243
296
  case 4: //Fan speed mode 4
244
- fanSpeed = hasAutomaticFanSpeed ? [5, 1, 2, 3, 4][setFanSpeed] : [0, 1, 2, 3, 4][setFanSpeed];
245
- fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 5 : 4;
297
+ this.accessory.fanSpeed = hasAutomaticFanSpeed ? [5, 1, 2, 3, 4][setFanSpeed] : [0, 1, 2, 3, 4][setFanSpeed];
298
+ this.accessory.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 5 : 4;
246
299
  break;
247
300
  case 5: //Fan speed mode 5
248
- fanSpeed = hasAutomaticFanSpeed ? [6, 1, 2, 3, 4, 5][setFanSpeed] : [0, 1, 2, 3, 4, 5][setFanSpeed];
249
- fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 6 : 5;
301
+ this.accessory.fanSpeed = hasAutomaticFanSpeed ? [6, 1, 2, 3, 4, 5][setFanSpeed] : [0, 1, 2, 3, 4, 5][setFanSpeed];
302
+ this.accessory.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 6 : 5;
250
303
  break;
251
304
  case 6: //Fan speed mode 6
252
- fanSpeed = hasAutomaticFanSpeed ? [7, 1, 2, 3, 4, 5, 6][setFanSpeed] : [0, 1, 2, 3, 4, 5, 6][setFanSpeed];
253
- fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 7 : 6;
305
+ this.accessory.fanSpeed = hasAutomaticFanSpeed ? [7, 1, 2, 3, 4, 5, 6][setFanSpeed] : [0, 1, 2, 3, 4, 5, 6][setFanSpeed];
306
+ this.accessory.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 7 : 6;
254
307
  break;
255
308
  };
256
309
  };
257
310
 
258
311
  //swing and vane mode
259
- swingMode = swingFunction && vaneHorizontal === 12 && vaneVertical === 7 ? 1 : 0;
312
+ this.accessory.swingMode = swingFunction && vaneHorizontal === 12 && vaneVertical === 7 ? 1 : 0;
260
313
 
261
314
  //lock physical controls
262
- lockPhysicalControls = prohibitSetTemperature && prohibitOperationMode && prohibitPower ? 1 : 0;
315
+ this.accessory.lockPhysicalControl = prohibitSetTemperature && prohibitOperationMode && prohibitPower ? 1 : 0;
263
316
 
264
317
  //update characteristics
265
318
  if (this.melCloudService) {
266
319
  this.melCloudService
267
320
  .updateCharacteristic(Characteristic.Active, power)
268
- .updateCharacteristic(Characteristic.CurrentHeaterCoolerState, currentOperationMode)
269
- .updateCharacteristic(Characteristic.TargetHeaterCoolerState, targetOperationMode)
321
+ .updateCharacteristic(Characteristic.CurrentHeaterCoolerState, this.accessory.currentOperationMode)
322
+ .updateCharacteristic(Characteristic.TargetHeaterCoolerState, this.accessory.targetOperationMode)
270
323
  .updateCharacteristic(Characteristic.CurrentTemperature, roomTemperature)
271
324
  .updateCharacteristic(Characteristic.HeatingThresholdTemperature, setTemperature)
272
325
  .updateCharacteristic(Characteristic.CoolingThresholdTemperature, setTemperature)
273
- .updateCharacteristic(Characteristic.LockPhysicalControls, lockPhysicalControls)
274
- .updateCharacteristic(Characteristic.TemperatureDisplayUnits, useFahrenheit);
275
- const updateRS = modelSupportsFanSpeed ? this.melCloudService.updateCharacteristic(Characteristic.RotationSpeed, fanSpeed) : false;
276
- const updateSM = swingFunction ? this.melCloudService.updateCharacteristic(Characteristic.SwingMode, swingMode) : false;
326
+ .updateCharacteristic(Characteristic.LockPhysicalControls, this.accessory.lockPhysicalControl)
327
+ .updateCharacteristic(Characteristic.TemperatureDisplayUnits, this.accessory.useFahrenheit);
328
+ const updateRS = modelSupportsFanSpeed ? this.melCloudService.updateCharacteristic(Characteristic.RotationSpeed, this.accessory.fanSpeed) : false;
329
+ const updateSM = swingFunction ? this.melCloudService.updateCharacteristic(Characteristic.SwingMode, this.accessory.swingMode) : false;
277
330
  };
278
331
  break;
279
332
  case 1: //Thermostat
280
- //operating mode 0, HEAT, DRY, COOL, 4, 5, 6, FAN, AUTO, ISEE HEAT, ISEE DRY, ISEE COOL
281
- currentOperationMode = !power || inStandbyMode ? 0 : [0, 1, 2, 2, 2, 2, 2, 2, (setTemperature < roomTemperature) ? 2 : 1, 1, 1, 2][operationMode]; //OFF, HEAT, COOL
282
- targetOperationMode = !power || inStandbyMode ? 0 : [0, 1, [1, 1, 1, 1][this.heatDryFanMode], 2, 2, 2, 2, [3, 3, 3, 3][this.autoDryFanMode], 3, 1, 1, 2][operationMode]; //OFF, HEAT, COOL, AUTO
283
- operationModeSetPropsMinValue = 0
284
- operationModeSetPropsMaxValue = modelSupportsAuto && modelSupportsHeat ? 3 : !modelSupportsAuto && modelSupportsHeat ? 2 : modelSupportsAuto && !modelSupportsHeat ? 3 : 2;
285
- operationModeSetPropsValidValues = modelSupportsAuto && modelSupportsHeat ? [0, 1, 2, 3] : !modelSupportsAuto && modelSupportsHeat ? [0, 1, 2] : modelSupportsAuto && !modelSupportsHeat ? [0, 2, 3] : [0, 2];
333
+ switch (power) {
334
+ case true:
335
+ switch (!inStandbyMode) {
336
+ case true:
337
+ switch (operationMode) {
338
+ case 1: //HEAT
339
+ this.accessory.currentOperationMode = 1; //OFF, HEAT, COOL
340
+ this.accessory.targetOperationMode = 1; //OFF, HEAT, COOL, AUTO
341
+ break;
342
+ case 2: //DRY
343
+ this.accessory.currentOperationMode = 2;
344
+ this.accessory.targetOperationMode = 2;
345
+ break;
346
+ case 3: //COOL
347
+ this.accessory.currentOperationMode = 2;
348
+ this.accessory.targetOperationMode = 2;
349
+ break;
350
+ case 7: //FAN
351
+ this.accessory.currentOperationMode = 2;
352
+ this.accessory.targetOperationMode = 2;
353
+ break;
354
+ case 8: //AUTO
355
+ this.accessory.currentOperationMode = setTemperature < roomTemperature ? 2 : 1;
356
+ this.accessory.targetOperationMode = 3;
357
+ break;
358
+ case 9: //ISEE HEAT
359
+ this.accessory.currentOperationMode = 1
360
+ this.accessory.targetOperationMode = 1;
361
+ break;
362
+ case 10: //ISEE DRY
363
+ this.accessory.currentOperationMode = 2;
364
+ this.accessory.targetOperationMode = 2;
365
+ break;
366
+ case 11: //ISEE COOL;
367
+ this.accessory.currentOperationMode = 2;
368
+ this.accessory.targetOperationMode = 2;
369
+ break;
370
+ default:
371
+ this.emit('warn', `Unknown operating mode: ${operationMode}`);
372
+ break;
373
+ };
374
+ break;
375
+ case false:
376
+ this.accessory.currentOperationMode = 0;
377
+ this.accessory.targetOperationMode = 0;
378
+ break;
379
+ };
380
+ case false:
381
+ this.accessory.currentOperationMode = 0;
382
+ this.accessory.targetOperationMode = 0;
383
+ break;
384
+ };
385
+ this.accessory.operationModeSetPropsMinValue = 0
386
+ this.accessory.operationModeSetPropsMaxValue = modelSupportsAuto && modelSupportsHeat ? 3 : !modelSupportsAuto && modelSupportsHeat ? 2 : modelSupportsAuto && !modelSupportsHeat ? 3 : 2;
387
+ this.accessory.operationModeSetPropsValidValues = modelSupportsAuto && modelSupportsHeat ? [0, 1, 2, 3] : !modelSupportsAuto && modelSupportsHeat ? [0, 1, 2] : modelSupportsAuto && !modelSupportsHeat ? [0, 2, 3] : [0, 2];
286
388
 
287
389
  //update characteristics
288
390
  if (this.melCloudService) {
289
391
  this.melCloudService
290
- .updateCharacteristic(Characteristic.CurrentHeatingCoolingState, currentOperationMode)
291
- .updateCharacteristic(Characteristic.TargetHeatingCoolingState, targetOperationMode)
392
+ .updateCharacteristic(Characteristic.CurrentHeatingCoolingState, this.accessory.currentOperationMode)
393
+ .updateCharacteristic(Characteristic.TargetHeatingCoolingState, this.accessory.targetOperationMode)
292
394
  .updateCharacteristic(Characteristic.CurrentTemperature, roomTemperature)
293
395
  .updateCharacteristic(Characteristic.TargetTemperature, setTemperature)
294
- .updateCharacteristic(Characteristic.TemperatureDisplayUnits, useFahrenheit);
396
+ .updateCharacteristic(Characteristic.TemperatureDisplayUnits, this.accessory.useFahrenheit);
295
397
  };
296
398
  break;
297
399
  };
298
400
 
299
- this.power = power;
300
- this.offline = offline;
301
- this.currentOperationMode = currentOperationMode;
302
- this.targetOperationMode = targetOperationMode;
303
- this.roomTemperature = roomTemperature;
304
- this.outdoorTemperature = outdoorTemperature;
305
- this.setTemperature = setTemperature;
306
- this.fanSpeed = fanSpeed;
307
- this.setFanSpeed = setFanSpeed;
308
- this.swingMode = swingMode;
309
- this.vaneHorizontal = vaneHorizontal;
310
- this.vaneVertical = vaneVertical;
311
- this.lockPhysicalControls = lockPhysicalControls;
312
-
313
401
  if (this.roomTemperatureSensorService) {
314
402
  this.roomTemperatureSensorService
315
403
  .updateCharacteristic(Characteristic.CurrentTemperature, roomTemperature)
@@ -420,7 +508,7 @@ class DeviceAta extends EventEmitter {
420
508
  button.state = power ? (setFanSpeed === 6) : false;
421
509
  break;
422
510
  case 37: //PHYSICAL LOCK CONTROLS ALL
423
- button.state = (lockPhysicalControls === 1);
511
+ button.state = (this.accessory.lockPhysicalControl === 1);
424
512
  break;
425
513
  case 38: //PHYSICAL LOCK CONTROLS POWER
426
514
  button.state = (prohibitPower === true);
@@ -471,26 +559,20 @@ class DeviceAta extends EventEmitter {
471
559
  const operationModeText = !power ? CONSTANTS.AirConditioner.System[0] : CONSTANTS.AirConditioner.DriveMode[operationMode];
472
560
  this.emit('message', `Power: ${power ? 'ON' : 'OFF'}`);
473
561
  this.emit('message', `Operation mode: ${operationModeText}`);
474
- this.emit('message', `Room temperature: ${roomTemperature}${this.temperatureUnit}`);
475
- this.emit('message', `Target temperature: ${setTemperature}${this.temperatureUnit}`);
476
- const info0 = hasOutdoorTemperature && this.outdoorTemperature !== null ? this.emit('message', `Outdoor temperature: ${roomTemperature}${this.temperatureUnit}`) : false;
477
- const info1 = displayMode === 0 ? this.emit('message', `Heating threshold temperature: ${setTemperature}${this.temperatureUnit}`) : false;
478
- const info2 = displayMode === 0 ? this.emit('message', `Cooling threshold temperature: ${setTemperature}${this.temperatureUnit}`) : false;
562
+ this.emit('message', `Room temperature: ${roomTemperature}${temperatureUnit}`);
563
+ this.emit('message', `Target temperature: ${setTemperature}${temperatureUnit}`);
564
+ const info0 = hasOutdoorTemperature && this.accessory.outdoorTemperature !== null ? this.emit('message', `Outdoor temperature: ${roomTemperature}${temperatureUnit}`) : false;
565
+ const info1 = displayMode === 0 ? this.emit('message', `Heating threshold temperature: ${setTemperature}${temperatureUnit}`) : false;
566
+ const info2 = displayMode === 0 ? this.emit('message', `Cooling threshold temperature: ${setTemperature}${temperatureUnit}`) : false;
479
567
  const info3 = modelSupportsFanSpeed ? this.emit('message', `Fan speed mode: ${CONSTANTS.AirConditioner.FanSpeed[setFanSpeed]}`) : false;
480
- const info4 = swingFunction ? this.emit('message', `Vane swing mode: ${CONSTANTS.AirConditioner.AirDirection[swingMode ? 6 : 0]}`) : false;
481
- this.emit('message', `Temperature display unit: ${this.temperatureUnit}`);
482
- this.emit('message', `Lock physical controls: ${lockPhysicalControls ? 'LOCKED' : 'UNLOCKED'}`);
568
+ const info4 = swingFunction ? this.emit('message', `Vane swing mode: ${CONSTANTS.AirConditioner.AirDirection[this.accessory.swingMode ? 6 : 0]}`) : false;
569
+ this.emit('message', `Temperature display unit: ${temperatureUnit}`);
570
+ this.emit('message', `Lock physical controls: ${this.accessory.lockPhysicalControl ? 'LOCKED' : 'UNLOCKED'}`);
483
571
  };
484
572
 
485
573
  //start prepare accessory
486
574
  if (this.startPrepareAccessory) {
487
575
  try {
488
- this.operationModeSetPropsMinValue = operationModeSetPropsMinValue;
489
- this.operationModeSetPropsMaxValue = operationModeSetPropsMaxValue;
490
- this.operationModeSetPropsValidValues = operationModeSetPropsValidValues;
491
- this.fanSpeedSetPropsMaxValue = fanSpeedSetPropsMaxValue;
492
-
493
- await new Promise(resolve => setTimeout(resolve, 150));
494
576
  const accessory = await this.prepareAccessory(accountInfo, deviceState, deviceId, deviceTypeText, deviceName, accountName);
495
577
  this.emit('publishAccessory', accessory);
496
578
  this.startPrepareAccessory = false;
@@ -616,27 +698,26 @@ class DeviceAta extends EventEmitter {
616
698
  const temperatureSensorOutdoor = this.temperatureSensorOutdoor;
617
699
  const buttonsConfigured = this.buttonsConfigured;
618
700
  const buttonsConfiguredCount = this.buttonsConfiguredCount;
619
- const presets = this.presets;
701
+ const presets = this.accessory.presets;
620
702
  const presetsCount = this.presetsCount;
621
- const hasAutomaticFanSpeed = this.hasAutomaticFanSpeed;
622
- const modelSupportsFanSpeed = this.modelSupportsFanSpeed;
623
- const modelSupportsDry = this.modelSupportsDry;
624
- const numberOfFanSpeeds = this.numberOfFanSpeeds;
625
- const swingFunction = this.swingFunction;
626
- const hasOutdoorTemperature = this.hasOutdoorTemperature;
627
- const heatDryFanMode = [deviceState.OperationMode, 8, modelSupportsDry ? 2 : deviceState.OperationMode, 7][this.heatDryFanMode]; //NONE, HEAT - 1, DRY - 2, FAN - 7
628
- const autoDryFanMode = [deviceState.OperationMode, 1, modelSupportsDry ? 2 : deviceState.OperationMode, 7][this.autoDryFanMode]; //NONE, AUTO - 8, DRY - 2, FAN - 7
703
+ const hasAutomaticFanSpeed = this.accessory.hasAutomaticFanSpeed;
704
+ const modelSupportsFanSpeed = this.accessory.modelSupportsFanSpeed;
705
+ const modelSupportsDry = this.accessory.modelSupportsDry;
706
+ const numberOfFanSpeeds = this.accessory.numberOfFanSpeeds;
707
+ const swingFunction = this.accessory.swingFunction;
708
+ const hasOutdoorTemperature = this.accessory.hasOutdoorTemperature;
709
+ const autoDryFanMode = [deviceState.OperationMode, 8, modelSupportsDry ? 2 : 8, 7][this.autoDryFanMode]; //NONE, AUTO - 8, DRY - 2, FAN - 7
710
+ const heatDryFanMode = [deviceState.OperationMode, 1, modelSupportsDry ? 2 : 1, 7][this.heatDryFanMode]; //NONE, HEAT - 1, DRY - 2, FAN - 7
711
+ const coolDryFanMode = [deviceState.OperationMode, 3, modelSupportsDry ? 2 : 3, 7][this.coolDryFanMode]; //NONE, COOL - 3, DRY - 2, FAN - 7
629
712
  const serviceName = `${deviceTypeText} ${accessoryName}`;
630
713
 
631
714
  switch (displayMode) {
632
715
  case 0: //Heater Cooler
633
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare heather/cooler service`) : false;
634
- this.melCloudService = accessory.addService(Service.HeaterCooler, serviceName, `HeaterCooler ${deviceId}`);
635
- this.melCloudService.removeCharacteristic(Characteristic.TargetHeaterCoolerState);
636
- this.melCloudService.addCharacteristic(Characteristic.CustomTargetHeaterCoolerState);
716
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare heater/cooler service`) : false;
717
+ this.melCloudService = new Service.HeaterCooler(serviceName, `HeaterCooler ${deviceId}`);
637
718
  this.melCloudService.getCharacteristic(Characteristic.Active)
638
719
  .onGet(async () => {
639
- const state = this.power;
720
+ const state = this.accessory.power;
640
721
  return state;
641
722
  })
642
723
  .onSet(async (state) => {
@@ -652,17 +733,17 @@ class DeviceAta extends EventEmitter {
652
733
  });
653
734
  this.melCloudService.getCharacteristic(Characteristic.CurrentHeaterCoolerState)
654
735
  .onGet(async () => {
655
- const value = this.currentOperationMode;
736
+ const value = this.accessory.currentOperationMode;
656
737
  return value;
657
738
  });
658
- this.melCloudService.getCharacteristic(Characteristic.CustomTargetHeaterCoolerState)
739
+ this.melCloudService.getCharacteristic(Characteristic.TargetHeaterCoolerState)
659
740
  .setProps({
660
- minValue: this.operationModeSetPropsMinValue,
661
- maxValue: this.operationModeSetPropsMaxValue,
662
- validValues: this.operationModeSetPropsValidValues
741
+ minValue: this.accessory.operationModeSetPropsMinValue,
742
+ maxValue: this.accessory.operationModeSetPropsMaxValue,
743
+ validValues: this.accessory.operationModeSetPropsValidValues
663
744
  })
664
745
  .onGet(async () => {
665
- const value = this.targetOperationMode; //1 = HEAT, 2 = DRY 3 = COOL, 7 = FAN, 8 = AUTO
746
+ const value = this.accessory.targetOperationMode; //1 = HEAT, 2 = DRY 3 = COOL, 7 = FAN, 8 = AUTO
666
747
  return value;
667
748
  })
668
749
  .onSet(async (value) => {
@@ -680,7 +761,7 @@ class DeviceAta extends EventEmitter {
680
761
  break;
681
762
  case 2: //COOL - COOL
682
763
  deviceState.Power = true;
683
- deviceState.OperationMode = 3;
764
+ deviceState.OperationMode = coolDryFanMode;
684
765
  deviceState.EffectiveFlags = CONSTANTS.AirConditioner.EffectiveFlags.Power + CONSTANTS.AirConditioner.EffectiveFlags.OperationMode;
685
766
  break;
686
767
  };
@@ -696,11 +777,11 @@ class DeviceAta extends EventEmitter {
696
777
  this.melCloudService.getCharacteristic(Characteristic.RotationSpeed)
697
778
  .setProps({
698
779
  minValue: 0,
699
- maxValue: this.fanSpeedSetPropsMaxValue,
780
+ maxValue: this.accessory.fanSpeedSetPropsMaxValue,
700
781
  minStep: 1
701
782
  })
702
783
  .onGet(async () => {
703
- const value = this.fanSpeed; //AUTO, 1, 2, 3, 4, 5, 6, OFF
784
+ const value = this.accessory.fanSpeed; //AUTO, 1, 2, 3, 4, 5, 6, OFF
704
785
  return value;
705
786
  })
706
787
  .onSet(async (value) => {
@@ -743,7 +824,7 @@ class DeviceAta extends EventEmitter {
743
824
  this.melCloudService.getCharacteristic(Characteristic.SwingMode)
744
825
  .onGet(async () => {
745
826
  //Vane Horizontal: Auto, 1, 2, 3, 4, 5, 12 = Swing //Vertical: Auto, 1, 2, 3, 4, 5, 7 = Swing
746
- const value = this.swingMode;
827
+ const value = this.accessory.swingMode;
747
828
  return value;
748
829
  })
749
830
  .onSet(async (value) => {
@@ -765,17 +846,17 @@ class DeviceAta extends EventEmitter {
765
846
  minStep: 0.5
766
847
  })
767
848
  .onGet(async () => {
768
- const value = this.roomTemperature;
849
+ const value = this.accessory.roomTemperature;
769
850
  return value;
770
851
  });
771
852
  this.melCloudService.getCharacteristic(Characteristic.HeatingThresholdTemperature)
772
853
  .setProps({
773
854
  minValue: 0,
774
855
  maxValue: 31,
775
- minStep: this.temperatureIncrement
856
+ minStep: this.accessory.temperatureIncrement
776
857
  })
777
858
  .onGet(async () => {
778
- const value = this.setTemperature;
859
+ const value = this.accessory.setTemperature;
779
860
  return value;
780
861
  })
781
862
  .onSet(async (value) => {
@@ -792,10 +873,10 @@ class DeviceAta extends EventEmitter {
792
873
  .setProps({
793
874
  minValue: 10,
794
875
  maxValue: 31,
795
- minStep: this.temperatureIncrement
876
+ minStep: this.accessory.temperatureIncrement
796
877
  })
797
878
  .onGet(async () => {
798
- const value = this.setTemperature;
879
+ const value = this.accessory.setTemperature;
799
880
  return value;
800
881
  })
801
882
  .onSet(async (value) => {
@@ -810,7 +891,7 @@ class DeviceAta extends EventEmitter {
810
891
  });
811
892
  this.melCloudService.getCharacteristic(Characteristic.LockPhysicalControls)
812
893
  .onGet(async () => {
813
- const value = this.lockPhysicalControls;
894
+ const value = this.accessory.lockPhysicalControl;
814
895
  return value;
815
896
  })
816
897
  .onSet(async (value) => {
@@ -828,36 +909,37 @@ class DeviceAta extends EventEmitter {
828
909
  });
829
910
  this.melCloudService.getCharacteristic(Characteristic.TemperatureDisplayUnits)
830
911
  .onGet(async () => {
831
- const value = this.useFahrenheit;
912
+ const value = this.accessory.useFahrenheit;
832
913
  return value;
833
914
  })
834
915
  .onSet(async (value) => {
835
916
  try {
836
- this.useFahrenheit = value ? true : false;
837
- accountInfo.UseFahrenheit = this.useFahrenheit;
917
+ this.accessory.useFahrenheit = value ? true : false;
918
+ accountInfo.UseFahrenheit = this.accessory.useFahrenheit;
838
919
  await this.melCloud.send(accountInfo);
839
920
  const info = this.disableLogInfo ? false : this.emit('message', `Set temperature display unit: ${CONSTANTS.TemperatureDisplayUnits[value]}`);
840
921
  } catch (error) {
841
922
  this.emit('warn', `Set temperature display unit error: ${error}`);
842
923
  };
843
924
  });
925
+ accessory.addService(this.melCloudService);
844
926
  break;
845
927
  case 1: //Thermostat
846
928
  const debug1 = this.enableDebugMode ? this.emit('debug', `Prepare thermostat service`) : false;
847
929
  this.melCloudService = accessory.addService(Service.Thermostat, serviceName, `Thermostat ${deviceId}`);
848
930
  this.melCloudService.getCharacteristic(Characteristic.CurrentHeatingCoolingState)
849
931
  .onGet(async () => {
850
- const value = this.currentOperationMode;;
932
+ const value = this.accessory.currentOperationMode;;
851
933
  return value;
852
934
  });
853
935
  this.melCloudService.getCharacteristic(Characteristic.TargetHeatingCoolingState)
854
936
  .setProps({
855
- minValue: this.operationModeSetPropsMinValue,
856
- maxValue: this.operationModeSetPropsMaxValue,
857
- validValues: this.operationModeSetPropsValidValues
937
+ minValue: this.accessory.operationModeSetPropsMinValue,
938
+ maxValue: this.accessory.operationModeSetPropsMaxValue,
939
+ validValues: this.accessory.operationModeSetPropsValidValues
858
940
  })
859
941
  .onGet(async () => {
860
- const value = this.targetOperationMode; //1 = HEAT, 2 = DRY 3 = COOL, 7 = FAN, 8 = AUTO
942
+ const value = this.accessory.targetOperationMode; //1 = HEAT, 2 = DRY 3 = COOL, 7 = FAN, 8 = AUTO
861
943
  return value;
862
944
  })
863
945
  .onSet(async (value) => {
@@ -874,7 +956,7 @@ class DeviceAta extends EventEmitter {
874
956
  break;
875
957
  case 2: //COOL - COOL
876
958
  deviceState.Power = true;
877
- deviceState.OperationMode = 3;
959
+ deviceState.OperationMode = coolDryFanMode;
878
960
  deviceState.EffectiveFlags = CONSTANTS.AirConditioner.EffectiveFlags.Power + CONSTANTS.AirConditioner.EffectiveFlags.OperationMode;
879
961
  break;
880
962
  case 3: //AUTO - AUTO
@@ -898,17 +980,17 @@ class DeviceAta extends EventEmitter {
898
980
  minStep: 0.5
899
981
  })
900
982
  .onGet(async () => {
901
- const value = this.roomTemperature;
983
+ const value = this.accessory.roomTemperature;
902
984
  return value;
903
985
  });
904
986
  this.melCloudService.getCharacteristic(Characteristic.TargetTemperature)
905
987
  .setProps({
906
988
  minValue: 0,
907
989
  maxValue: 31,
908
- minStep: this.temperatureIncrement
990
+ minStep: this.accessory.temperatureIncrement
909
991
  })
910
992
  .onGet(async () => {
911
- const value = this.setTemperature;
993
+ const value = this.accessory.setTemperature;
912
994
  return value;
913
995
  })
914
996
  .onSet(async (value) => {
@@ -923,13 +1005,13 @@ class DeviceAta extends EventEmitter {
923
1005
  });
924
1006
  this.melCloudService.getCharacteristic(Characteristic.TemperatureDisplayUnits)
925
1007
  .onGet(async () => {
926
- const value = this.useFahrenheit;
1008
+ const value = this.accessory.useFahrenheit;
927
1009
  return value;
928
1010
  })
929
1011
  .onSet(async (value) => {
930
1012
  try {
931
- this.useFahrenheit = value ? true : false;
932
- accountInfo.UseFahrenheit = this.useFahrenheit;
1013
+ this.accessory.useFahrenheit = value ? true : false;
1014
+ accountInfo.UseFahrenheit = this.accessory.useFahrenheit;
933
1015
  await this.melCloud.send(accountInfo);
934
1016
  const info = this.disableLogInfo ? false : this.emit('message', `Set temperature display unit: ${CONSTANTS.TemperatureDisplayUnits[value]}`);
935
1017
  } catch (error) {
@@ -940,7 +1022,7 @@ class DeviceAta extends EventEmitter {
940
1022
  };
941
1023
 
942
1024
  //temperature sensor services
943
- if (temperatureSensor && this.roomTemperature !== null) {
1025
+ if (temperatureSensor && this.accessory.roomTemperature !== null) {
944
1026
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare room temperature sensor service`) : false;
945
1027
  this.roomTemperatureSensorService = new Service.TemperatureSensor(`${serviceName} Room`, `Room Temperature Sensor ${deviceId}`);
946
1028
  this.roomTemperatureSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
@@ -952,13 +1034,13 @@ class DeviceAta extends EventEmitter {
952
1034
  minStep: 0.5
953
1035
  })
954
1036
  .onGet(async () => {
955
- const state = this.roomTemperature;
1037
+ const state = this.accessory.roomTemperature;
956
1038
  return state;
957
1039
  })
958
1040
  accessory.addService(this.roomTemperatureSensorService);
959
1041
  };
960
1042
 
961
- if (temperatureSensorOutdoor && hasOutdoorTemperature && this.outdoorTemperature !== null) {
1043
+ if (temperatureSensorOutdoor && hasOutdoorTemperature && this.accessory.outdoorTemperature !== null) {
962
1044
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare outdoor temperature sensor service`) : false;
963
1045
  this.outdoorTemperatureSensorService = new Service.TemperatureSensor(`${serviceName} Outdoor`, `Outdoor Temperature Sensor ${deviceId}`);
964
1046
  this.outdoorTemperatureSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
@@ -970,7 +1052,7 @@ class DeviceAta extends EventEmitter {
970
1052
  minStep: 0.5
971
1053
  })
972
1054
  .onGet(async () => {
973
- const state = this.outdoorTemperature;
1055
+ const state = this.accessory.outdoorTemperature;
974
1056
  return state;
975
1057
  })
976
1058
  accessory.addService(this.outdoorTemperatureSensorService);