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