homebridge-melcloud-control 3.1.11 → 3.1.17

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
@@ -36,6 +36,7 @@ class DeviceErv extends EventEmitter {
36
36
  this.refreshInterval = refreshInterval;
37
37
  this.useFahrenheit = useFahrenheit;
38
38
  this.startPrepareAccessory = true;
39
+ this.displayDeviceInfo = true;
39
40
 
40
41
  //external integrations
41
42
  this.restFul = account.restFul ?? {};
@@ -70,10 +71,10 @@ class DeviceErv extends EventEmitter {
70
71
  this.buttonsConfigured = [];
71
72
  for (const button of this.buttons) {
72
73
  const buttonName = button.name ?? false;
73
- const buttonMode = button.mode ?? false;
74
+ const buttonMode = button.mode ?? -1;
74
75
  const buttonDisplayType = button.displayType ?? 0;
75
76
  const buttonNamePrefix = button.namePrefix ?? false;
76
- if (buttonName && buttonMode && buttonDisplayType > 0) {
77
+ if (buttonName && buttonMode >= 0 && buttonDisplayType > 0) {
77
78
  const buttonServiceType = ['', Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][buttonDisplayType];
78
79
  const buttonCharacteristicType = ['', Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][buttonDisplayType];
79
80
  button.namePrefix = buttonNamePrefix;
@@ -92,12 +93,6 @@ class DeviceErv extends EventEmitter {
92
93
  this.accessory.currentOperationMode = 0;
93
94
  this.accessory.targetOperationMode = 0;
94
95
  this.accessory.fanSpeed = 0;
95
- this.accessory.lockPhysicalControl = 0;
96
-
97
- this.accessory.operationModeSetPropsMinValue = 0;
98
- this.accessory.operationModeSetPropsMaxValue = 3;
99
- this.accessory.operationModeSetPropsValidValues = [0];
100
- this.accessory.fanSpeedSetPropsMaxValue = 2;
101
96
  };
102
97
 
103
98
  async start() {
@@ -110,7 +105,7 @@ class DeviceErv extends EventEmitter {
110
105
  debugLog: this.enableDebugMode
111
106
  });
112
107
 
113
- this.melCloudErv.on('externalIntegrations', (deviceData, deviceState) => {
108
+ this.melCloudErv.on('externalIntegrations', (deviceData) => {
114
109
  try {
115
110
  //RESTFul server
116
111
  const restFulEnabled = this.restFul.enable || false;
@@ -127,7 +122,7 @@ class DeviceErv extends EventEmitter {
127
122
  })
128
123
  .on('set', async (key, value) => {
129
124
  try {
130
- await this.setOverExternalIntegration('RESTFul', deviceState, key, value);
125
+ await this.setOverExternalIntegration('RESTFul', deviceData, key, value);
131
126
  } catch (error) {
132
127
  this.emit('warn', `RESTFul set error: ${error}.`);
133
128
  };
@@ -140,7 +135,7 @@ class DeviceErv extends EventEmitter {
140
135
  });
141
136
  }
142
137
  const restFul0 = this.restFulConnected ? this.restFul1.update('info', deviceData) : false;
143
- const restFul1 = this.restFulConnected ? this.restFul1.update('state', deviceState) : false;
138
+ const restFul1 = this.restFulConnected ? this.restFul1.update('state', deviceData.Device) : false;
144
139
  }
145
140
 
146
141
  //MQTT client
@@ -166,7 +161,7 @@ class DeviceErv extends EventEmitter {
166
161
  })
167
162
  .on('set', async (key, value) => {
168
163
  try {
169
- await this.setOverExternalIntegration('MQTT', deviceState, key, value);
164
+ await this.setOverExternalIntegration('MQTT', deviceData, key, value);
170
165
  } catch (error) {
171
166
  this.emit('warn', `MQTT set error: ${error}.`);
172
167
  };
@@ -179,13 +174,17 @@ class DeviceErv extends EventEmitter {
179
174
  });
180
175
  }
181
176
  const mqtt0 = this.mqttConnected ? this.mqtt1.emit('publish', `Info`, deviceData) : false;
182
- const mqtt1 = this.mqttConnected ? this.mqtt1.emit('publish', `State`, deviceState) : false;
177
+ const mqtt1 = this.mqttConnected ? this.mqtt1.emit('publish', `State`, deviceData.Device) : false;
183
178
  }
184
179
  } catch (error) {
185
180
  this.emit('warn', `External integration start error: ${error.message || error}.`);
186
181
  };
187
182
  })
188
183
  .on('deviceInfo', (manufacturer, modelIndoor, modelOutdoor, serialNumber, firmwareAppVersion) => {
184
+ if (!this.displayDeviceInfo) {
185
+ return;
186
+ }
187
+
189
188
  if (!this.disableLogDeviceInfo) {
190
189
  this.emit('devInfo', `---- ${this.deviceTypeText}: ${this.deviceName} ----`);
191
190
  this.emit('devInfo', `Account: ${this.accountName}`);
@@ -202,11 +201,9 @@ class DeviceErv extends EventEmitter {
202
201
  this.model = modelIndoor ? modelIndoor : modelOutdoor ? modelOutdoor : `${deviceTypeText} ${this.deviceId}`;
203
202
  this.serialNumber = serialNumber;
204
203
  this.firmwareRevision = firmwareAppVersion;
205
-
206
- //device info
207
-
204
+ this.displayDeviceInfo = false;
208
205
  })
209
- .on('deviceState', async (deviceData, deviceState) => {
206
+ .on('deviceState', async (deviceData) => {
210
207
  //device info
211
208
  const displayMode = this.displayMode;
212
209
  const hasCoolOperationMode = deviceData.Device.HasCoolOperationMode ?? false;
@@ -235,19 +232,19 @@ class DeviceErv extends EventEmitter {
235
232
  const presetsOnServer = deviceData.Presets ?? [];
236
233
 
237
234
  //device state
238
- const roomTemperature = deviceState.RoomTemperature;
239
- const supplyTemperature = deviceState.SupplyTemperature;
240
- const outdoorTemperature = deviceState.OutdoorTemperature;
241
- const nightPurgeMode = deviceState.NightPurgeMode;
242
- const setTemperature = deviceState.SetTemperature;
243
- const setFanSpeed = deviceState.SetFanSpeed;
244
- const operationMode = deviceState.OperationMode;
245
- const ventilationMode = deviceState.VentilationMode;
246
- const hideRoomTemperature = deviceState.HideRoomTemperature;
247
- const hideSupplyTemperature = deviceState.HideSupplyTemperature;
248
- const hideOutdoorTemperature = deviceState.HideOutdoorTemperature;
249
- const power = deviceState.Power;
250
- const offline = deviceState.Offline;
235
+ const power = deviceData.Device.Power;
236
+ const offline = deviceData.Device.Offline;
237
+ const roomTemperature = deviceData.Device.RoomTemperature;
238
+ const supplyTemperature = deviceData.Device.SupplyTemperature;
239
+ const outdoorTemperature = deviceData.Device.OutdoorTemperature;
240
+ const nightPurgeMode = deviceData.Device.NightPurgeMode;
241
+ const setTemperature = deviceData.Device.SetTemperature;
242
+ const setFanSpeed = deviceData.Device.SetFanSpeed;
243
+ const operationMode = deviceData.Device.OperationMode;
244
+ const ventilationMode = deviceData.Device.VentilationMode;
245
+ const hideRoomTemperature = deviceData.Device.HideRoomTemperature;
246
+ const hideSupplyTemperature = deviceData.Device.HideSupplyTemperature;
247
+ const hideOutdoorTemperature = deviceData.Device.HideOutdoorTemperature;
251
248
  const temperatureUnit = CONSTANTS.TemperatureDisplayUnits[this.useFahrenheit];
252
249
 
253
250
  //set temperature
@@ -256,12 +253,13 @@ class DeviceErv extends EventEmitter {
256
253
  //accessory
257
254
  this.accessory.presetsOnServer = presetsOnServer;
258
255
  this.accessory.power = power ? 1 : 0;
259
- this.accessory.offline = offline;
256
+ this.accessory.offline = offline ?? false;
260
257
  this.accessory.roomTemperature = roomTemperature;
261
258
  this.accessory.outdoorTemperature = outdoorTemperature;
262
259
  this.accessory.supplyTemperature = supplyTemperature;
263
260
  this.accessory.setTemperature = targetTemperature;
264
261
  this.accessory.setFanSpeed = setFanSpeed;
262
+ this.accessory.lockPhysicalControl = 0;
265
263
  this.accessory.temperatureIncrement = temperatureIncrement;
266
264
  this.accessory.useFahrenheit = this.useFahrenheit;
267
265
  this.accessory.temperatureUnit = temperatureUnit;
@@ -330,6 +328,7 @@ class DeviceErv extends EventEmitter {
330
328
  this.accessory.operationModeSetPropsValidValues = hasAutoVentilationMode ? (hasBypassVentilationMode ? [0, 1, 2] : [0, 2]) : (hasBypassVentilationMode ? [1, 2] : [2]);
331
329
 
332
330
  //fan speed mode
331
+ this.accessory.fanSpeedSetPropsMaxValue = 2;
333
332
  switch (numberOfFanSpeeds) {
334
333
  case 2: //Fan speed mode 2
335
334
  this.accessory.fanSpeed = hasAutomaticFanSpeed ? [3, 1, 2][setFanSpeed] : [0, 1, 2][setFanSpeed];
@@ -410,6 +409,9 @@ class DeviceErv extends EventEmitter {
410
409
  .updateCharacteristic(Characteristic.TemperatureDisplayUnits, this.accessory.useFahrenheit);
411
410
  };
412
411
  break;
412
+ default:
413
+ this.emit('warn', `Unknown display mode: ${displayMode}`);
414
+ return;
413
415
  };
414
416
 
415
417
  //update temperature sensors
@@ -458,8 +460,7 @@ class DeviceErv extends EventEmitter {
458
460
  if (this.presetsConfigured.length > 0) {
459
461
  for (let i = 0; i < this.presetsConfigured.length; i++) {
460
462
  const preset = this.presetsConfigured[i];
461
- const index = presetsOnServer.findIndex(p => p.ID === preset.Id);
462
- const presetData = presetsOnServer[index];
463
+ const presetData = presetsOnServer.find(p => p.ID === preset.Id);
463
464
 
464
465
  preset.state = presetData ? (presetData.Power === power
465
466
  && presetData.SetTemperature === targetTemperature
@@ -565,7 +566,7 @@ class DeviceErv extends EventEmitter {
565
566
  }
566
567
 
567
568
  try {
568
- const accessory = await this.prepareAccessory(this.accountInfo, deviceState, this.deviceId, this.deviceTypeText, this.deviceName, this.accountName);
569
+ const accessory = await this.prepareAccessory(this.accountInfo, deviceData, this.deviceId, this.deviceTypeText, this.deviceName, this.accountName);
569
570
  this.emit('publishAccessory', accessory);
570
571
  this.startPrepareAccessory = false;
571
572
  } catch (error) {
@@ -583,8 +584,6 @@ class DeviceErv extends EventEmitter {
583
584
  })
584
585
  .on('error', async (error) => {
585
586
  this.emit('error', error);
586
- await new Promise(resolve => setTimeout(resolve, 15000));
587
- await this.melCloudErv.impulseGenerator.start([{ name: 'checkState', sampling: this.refreshInterval }]);
588
587
  });
589
588
 
590
589
  //check state
@@ -599,64 +598,64 @@ class DeviceErv extends EventEmitter {
599
598
  };
600
599
  };
601
600
 
602
- async setOverExternalIntegration(integration, deviceState, key, value) {
601
+ async setOverExternalIntegration(integration, deviceData, key, value) {
603
602
  try {
604
603
  let set = false
605
604
  switch (key) {
606
605
  case 'Power':
607
- deviceState[key] = value;
608
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power;
609
- set = await this.melCloudErv.send(deviceState);
606
+ deviceData.Device[key] = value;
607
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power;
608
+ set = await this.melCloudErv.send(deviceData);
610
609
  break;
611
610
  case 'OperationMode':
612
- deviceState[key] = value;
613
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.OperationMode;
614
- set = await this.melCloudErv.send(deviceState);
611
+ deviceData.Device[key] = value;
612
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.OperationMode;
613
+ set = await this.melCloudErv.send(deviceData);
615
614
  break;
616
615
  case 'VentilationMode':
617
- deviceState[key] = value;
618
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
619
- set = await this.melCloudErv.send(deviceState);
616
+ deviceData.Device[key] = value;
617
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
618
+ set = await this.melCloudErv.send(deviceData);
620
619
  break;
621
620
  case 'SetTemperature':
622
- deviceState[key] = value;
623
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetTemperature;
624
- set = await this.melCloudErv.send(deviceState);
621
+ deviceData.Device[key] = value;
622
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetTemperature;
623
+ set = await this.melCloudErv.send(deviceData);
625
624
  break;
626
625
  case 'DefaultCoolingSetTemperature':
627
- deviceState[key] = value;
628
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetTemperature;
629
- set = await this.melCloudErv.send(deviceState);
626
+ deviceData.Device[key] = value;
627
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetTemperature;
628
+ set = await this.melCloudErv.send(deviceData);
630
629
  break;
631
630
  case 'DefaultHeatingSetTemperature':
632
- deviceState[key] = value;
633
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetTemperature;
634
- set = await this.melCloudErv.send(deviceState);
631
+ deviceData.Device[key] = value;
632
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetTemperature;
633
+ set = await this.melCloudErv.send(deviceData);
635
634
  break;
636
635
  case 'NightPurgeMode':
637
- deviceState[key] = value;
638
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.NightPurgeMode;
639
- set = await this.melCloudErv.send(deviceState);
636
+ deviceData.Device[key] = value;
637
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.NightPurgeMode;
638
+ set = await this.melCloudErv.send(deviceData);
640
639
  break;
641
640
  case 'SetFanSpeed':
642
- deviceState[key] = value;
643
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetFanSpeed;
644
- set = await this.melCloudErv.send(deviceState);
641
+ deviceData.Device[key] = value;
642
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetFanSpeed;
643
+ set = await this.melCloudErv.send(deviceData);
645
644
  break;
646
645
  case 'HideRoomTemperature':
647
- deviceState[key] = value;
648
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Prohibit;
649
- set = await this.melCloudErv.send(deviceState);
646
+ deviceData.Device[key] = value;
647
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Prohibit;
648
+ set = await this.melCloudErv.send(deviceData);
650
649
  break;
651
650
  case 'HideSupplyTemperature':
652
- deviceState[key] = value;
653
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Prohibit;
654
- set = await this.melCloudErv.send(deviceState);
651
+ deviceData.Device[key] = value;
652
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Prohibit;
653
+ set = await this.melCloudErv.send(deviceData);
655
654
  break;
656
655
  case 'HideOutdoorTemperature':
657
- deviceState[key] = value;
658
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Prohibit;
659
- set = await this.melCloudErv.send(deviceState);
656
+ deviceData.Device[key] = value;
657
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Prohibit;
658
+ set = await this.melCloudErv.send(deviceData);
660
659
  break;
661
660
  default:
662
661
  this.emit('warn', `${integration}, received key: ${key}, value: ${value}`);
@@ -669,7 +668,7 @@ class DeviceErv extends EventEmitter {
669
668
  }
670
669
 
671
670
  //prepare accessory
672
- async prepareAccessory(accountInfo, deviceState, deviceId, deviceTypeText, deviceName, accountName) {
671
+ async prepareAccessory(accountInfo, deviceData, deviceId, deviceTypeText, deviceName, accountName) {
673
672
  try {
674
673
  //accessory
675
674
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare accessory`) : false;
@@ -687,15 +686,11 @@ class DeviceErv extends EventEmitter {
687
686
  .setCharacteristic(Characteristic.FirmwareRevision, this.firmwareRevision);
688
687
 
689
688
  //melcloud services
690
- const presetsOnServer = this.accessory.presetsOnServer;
691
689
  const displayMode = this.displayMode;
690
+ const presetsOnServer = this.accessory.presetsOnServer;
692
691
  const temperatureSensor = this.temperatureSensor;
693
692
  const temperatureSensorOutdoor = this.temperatureSensorOutdoor;
694
693
  const temperatureSensorSupply = this.temperatureSensorSupply;
695
- const presetsConfigured = this.presetsConfigured;
696
- const presetsConfiguredCount = this.presetsConfiguredCount;
697
- const buttonsConfigured = this.buttonsConfigured;
698
- const buttonsConfiguredCount = this.buttonsConfiguredCount;
699
694
  const hasCoolOperationMode = this.accessory.hasCoolOperationMode;
700
695
  const hasHeatOperationMode = this.accessory.hasHeatOperationMode;
701
696
  const hasCO2Sensor = this.accessory.hasCO2Sensor;
@@ -715,9 +710,9 @@ class DeviceErv extends EventEmitter {
715
710
  })
716
711
  .onSet(async (state) => {
717
712
  try {
718
- deviceState.Power = [false, true][state];
719
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power;
720
- await this.melCloudErv.send(deviceState);
713
+ deviceData.Device.Power = [false, true][state];
714
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power;
715
+ await this.melCloudErv.send(deviceData);
721
716
  const info = this.disableLogInfo ? false : this.emit('message', `Set power: ${state ? 'ON' : 'OFF'}`);
722
717
  } catch (error) {
723
718
  this.emit('warn', `Set power error: ${error}`);
@@ -742,21 +737,21 @@ class DeviceErv extends EventEmitter {
742
737
  try {
743
738
  switch (value) {
744
739
  case 0: //AUTO - AUTO
745
- deviceState.VentilationMode = hasAutoVentilationMode ? 2 : 0;
746
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
740
+ deviceData.Device.VentilationMode = hasAutoVentilationMode ? 2 : 0;
741
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
747
742
  break;
748
743
  case 1: //HEAT - LOSSNAY
749
- deviceState.VentilationMode = 0;
750
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
744
+ deviceData.Device.VentilationMode = 0;
745
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
751
746
  break;
752
747
  case 2: //COOL - BYPASS
753
- deviceState.VentilationMode = hasBypassVentilationMode ? 1 : 0;
754
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
748
+ deviceData.Device.VentilationMode = hasBypassVentilationMode ? 1 : 0;
749
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
755
750
  break;
756
751
  };
757
752
 
758
- await this.melCloudErv.send(deviceState);
759
- const operationModeText = CONSTANTS.Ventilation.VentilationMode[deviceState.VentilationMode];
753
+ await this.melCloudErv.send(deviceData);
754
+ const operationModeText = CONSTANTS.Ventilation.VentilationMode[deviceData.Device.VentilationMode];
760
755
  const info = this.disableLogInfo ? false : this.emit('message', `Set operation mode: ${operationModeText}`);
761
756
  } catch (error) {
762
757
  this.emit('warn', `Set operation mode error: ${error}`);
@@ -777,21 +772,21 @@ class DeviceErv extends EventEmitter {
777
772
  let fanSpeedModeText = 0; //AUTO, 1, 2, 3, 4, OFF
778
773
  switch (ataNumberOfFanSpeeds) {
779
774
  case 2: //Fan speed mode 2
780
- deviceState.SetFanSpeed = ataHasAutomaticFanSpeed ? [0, 1, 2, 0][value] : [1, 1, 2][value];
775
+ deviceData.Device.SetFanSpeed = ataHasAutomaticFanSpeed ? [0, 1, 2, 0][value] : [1, 1, 2][value];
781
776
  fanSpeedModeText = ataHasAutomaticFanSpeed ? [5, 1, 2, 0][value] : [5, 1, 2][value];
782
777
  break;
783
778
  case 3: //Fan speed mode 3
784
- deviceState.SetFanSpeed = ataHasAutomaticFanSpeed ? [0, 1, 2, 3, 0][value] : [1, 1, 2, 3][value];
779
+ deviceData.Device.SetFanSpeed = ataHasAutomaticFanSpeed ? [0, 1, 2, 3, 0][value] : [1, 1, 2, 3][value];
785
780
  fanSpeedModeText = ataHasAutomaticFanSpeed ? [5, 1, 2, 3, 0][value] : [5, 1, 2, 3][value];
786
781
  break;
787
782
  case 4: //Fan speed mode 4
788
- deviceState.SetFanSpeed = ataHasAutomaticFanSpeed ? [0, 1, 2, 3, 4, 0][value] : [1, 1, 2, 3, 4][value];
783
+ deviceData.Device.SetFanSpeed = ataHasAutomaticFanSpeed ? [0, 1, 2, 3, 4, 0][value] : [1, 1, 2, 3, 4][value];
789
784
  fanSpeedModeText = ataHasAutomaticFanSpeed ? [5, 1, 2, 3, 4, 0][value] : [5, 1, 2, 3, 4][value];
790
785
  break;
791
786
  };
792
787
 
793
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetFanSpeed;
794
- await this.melCloudErv.send(deviceState);
788
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetFanSpeed;
789
+ await this.melCloudErv.send(deviceData);
795
790
  const info = this.disableLogInfo ? false : this.emit('message', `Set fan speed mode: ${CONSTANTS.Ventilation.FanSpeed[fanSpeedModeText]}`);
796
791
  } catch (error) {
797
792
  this.emit('warn', `Set fan speed mode error: ${error}`);
@@ -821,9 +816,9 @@ class DeviceErv extends EventEmitter {
821
816
  })
822
817
  .onSet(async (value) => {
823
818
  try {
824
- deviceState.SetTemperature = value;
825
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetTemperature;
826
- await this.melCloudErv.send(deviceState);
819
+ deviceData.Device.SetTemperature = value;
820
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetTemperature;
821
+ await this.melCloudErv.send(deviceData);
827
822
  const info = this.disableLogInfo ? false : this.emit('message', `Set heating threshold temperature: ${value}${this.accessory.temperatureUnit}`);
828
823
  } catch (error) {
829
824
  this.emit('warn', `Set heating threshold temperature error: ${error}`);
@@ -844,9 +839,9 @@ class DeviceErv extends EventEmitter {
844
839
  })
845
840
  .onSet(async (value) => {
846
841
  try {
847
- deviceState.SetTemperature = value;
848
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetTemperature;
849
- await this.melCloudErv.send(deviceState);
842
+ deviceData.Device.SetTemperature = value;
843
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetTemperature;
844
+ await this.melCloudErv.send(deviceData);
850
845
  const info = this.disableLogInfo ? false : this.emit('message', `Set cooling threshold temperature: ${value}${this.accessory.temperatureUnit}`);
851
846
  } catch (error) {
852
847
  this.emit('warn', `Set cooling threshold temperature error: ${error}`);
@@ -862,9 +857,9 @@ class DeviceErv extends EventEmitter {
862
857
  // .onSet(async (value) => {
863
858
  // try {
864
859
  // value = value ? true : false;
865
- // deviceState = deviceState;
866
- // deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Prohibit;
867
- // await this.melCloudErv.send(deviceState);
860
+ // deviceData.Device = deviceData.Device;
861
+ // deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Prohibit;
862
+ // await this.melCloudErv.send(deviceData);
868
863
  // const info = this.disableLogInfo ? false : this.emit('message', `Set local physical controls: ${value ? 'LOCK' : 'UNLOCK'}`);
869
864
  // } catch (error) {
870
865
  // this.emit('warn', `Set lock physical controls error: ${error}`);
@@ -907,28 +902,28 @@ class DeviceErv extends EventEmitter {
907
902
  try {
908
903
  switch (value) {
909
904
  case 0: //OFF - POWER OFF
910
- deviceState.Power = false;
911
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power;
905
+ deviceData.Device.Power = false;
906
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power;
912
907
  break;
913
908
  case 1: //HEAT - LOSSNAY
914
- deviceState.Power = true;
915
- deviceState.VentilationMode = 0;
916
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
909
+ deviceData.Device.Power = true;
910
+ deviceData.Device.VentilationMode = 0;
911
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
917
912
  break;
918
913
  case 2: //COOL - BYPASS
919
- deviceState.Power = true;
920
- deviceState.VentilationMode = hasBypassVentilationMode ? 1 : 0;
921
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
914
+ deviceData.Device.Power = true;
915
+ deviceData.Device.VentilationMode = hasBypassVentilationMode ? 1 : 0;
916
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
922
917
  break;
923
918
  case 3: //AUTO - AUTO
924
- deviceState.Power = true;
925
- deviceState.VentilationMode = hasAutoVentilationMode ? 2 : 0;
926
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
919
+ deviceData.Device.Power = true;
920
+ deviceData.Device.VentilationMode = hasAutoVentilationMode ? 2 : 0;
921
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
927
922
  break;
928
923
  };
929
924
 
930
- await this.melCloudErv.send(deviceState);
931
- const operationModeText = CONSTANTS.Ventilation.VentilationMode[deviceState.VentilationMode];
925
+ await this.melCloudErv.send(deviceData);
926
+ const operationModeText = CONSTANTS.Ventilation.VentilationMode[deviceData.Device.VentilationMode];
932
927
  const info = this.disableLogInfo ? false : this.emit('message', `Set operation mode: ${operationModeText}`);
933
928
  } catch (error) {
934
929
  this.emit('warn', `Set operation mode error: ${error}`);
@@ -956,9 +951,9 @@ class DeviceErv extends EventEmitter {
956
951
  })
957
952
  .onSet(async (value) => {
958
953
  try {
959
- deviceState.SetTemperature = value;
960
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetTemperature;
961
- await this.melCloudErv.send(deviceState);
954
+ deviceData.Device.SetTemperature = value;
955
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.SetTemperature;
956
+ await this.melCloudErv.send(deviceData);
962
957
  const info = this.disableLogInfo ? false : this.emit('message', `Set temperature: ${value}${this.accessory.temperatureUnit}`);
963
958
  } catch (error) {
964
959
  this.emit('warn', `Set temperature error: ${error}`);
@@ -1103,22 +1098,18 @@ class DeviceErv extends EventEmitter {
1103
1098
  }
1104
1099
 
1105
1100
  //presets services
1106
- if (presetsConfiguredCount > 0) {
1101
+ if (this.presetsConfiguredCount > 0) {
1107
1102
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare presets services`) : false;
1108
1103
  this.presetsServices = [];
1109
1104
  const previousPresets = [];
1110
1105
 
1111
- for (let i = 0; i < presetsConfiguredCount; i++) {
1112
- const preset = presetsConfigured[i];
1113
- const index = presetsOnServer.findIndex(p => p.ID === preset.Id);
1114
- const presetData = presetsOnServer[index]
1106
+ for (let i = 0; i < this.presetsConfiguredCount; i++) {
1107
+ const preset = this.presetsConfigured[i];
1108
+ const presetData = presetsOnServer.find(p => p.ID === preset.Id);
1115
1109
 
1116
1110
  //get preset name
1117
1111
  const presetName = preset.name;
1118
1112
 
1119
- //get preset display type
1120
- const displayType = button.displayType;
1121
-
1122
1113
  //get preset name prefix
1123
1114
  const presetNamePrefix = preset.namePrefix;
1124
1115
 
@@ -1130,54 +1121,49 @@ class DeviceErv extends EventEmitter {
1130
1121
  presetService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
1131
1122
  presetService.getCharacteristic(characteristicType)
1132
1123
  .onGet(async () => {
1133
- const state = this.presetsStates[i];
1124
+ const state = preset.state;
1134
1125
  return state;
1135
1126
  })
1136
- if (displayType > 2) {
1137
- presetService.onSet(async (state) => {
1127
+ .onSet(async (state) => {
1138
1128
  try {
1139
1129
  switch (state) {
1140
1130
  case true:
1141
- previousPresets[i] = deviceState;
1142
- deviceState.SetTemperature = presetData.SetTemperature;
1143
- deviceState.Power = presetData.Power;
1144
- deviceState.OperationMode = presetData.OperationMode;
1145
- deviceState.VentilationMode = presetData.VentilationMode;
1146
- deviceState.SetFanSpeed = presetData.FanSpeed;
1147
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power;
1131
+ previousPresets[i] = deviceData.Device;
1132
+ deviceData.Device.SetTemperature = presetData.SetTemperature;
1133
+ deviceData.Device.Power = presetData.Power;
1134
+ deviceData.Device.OperationMode = presetData.OperationMode;
1135
+ deviceData.Device.VentilationMode = presetData.VentilationMode;
1136
+ deviceData.Device.SetFanSpeed = presetData.FanSpeed;
1137
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power;
1148
1138
  break;
1149
1139
  case false:
1150
- deviceState = previousPresets[i];
1140
+ deviceData.Device = previousPresets[i];
1151
1141
  break;
1152
1142
  };
1153
1143
 
1154
- await this.melCloudErv.send(deviceState);
1144
+ await this.melCloudErv.send(deviceData);
1155
1145
  const info = this.disableLogInfo ? false : this.emit('message', `Set: ${presetName}`);
1156
1146
  } catch (error) {
1157
1147
  this.emit('warn', `Set preset error: ${error}`);
1158
1148
  };
1159
1149
  });
1160
- };
1161
- previousPresets.push(deviceState);
1162
- this.presetsServices.push(presetService);
1163
- accessory.addService(presetService);
1164
1150
  };
1151
+ previousPresets.push(deviceData.Device);
1152
+ this.presetsServices.push(presetService);
1153
+ accessory.addService(presetService);
1165
1154
  };
1166
1155
 
1167
1156
  //buttons services
1168
- if (buttonsConfiguredCount > 0) {
1157
+ if (this.buttonsConfiguredCount > 0) {
1169
1158
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare buttons services`) : false;
1170
1159
  this.buttonsServices = [];
1171
1160
 
1172
- for (let i = 0; i < buttonsConfiguredCount; i++) {
1173
- const button = buttonsConfigured[i];
1161
+ for (let i = 0; i < this.buttonsConfiguredCount; i++) {
1162
+ const button = this.buttonsConfigured[i];
1174
1163
 
1175
1164
  //get button mode
1176
1165
  const mode = button.mode;
1177
1166
 
1178
- //get button display type
1179
- const displayType = button.displayType;
1180
-
1181
1167
  //get button name
1182
1168
  const buttonName = button.name;
1183
1169
 
@@ -1195,84 +1181,82 @@ class DeviceErv extends EventEmitter {
1195
1181
  const state = button.state;
1196
1182
  return state;
1197
1183
  })
1198
- if (displayType > 2) {
1199
- buttonService.onSet(async (state) => {
1184
+ .onSet(async (state) => {
1200
1185
  try {
1201
1186
  switch (mode) {
1202
1187
  case 0: //POWER ON,OFF
1203
- deviceState.Power = state;
1204
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power;
1188
+ deviceData.Device.Power = state;
1189
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power;
1205
1190
  break;
1206
1191
  case 1: //OPERATING MODE RECOVERY
1207
- deviceState.Power = true;
1208
- deviceState.VentilationMode = 0;
1209
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
1192
+ deviceData.Device.Power = true;
1193
+ deviceData.Device.VentilationMode = 0;
1194
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
1210
1195
  break;
1211
1196
  case 2: //OPERATING MODE BYPASS
1212
- deviceState.Power = true;
1213
- deviceState.VentilationMode = 1;
1214
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
1197
+ deviceData.Device.Power = true;
1198
+ deviceData.Device.VentilationMode = 1;
1199
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
1215
1200
  break
1216
1201
  case 3: //OPERATING MODE AUTO
1217
- deviceState.Power = true;
1218
- deviceState.VentilationMode = 2;
1219
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
1202
+ deviceData.Device.Power = true;
1203
+ deviceData.Device.VentilationMode = 2;
1204
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.VentilationMode;
1220
1205
  break;
1221
1206
  case 4: //NIGHT PURGE MODE
1222
- deviceState.Power = true;
1223
- deviceState.NightPurgeMode = state;
1224
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power
1207
+ deviceData.Device.Power = true;
1208
+ deviceData.Device.NightPurgeMode = state;
1209
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power
1225
1210
  break;
1226
1211
  case 10: //FAN SPEED MODE AUTO
1227
- deviceState.Power = true;
1228
- deviceState.SetFanSpeed = 0;
1229
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.SetFanSpeed;
1212
+ deviceData.Device.Power = true;
1213
+ deviceData.Device.SetFanSpeed = 0;
1214
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.SetFanSpeed;
1230
1215
  break;
1231
1216
  case 11: //FAN SPEED MODE 1
1232
- deviceState.Power = true;
1233
- deviceState.SetFanSpeed = 1;
1234
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.SetFanSpeed;
1217
+ deviceData.Device.Power = true;
1218
+ deviceData.Device.SetFanSpeed = 1;
1219
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.SetFanSpeed;
1235
1220
  break;
1236
1221
  case 12: //FAN SPEED MODE 2
1237
- deviceState.Power = true;
1238
- deviceState.SetFanSpeed = 2;
1239
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.SetFanSpeed;
1222
+ deviceData.Device.Power = true;
1223
+ deviceData.Device.SetFanSpeed = 2;
1224
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.SetFanSpeed;
1240
1225
  break;
1241
1226
  case 13: //FAN SPEED MODE 3
1242
- deviceState.Power = true;
1243
- deviceState.SetFanSpeed = 3;
1244
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.SetFanSpeed;
1227
+ deviceData.Device.Power = true;
1228
+ deviceData.Device.SetFanSpeed = 3;
1229
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.SetFanSpeed;
1245
1230
  break;
1246
1231
  case 14: //FAN MODE 4
1247
- deviceState.Power = true;
1248
- deviceState.SetFanSpeed = 4;
1249
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.SetFanSpeed;
1232
+ deviceData.Device.Power = true;
1233
+ deviceData.Device.SetFanSpeed = 4;
1234
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Power + CONSTANTS.Ventilation.EffectiveFlags.SetFanSpeed;
1250
1235
  break;
1251
1236
  case 15: //PHYSICAL LOCK CONTROLS
1252
- deviceState = deviceState;
1253
- deviceState.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Prohibit;
1237
+ deviceData.Device = deviceData.Device;
1238
+ deviceData.Device.EffectiveFlags = CONSTANTS.Ventilation.EffectiveFlags.Prohibit;
1254
1239
  break;
1255
1240
  case 16: //ROOM TEMP HIDE
1256
- deviceState.HideRoomTemperature = state;
1241
+ deviceData.Device.HideRoomTemperature = state;
1257
1242
  break;
1258
1243
  case 17: //SUPPLY TEMP HIDE
1259
- deviceState.HideSupplyTemperature = state;
1244
+ deviceData.Device.HideSupplyTemperature = state;
1260
1245
  break;
1261
1246
  case 18: //OUTDOOR EMP HIDE
1262
- deviceState.hideOutdoorTemperature = state;
1247
+ deviceData.Device.hideOutdoorTemperature = state;
1263
1248
  break;
1264
1249
  default:
1265
1250
  this.emit('message', `Unknown button mode: ${mode}`);
1266
1251
  break;
1267
1252
  };
1268
1253
 
1269
- await this.melCloudErv.send(deviceState);
1254
+ await this.melCloudErv.send(deviceData);
1270
1255
  const info = this.disableLogInfo ? false : this.emit('message', `Set: ${buttonName}`);
1271
1256
  } catch (error) {
1272
1257
  this.emit('warn', `Set button error: ${error}`);
1273
1258
  };
1274
1259
  });
1275
- };
1276
1260
  this.buttonsServices.push(buttonService);
1277
1261
  accessory.addService(buttonService);
1278
1262
  };