homebridge-melcloud-control 3.9.1 → 3.9.2-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/index.js CHANGED
@@ -54,12 +54,16 @@ class MelCloudPlatform {
54
54
 
55
55
  //log config
56
56
  const enableDebugMode = account.enableDebugMode || false;
57
- const disableLogDeviceInfo = account.disableLogDeviceInfo || false;
58
- const disableLogInfo = account.disableLogInfo || false;
59
- const disableLogSuccess = account.disableLogSuccess || false;
60
- const disableLogWarn = account.disableLogWarn || false;
61
- const disableLogError = account.disableLogError || false;
62
- const debug = enableDebugMode ? log.info(`${accountName}, debug: Did finish launching.`) : false;
57
+ const logLevel = {
58
+ debug: enableDebugMode,
59
+ info: !account.disableLogInfo,
60
+ success: !account.disableLogSuccess,
61
+ warn: !account.disableLogWarn,
62
+ error: !account.disableLogError,
63
+ devInfo: !account.disableLogDeviceInfo,
64
+ };
65
+
66
+ if (logLevel.debug) log.info(`${accountName}, debug: Did finish launching.`);
63
67
 
64
68
  //remove sensitive data
65
69
  const debugData = {
@@ -70,7 +74,7 @@ class MelCloudPlatform {
70
74
  passwd: 'removed'
71
75
  }
72
76
  };
73
- const debug1 = !enableDebugMode ? false : log.info(`${accountName}, Config: ${JSON.stringify(debugData, null, 2)}`);
77
+ if (logLevel.debug) log.info(`${accountName}, Config: ${JSON.stringify(debugData, null, 2)}`);
74
78
 
75
79
  //define directory and file paths
76
80
  const accountFile = `${prefDir}/${accountName}_Account`;
@@ -82,22 +86,13 @@ class MelCloudPlatform {
82
86
 
83
87
  try {
84
88
  //melcloud account
85
- const melCloud = new MelCloud(user, passwd, language, accountFile, buildingsFile, devicesFile, enableDebugMode, false);
86
- melCloud.on('success', (success) => {
87
- const emitLog = disableLogSuccess ? false : log.success(`${accountName}, ${success}.`);
88
- })
89
- .on('info', (info) => {
90
- const emitLog = disableLogInfo ? false : log.info(`${accountName}, ${info}.`);
91
- })
92
- .on('debug', (debug) => {
93
- const emitLog = !enableDebugMode ? false : log.info(`${accountName}, debug: ${debug}.`);
94
- })
95
- .on('warn', (warn) => {
96
- const emitLog = disableLogWarn ? false : log.warn(`${accountName}, ${warn}.`);
97
- })
98
- .on('error', (error) => {
99
- const emitLog = disableLogError ? false : log.error(`${accountName}, ${error}.`);
100
- });
89
+ const melCloud = new MelCloud(user, passwd, language, accountFile, buildingsFile, devicesFile, enableDebugMode, false)
90
+ .on('success', (msg) => logLevel.success && log.success(`${accountName}, ${msg}`))
91
+ .on('info', (msg) => logLevel.info && log.info(`${accountName}, ${msg}`))
92
+ .on('debug', (msg) => logLevel.debug && log.info(`${accountName}, debug: ${msg}`))
93
+ .on('warn', (msg) => logLevel.warn && log.warn(`${accountName}, ${msg}`))
94
+ .on('error', (msg) => logLevel.error && log.error(`${accountName}, ${msg}`));
95
+
101
96
 
102
97
  //connect
103
98
  const response = await melCloud.connect();
@@ -123,7 +118,7 @@ class MelCloudPlatform {
123
118
  const atwDevices = account.atwDevices ?? [];
124
119
  const ervDevices = account.ervDevices ?? [];
125
120
  const devices = [...ataDevices, ...atwDevices, ...ervDevices];
126
- const emitLog = !enableDebugMode ? false : log.info(`Found configured devices ATA: ${ataDevices.length}, ATW: ${atwDevices.length}, ERV: ${ervDevices.length}.`);
121
+ if (logLevel.debug) log.info(`Found configured devices ATA: ${ataDevices.length}, ATW: ${atwDevices.length}, ERV: ${ervDevices.length}.`);
127
122
  for (const device of devices) {
128
123
  //chack device from config exist on melcloud
129
124
  const deviceId = device.id;
@@ -152,65 +147,52 @@ class MelCloudPlatform {
152
147
  configuredDevice = new DeviceErv(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile, deviceRefreshInterval, useFahrenheit, restFul, mqtt);
153
148
  break;
154
149
  default:
155
- const emitLog = disableLogWarn ? false : log.warn(`${accountName}, ${deviceTypeText}, ${deviceName}, unknown device: ${deviceType}.`);
150
+ if (logLevel.warn) log.warn(`${accountName}, ${deviceTypeText}, ${deviceName}, unknown device: ${deviceType}.`);
156
151
  return;
157
152
  }
158
153
 
159
- configuredDevice.on('publishAccessory', (accessory) => {
160
- api.publishExternalAccessories(PluginName, [accessory]);
161
- const emitLog = disableLogSuccess ? false : log.success(`${accountName}, ${deviceTypeText}, ${deviceName}, published as external accessory.`);
154
+ configuredDevice.on('melCloud', async (key, value) => {
155
+ try {
156
+ accountInfo[key] = value;
157
+ await melCloud.send(accountInfo);
158
+ } catch (error) {
159
+ if (logLevel.error) log.error(`${accountName}, ${deviceTypeText}, ${deviceName}, ${error}.`);
160
+ }
162
161
  })
163
- .on('melCloud', async (key, value) => {
164
- try {
165
- accountInfo[key] = value;
166
- await melCloud.send(accountInfo);
167
- } catch (error) {
168
- const emitLog = disableLogError ? false : log.error(`${accountName}, ${deviceTypeText}, ${deviceName}, ${error}.`);
169
- }
170
- })
171
- .on('devInfo', (devInfo) => {
172
- const emitLog = disableLogDeviceInfo ? false : log.info(devInfo);
173
- })
174
- .on('success', (success) => {
175
- const emitLog = disableLogSuccess ? false : log.success(`${accountName}, ${deviceTypeText}, ${deviceName}, ${success}.`);
176
- })
177
- .on('info', (info) => {
178
- const emitLog = disableLogInfo ? false : log.info(`${accountName}, ${deviceTypeText}, ${deviceName}, ${info}.`);
179
- })
180
- .on('debug', (debug) => {
181
- const emitLog = !enableDebugMode ? false : log.info(`${accountName}, ${deviceTypeText}, ${deviceName}, debug: ${debug}.`);
182
- })
183
- .on('warn', (warn) => {
184
- const emitLog = disableLogWarn ? false : log.warn(`${accountName}, ${deviceTypeText}, ${deviceName}, ${warn}.`);
185
- })
186
- .on('error', (error) => {
187
- const emitLog = disableLogError ? false : log.error(`${accountName}, ${deviceTypeText}, ${deviceName}, ${error}.`);
188
- });
162
+ .on('devInfo', (info) => logLevel.devInfo && log.info(info))
163
+ .on('success', (msg) => logLevel.success && log.success(`${accountName}, ${deviceTypeText}, ${deviceName}, ${msg}`))
164
+ .on('info', (msg) => logLevel.info && log.info(`${accountName}, ${deviceTypeText}, ${deviceName}, ${msg}`))
165
+ .on('debug', (msg) => logLevel.debug && log.info(`${accountName}, ${deviceTypeText}, ${deviceName}, debug: ${msg}`))
166
+ .on('warn', (msg) => logLevel.warn && log.warn(`${accountName}, ${deviceTypeText}, ${deviceName}, ${msg}`))
167
+ .on('error', (msg) => logLevel.error && log.error(`${accountName}, ${deviceTypeText}, ${deviceName}, ${msg}`));
189
168
 
190
169
  //create impulse generator
191
170
  const impulseGenerator = new ImpulseGenerator();
192
171
  impulseGenerator.on('start', async () => {
193
172
  try {
194
- const startDone = await configuredDevice.start();
195
- const stopImpulseGenerator = startDone ? await impulseGenerator.stop() : false;
173
+ const accessory = await configuredDevice.start();
174
+ if (accessory) {
175
+ api.publishExternalAccessories(PluginName, [accessory]);
176
+ if (logLevel.success) log.success(`${accountName}, ${deviceTypeText}, ${deviceName}, Published as external accessory.`);
196
177
 
197
- //start impulse generator
198
- const startImpulseGenerator = stopImpulseGenerator ? await configuredDevice.startImpulseGenerator() : false
178
+ await impulseGenerator.stop();
179
+ await configuredDevice.startImpulseGenerator();
180
+ }
199
181
  } catch (error) {
200
- const emitLog = disableLogError ? false : log.error(`${accountName}, ${deviceTypeText}, ${deviceName}, ${error}, trying again.`);
182
+ if (logLevel.error) log.error(`${accountName}, ${deviceTypeText}, ${deviceName}, ${error}, trying again.`);
201
183
  }
202
184
  }).on('state', (state) => {
203
- const emitLog = !enableDebugMode ? false : state ? log.info(`${accountName}, ${deviceTypeText}, ${deviceName}, Start impulse generator started.`) : log.info(`${accountName}, ${deviceTypeText}, ${deviceName}, Start impulse generator stopped.`);
185
+ if (logLevel.debug) log.info(`${accountName}, ${deviceTypeText}, ${deviceName}, Start impulse generator ${state ? 'started' : 'stopped'}.`);
204
186
  });
205
187
 
206
188
  //start impulse generator
207
189
  await impulseGenerator.start([{ name: 'start', sampling: 45000 }]);
208
190
  } catch (error) {
209
- const emitLog = disableLogError ? false : log.error(`${accountName}, ${deviceTypeText}, ${deviceName}, did finish launching error: ${error}.`);
191
+ if (logLevel.error) log.error(`${accountName}, ${deviceTypeText}, ${deviceName}, did finish launching error: ${error}.`);
210
192
  }
211
193
  }
212
194
  } catch (error) {
213
- const emitLog = disableLogError ? false : log.error(`${accountName}, did finish launching error: ${error}.`);
195
+ if (logLevel.error) log.error(`${accountName}, did finish launching error: ${error}.`);
214
196
  }
215
197
  }
216
198
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "3.9.1",
4
+ "version": "3.9.2-beta.1",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/deviceata.js CHANGED
@@ -258,8 +258,9 @@ class DeviceAta extends EventEmitter {
258
258
  }
259
259
 
260
260
  //prepare accessory
261
- async prepareAccessory(deviceData) {
261
+ async prepareAccessory() {
262
262
  try {
263
+ const deviceData = this.deviceData;
263
264
  const deviceId = this.deviceId;
264
265
  const deviceTypeText = this.deviceTypeText;
265
266
  const deviceName = this.deviceName;
@@ -1369,43 +1370,28 @@ class DeviceAta extends EventEmitter {
1369
1370
  this.emit('info', `Temperature display unit: ${obj.temperatureUnit}`);
1370
1371
  this.emit('info', `Lock physical controls: ${obj.lockPhysicalControl ? 'LOCKED' : 'UNLOCKED'}`);
1371
1372
  };
1372
-
1373
- //prepare accessory
1374
- if (this.startPrepareAccessory) {
1375
- const accessory = await this.prepareAccessory(deviceData);
1376
- this.emit('publishAccessory', accessory);
1377
- this.startPrepareAccessory = false;
1378
- }
1379
- })
1380
- .on('success', (success) => {
1381
- this.emit('success', success);
1382
- })
1383
- .on('info', (info) => {
1384
- this.emit('info', info);
1385
- })
1386
- .on('debug', (debug) => {
1387
- this.emit('debug', debug);
1388
- })
1389
- .on('warn', (warn) => {
1390
- this.emit('warn', warn);
1391
- })
1392
- .on('error', (error) => {
1393
- this.emit('error', error);
1394
1373
  })
1374
+ .on('success', (success) => this.emit('success', success))
1375
+ .on('info', (info) => this.emit('info', info))
1376
+ .on('debug', (debug) => this.emit('debug', debug))
1377
+ .on('warn', (warn) => this.emit('warn', warn))
1378
+ .on('error', (error) => this.emit('error', error))
1395
1379
  .on('restFul', (path, data) => {
1396
- const restFul = this.restFulConnected ? this.restFul1.update(path, data) : false;
1380
+ if (this.restFulConnected) this.restFul1.update(path, data);
1397
1381
  })
1398
1382
  .on('mqtt', (topic, message) => {
1399
- const mqtt = this.mqttConnected ? this.mqtt1.emit('publish', topic, message) : false;
1383
+ if (this.mqttConnected) this.mqtt1.emit('publish', topic, message);
1400
1384
  });
1401
1385
 
1402
1386
  //start external integrations
1403
- const startExternalIntegrations = this.restFul.enable || this.mqtt.enable ? await this.externalIntegrations() : false;
1387
+ if (this.restFul.enable || this.mqtt.enable) await this.externalIntegrations();
1404
1388
 
1405
1389
  //check state
1406
1390
  await this.melCloudAta.checkState();
1407
1391
 
1408
- return true;
1392
+ //prepare accessory
1393
+ const accessory = await this.prepareAccessory();
1394
+ return accessory;
1409
1395
  } catch (error) {
1410
1396
  throw new Error(`Start error: ${error}`);
1411
1397
  };
package/src/deviceatw.js CHANGED
@@ -284,8 +284,9 @@ class DeviceAtw extends EventEmitter {
284
284
  }
285
285
 
286
286
  //prepare accessory
287
- async prepareAccessory(deviceData) {
287
+ async prepareAccessory() {
288
288
  try {
289
+ const deviceData = this.deviceData;
289
290
  const deviceId = this.deviceId;
290
291
  const deviceTypeText = this.deviceTypeText;
291
292
  const deviceName = this.deviceName;
@@ -305,14 +306,14 @@ class DeviceAtw extends EventEmitter {
305
306
  const caseZone2Sensor = this.accessory.caseZone2Sensor;
306
307
 
307
308
  //accessory
308
- if (this.enableDebugMode) this.emit('debug', `Prepare accessory`);
309
+ if (this.enableDebugMode) this.emit('debug', `Prepare accessory`);
309
310
  const accessoryName = deviceName;
310
311
  const accessoryUUID = AccessoryUUID.generate(accountName + deviceId.toString());
311
312
  const accessoryCategory = [Categories.OTHER, Categories.AIR_HEATER, Categories.THERMOSTAT][this.displayType];
312
313
  const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
313
314
 
314
315
  //information service
315
- if (this.enableDebugMode) this.emit('debug', `Prepare information service`);
316
+ if (this.enableDebugMode) this.emit('debug', `Prepare information service`);
316
317
  accessory.getService(Service.AccessoryInformation)
317
318
  .setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
318
319
  .setCharacteristic(Characteristic.Model, this.model)
@@ -328,7 +329,7 @@ class DeviceAtw extends EventEmitter {
328
329
  const serviceName = `${deviceTypeText} ${accessoryName}: ${zoneName}`;
329
330
  switch (this.displayMode) {
330
331
  case 1: //Heater Cooler
331
- if (this.enableDebugMode) this.emit('debug', `Prepare heather/cooler ${zoneName} service`);
332
+ if (this.enableDebugMode) this.emit('debug', `Prepare heather/cooler ${zoneName} service`);
332
333
  const melCloudService = new Service.HeaterCooler(serviceName, `HeaterCooler ${deviceId} ${i}`);
333
334
  melCloudService.setPrimaryService(true);
334
335
  melCloudService.getCharacteristic(Characteristic.Active)
@@ -639,7 +640,7 @@ class DeviceAtw extends EventEmitter {
639
640
  accessory.addService(melCloudService);
640
641
  break;
641
642
  case 2: //Thermostat
642
- if (this.enableDebugMode) this.emit('debug', `Prepare thermostat ${zoneName} service`);
643
+ if (this.enableDebugMode) this.emit('debug', `Prepare thermostat ${zoneName} service`);
643
644
  const melCloudServiceT = new Service.Thermostat(serviceName, `Thermostat ${deviceId} ${i}`);
644
645
  melCloudServiceT.setPrimaryService(true);
645
646
  melCloudServiceT.getCharacteristic(Characteristic.CurrentHeatingCoolingState)
@@ -832,7 +833,7 @@ class DeviceAtw extends EventEmitter {
832
833
  switch (i) {
833
834
  case caseHeatPumpSensor: //Heat Pump
834
835
  if (zone.roomTemperature !== null) {
835
- if (this.enableDebugMode) this.emit('debug', `${zoneName}, Prepare temperature sensor service`);
836
+ if (this.enableDebugMode) this.emit('debug', `${zoneName}, Prepare temperature sensor service`);
836
837
  this.roomTemperatureSensorService = new Service.TemperatureSensor(`${serviceName}`, `${zoneName} Temperature Sensor ${deviceId} ${i}`);
837
838
  this.roomTemperatureSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
838
839
  this.roomTemperatureSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} ${zoneName}`);
@@ -850,7 +851,7 @@ class DeviceAtw extends EventEmitter {
850
851
  };
851
852
 
852
853
  if (zone.flowTemperature !== null) {
853
- if (this.enableDebugMode) this.emit('debug', `Prepare flow temperature sensor service`);
854
+ if (this.enableDebugMode) this.emit('debug', `Prepare flow temperature sensor service`);
854
855
  this.flowTemperatureSensorService = new Service.TemperatureSensor(`${serviceName} Flow`, `${zoneName} Temperature Sensor Flow ${deviceId} ${i}`);
855
856
  this.flowTemperatureSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
856
857
  this.flowTemperatureSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} ${zoneName} Flow`);
@@ -869,7 +870,7 @@ class DeviceAtw extends EventEmitter {
869
870
  };
870
871
 
871
872
  if (zone.returnTemperature !== null) {
872
- if (this.enableDebugMode) this.emit('debug', `Prepare return temperature sensor service`);
873
+ if (this.enableDebugMode) this.emit('debug', `Prepare return temperature sensor service`);
873
874
  this.returnTemperatureSensorService = new Service.TemperatureSensor(`${serviceName} Return`, `${zoneName} Temperature Sensor Return ${deviceId} ${i}`);
874
875
  this.returnTemperatureSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
875
876
  this.returnTemperatureSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} ${zoneName} Return`);
@@ -888,7 +889,7 @@ class DeviceAtw extends EventEmitter {
888
889
  break;
889
890
  case caseZone1Sensor: //Zone 1
890
891
  if (zone.roomTemperature !== null) {
891
- if (this.enableDebugMode) this.emit('debug', `${zoneName}, Prepare temperature sensor service`);
892
+ if (this.enableDebugMode) this.emit('debug', `${zoneName}, Prepare temperature sensor service`);
892
893
  this.roomTemperatureZone1SensorService = new Service.TemperatureSensor(`${serviceName}`, `${zoneName} Temperature Sensor ${deviceId} ${i}`);
893
894
  this.roomTemperatureZone1SensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
894
895
  this.roomTemperatureZone1SensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} ${zoneName}`);
@@ -906,7 +907,7 @@ class DeviceAtw extends EventEmitter {
906
907
  };
907
908
 
908
909
  if (zone.flowTemperature !== null) {
909
- if (this.enableDebugMode) this.emit('debug', `Prepare flow temperature zone 1 sensor service`);
910
+ if (this.enableDebugMode) this.emit('debug', `Prepare flow temperature zone 1 sensor service`);
910
911
  this.flowTemperatureZone1SensorService = new Service.TemperatureSensor(`${serviceName} Flow`, `${zoneName} Temperature Sensor Flow ${deviceId} ${i}`);
911
912
  this.flowTemperatureZone1SensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
912
913
  this.flowTemperatureZone1SensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} ${zoneName} Flow`);
@@ -924,7 +925,7 @@ class DeviceAtw extends EventEmitter {
924
925
  };
925
926
 
926
927
  if (zone.returnTemperature !== null) {
927
- if (this.enableDebugMode) this.emit('debug', `Prepare return temperature zone 1 sensor service`);
928
+ if (this.enableDebugMode) this.emit('debug', `Prepare return temperature zone 1 sensor service`);
928
929
  this.returnTemperatureZone1SensorService = new Service.TemperatureSensor(`${serviceName} Return`, `${zoneName} Temperature Sensor Return ${deviceId} ${i}`);
929
930
  this.returnTemperatureZone1SensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
930
931
  this.returnTemperatureZone1SensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} ${zoneName} Return`);
@@ -943,7 +944,7 @@ class DeviceAtw extends EventEmitter {
943
944
  break;
944
945
  case caseHotWaterSensor: //Hot Water
945
946
  if (zone.roomTemperature !== null) {
946
- if (this.enableDebugMode) this.emit('debug', `${zoneName}, Prepare temperature sensor service`);
947
+ if (this.enableDebugMode) this.emit('debug', `${zoneName}, Prepare temperature sensor service`);
947
948
  this.roomTemperatureWaterTankSensorService = new Service.TemperatureSensor(`${serviceName}`, `${zoneName} Temperature Sensor ${deviceId} ${i}`);
948
949
  this.roomTemperatureWaterTankSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
949
950
  this.roomTemperatureWaterTankSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} ${zoneName}`);
@@ -961,7 +962,7 @@ class DeviceAtw extends EventEmitter {
961
962
  };
962
963
 
963
964
  if (zone.flowTemperature !== null) {
964
- if (this.enableDebugMode) this.emit('debug', `Prepare flow temperature water tank sensor service`);
965
+ if (this.enableDebugMode) this.emit('debug', `Prepare flow temperature water tank sensor service`);
965
966
  this.flowTemperatureWaterTankSensorService = new Service.TemperatureSensor(`${serviceName} Flow`, `${zoneName} Temperature Sensor Flow ${deviceId} ${i}`);
966
967
  this.flowTemperatureWaterTankSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
967
968
  this.flowTemperatureWaterTankSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} ${zoneName} Flow`);
@@ -979,7 +980,7 @@ class DeviceAtw extends EventEmitter {
979
980
  };
980
981
 
981
982
  if (zone.returnTemperature !== null) {
982
- if (this.enableDebugMode) this.emit('debug', `Prepare return temperature water tank sensor service`);
983
+ if (this.enableDebugMode) this.emit('debug', `Prepare return temperature water tank sensor service`);
983
984
  this.returnTemperatureWaterTankSensorService = new Service.TemperatureSensor(`${serviceName} Return`, `${zoneName} Temperature Sensor Return ${deviceId} ${i}`);
984
985
  this.returnTemperatureWaterTankSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
985
986
  this.returnTemperatureWaterTankSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} ${zoneName} Return`);
@@ -998,7 +999,7 @@ class DeviceAtw extends EventEmitter {
998
999
  break;
999
1000
  case caseZone2Sensor: //Zone 2
1000
1001
  if (zone.roomTemperature !== null) {
1001
- if (this.enableDebugMode) this.emit('debug', `${zoneName}, Prepare temperature sensor service`);
1002
+ if (this.enableDebugMode) this.emit('debug', `${zoneName}, Prepare temperature sensor service`);
1002
1003
  this.roomTemperatureZone2SensorService = new Service.TemperatureSensor(`${serviceName}`, `${zoneName} Temperature Sensor ${deviceId} ${i}`);
1003
1004
  this.roomTemperatureZone2SensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1004
1005
  this.roomTemperatureZone2SensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} ${zoneName}`);
@@ -1016,7 +1017,7 @@ class DeviceAtw extends EventEmitter {
1016
1017
  };
1017
1018
 
1018
1019
  if (zone.flowTemperature !== null) {
1019
- if (this.enableDebugMode) this.emit('debug', `Prepare flow temperature zone 2 sensor service`);
1020
+ if (this.enableDebugMode) this.emit('debug', `Prepare flow temperature zone 2 sensor service`);
1020
1021
  this.flowTemperatureZone2SensorService = new Service.TemperatureSensor(`${serviceName} Flow`, `${zoneName} Temperature Sensor Flow${deviceId} ${i}`);
1021
1022
  this.flowTemperatureZone2SensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1022
1023
  this.flowTemperatureZone2SensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} ${zoneName} Flow`);
@@ -1034,7 +1035,7 @@ class DeviceAtw extends EventEmitter {
1034
1035
  };
1035
1036
 
1036
1037
  if (zone.returnTemperature !== null) {
1037
- if (this.enableDebugMode) this.emit('debug', `Prepare return temperature zone 2 sensor service`);
1038
+ if (this.enableDebugMode) this.emit('debug', `Prepare return temperature zone 2 sensor service`);
1038
1039
  this.returnTemperatureZone2SensorService = new Service.TemperatureSensor(`${serviceName} Return`, `${zoneName} Temperature Sensor Return${deviceId} ${i}`);
1039
1040
  this.returnTemperatureZone2SensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1040
1041
  this.returnTemperatureZone2SensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} ${zoneName} Return`);
@@ -1057,7 +1058,7 @@ class DeviceAtw extends EventEmitter {
1057
1058
 
1058
1059
  //presets services
1059
1060
  if (this.presetsConfiguredCount > 0) {
1060
- if (this.enableDebugMode) this.emit('debug', `Prepare presets services`);
1061
+ if (this.enableDebugMode) this.emit('debug', `Prepare presets services`);
1061
1062
  this.presetsServices = [];
1062
1063
  this.presetsConfigured.forEach((preset, i) => {
1063
1064
  const presetData = presetsOnServer.find(p => p.ID === preset.Id);
@@ -1128,7 +1129,7 @@ class DeviceAtw extends EventEmitter {
1128
1129
 
1129
1130
  //buttons services
1130
1131
  if (this.buttonsConfiguredCount > 0) {
1131
- if (this.enableDebugMode) this.emit('debug', `Prepare buttons services`);
1132
+ if (this.enableDebugMode) this.emit('debug', `Prepare buttons services`);
1132
1133
  this.buttonsServices = [];
1133
1134
  this.buttonsConfigured.forEach((button, i) => {
1134
1135
  //get button mode
@@ -1972,52 +1973,30 @@ class DeviceAtw extends EventEmitter {
1972
1973
  this.emit('warn', `Unknown button mode: ${mode} detected`);
1973
1974
  break;
1974
1975
  };
1975
-
1976
- //update services
1977
- if (this.buttonsServices) {
1978
- const characteristicType = button.characteristicType;
1979
- this.buttonsServices[i]
1980
- .updateCharacteristic(characteristicType, button.state)
1981
- };
1982
1976
  };
1983
1977
  };
1984
-
1985
- //prepare accessory
1986
- if (this.startPrepareAccessory) {
1987
- const accessory = await this.prepareAccessory(deviceData);
1988
- this.emit('publishAccessory', accessory);
1989
- this.startPrepareAccessory = false;
1990
- }
1991
- })
1992
- .on('success', (success) => {
1993
- this.emit('success', success);
1994
- })
1995
- .on('info', (info) => {
1996
- this.emit('info', info);
1997
- })
1998
- .on('debug', (debug) => {
1999
- this.emit('debug', debug);
2000
- })
2001
- .on('warn', (warn) => {
2002
- this.emit('warn', warn);
2003
- })
2004
- .on('error', (error) => {
2005
- this.emit('error', error);
2006
1978
  })
1979
+ .on('success', (success) => this.emit('success', success))
1980
+ .on('info', (info) => this.emit('info', info))
1981
+ .on('debug', (debug) => this.emit('debug', debug))
1982
+ .on('warn', (warn) => this.emit('warn', warn))
1983
+ .on('error', (error) => this.emit('error', error))
2007
1984
  .on('restFul', (path, data) => {
2008
- const restFul = this.restFulConnected ? this.restFul1.update(path, data) : false;
1985
+ if (this.restFulConnected) this.restFul1.update(path, data);
2009
1986
  })
2010
1987
  .on('mqtt', (topic, message) => {
2011
- const mqtt = this.mqttConnected ? this.mqtt1.emit('publish', topic, message) : false;
1988
+ if (this.mqttConnected) this.mqtt1.emit('publish', topic, message);
2012
1989
  });
2013
1990
 
2014
1991
  //start external integrations
2015
- const startExternalIntegrations = this.restFul.enable || this.mqtt.enable ? await this.externalIntegrations() : false;
1992
+ if (this.restFul.enable || this.mqtt.enable) await this.externalIntegrations();
2016
1993
 
2017
1994
  //check state
2018
1995
  await this.melCloudAtw.checkState();
2019
1996
 
2020
- return true;
1997
+ //prepare accessory
1998
+ const accessory = await this.prepareAccessory(deviceData);
1999
+ return accessory;
2021
2000
  } catch (error) {
2022
2001
  throw new Error(`Start error: ${error}`);
2023
2002
  };
package/src/deviceerv.js CHANGED
@@ -246,8 +246,9 @@ class DeviceErv extends EventEmitter {
246
246
  }
247
247
 
248
248
  //prepare accessory
249
- async prepareAccessory(deviceData) {
249
+ async prepareAccessory() {
250
250
  try {
251
+ const deviceData = this.deviceData;
251
252
  const deviceId = this.deviceId;
252
253
  const deviceTypeText = this.deviceTypeText;
253
254
  const deviceName = this.deviceName;
@@ -266,14 +267,14 @@ class DeviceErv extends EventEmitter {
266
267
  const numberOfFanSpeeds = this.accessory.numberOfFanSpeeds;
267
268
 
268
269
  //accessory
269
- if (this.enableDebugMode) this.emit('debug', `Prepare accessory`);
270
+ if (this.enableDebugMode) this.emit('debug', `Prepare accessory`);
270
271
  const accessoryName = deviceName;
271
272
  const accessoryUUID = AccessoryUUID.generate(accountName + deviceId.toString());
272
273
  const accessoryCategory = [Categories.OTHER, Categories.AIR_PURIFIER, Categories.THERMOSTAT][this.displayType];
273
274
  const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
274
275
 
275
276
  //information service
276
- if (this.enableDebugMode) this.emit('debug', `Prepare information service`);
277
+ if (this.enableDebugMode) this.emit('debug', `Prepare information service`);
277
278
  accessory.getService(Service.AccessoryInformation)
278
279
  .setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
279
280
  .setCharacteristic(Characteristic.Model, this.model)
@@ -285,7 +286,7 @@ class DeviceErv extends EventEmitter {
285
286
  const serviceName = `${deviceTypeText} ${accessoryName}`;
286
287
  switch (this.displayMode) {
287
288
  case 1: //Heater Cooler
288
- if (this.enableDebugMode) this.emit('debug', `Prepare heather/cooler service`);
289
+ if (this.enableDebugMode) this.emit('debug', `Prepare heather/cooler service`);
289
290
  this.melCloudService = new Service.HeaterCooler(serviceName, `HeaterCooler ${deviceId}`);
290
291
  this.melCloudService.setPrimaryService(true);
291
292
  this.melCloudService.getCharacteristic(Characteristic.Active)
@@ -464,7 +465,7 @@ class DeviceErv extends EventEmitter {
464
465
  accessory.addService(this.melCloudService);
465
466
  break;
466
467
  case 2: //Thermostat
467
- if (this.enableDebugMode) this.emit('debug', `Prepare thermostat service`);
468
+ if (this.enableDebugMode) this.emit('debug', `Prepare thermostat service`);
468
469
  this.melCloudService = new Service.Thermostat(serviceName, `Thermostat ${deviceId}`);
469
470
  this.melCloudService.setPrimaryService(true);
470
471
  this.melCloudService.getCharacteristic(Characteristic.CurrentHeatingCoolingState)
@@ -559,7 +560,7 @@ class DeviceErv extends EventEmitter {
559
560
 
560
561
  //temperature sensor service room
561
562
  if (this.temperatureSensor && hasRoomTemperature && this.accessory.roomTemperature !== null) {
562
- if (this.enableDebugMode) this.emit('debug', `Prepare room temperature sensor service`);
563
+ if (this.enableDebugMode) this.emit('debug', `Prepare room temperature sensor service`);
563
564
  this.roomTemperatureSensorService = new Service.TemperatureSensor(`${serviceName} Room`, `Room Temperature Sensor ${deviceId}`);
564
565
  this.roomTemperatureSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
565
566
  this.roomTemperatureSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName} Room`);
@@ -578,7 +579,7 @@ class DeviceErv extends EventEmitter {
578
579
 
579
580
  //temperature sensor service supply
580
581
  if (this.temperatureSensorSupply && hasSupplyTemperature && this.accessory.supplyTemperature !== null) {
581
- if (this.enableDebugMode) this.emit('debug', `Prepare supply temperature sensor service`);
582
+ if (this.enableDebugMode) this.emit('debug', `Prepare supply temperature sensor service`);
582
583
  this.supplyTemperatureSensorService = new Service.TemperatureSensor(`${serviceName} Supply`, `Supply Temperature Sensor ${deviceId}`);
583
584
  this.supplyTemperatureSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
584
585
  this.supplyTemperatureSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName} Supply`);
@@ -597,7 +598,7 @@ class DeviceErv extends EventEmitter {
597
598
 
598
599
  //temperature sensor service outdoor
599
600
  if (this.temperatureSensorOutdoor && hasOutdoorTemperature && this.accessory.outdoorTemperature !== null) {
600
- if (this.enableDebugMode) this.emit('debug', `Prepare outdoor temperature sensor service`);
601
+ if (this.enableDebugMode) this.emit('debug', `Prepare outdoor temperature sensor service`);
601
602
  this.outdoorTemperatureSensorService = new Service.TemperatureSensor(`${serviceName} Outdoor`, `Outdoor Temperature Sensor ${deviceId}`);
602
603
  this.outdoorTemperatureSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
603
604
  this.outdoorTemperatureSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName} Outdoor`);
@@ -680,7 +681,7 @@ class DeviceErv extends EventEmitter {
680
681
 
681
682
  //presets services
682
683
  if (this.presetsConfiguredCount > 0) {
683
- if (this.enableDebugMode) this.emit('debug', `Prepare presets services`);
684
+ if (this.enableDebugMode) this.emit('debug', `Prepare presets services`);
684
685
  this.presetsServices = [];
685
686
  this.presetsConfigured.forEach((preset, i) => {
686
687
  const presetData = presetsOnServer.find(p => p.ID === preset.Id);
@@ -737,7 +738,7 @@ class DeviceErv extends EventEmitter {
737
738
 
738
739
  //buttons services
739
740
  if (this.buttonsConfiguredCount > 0) {
740
- if (this.enableDebugMode) this.emit('debug', `Prepare buttons services`);
741
+ if (this.enableDebugMode) this.emit('debug', `Prepare buttons services`);
741
742
  this.buttonsServices = [];
742
743
  this.buttonsConfigured.forEach((button, i) => {
743
744
  //get button mode
@@ -1239,43 +1240,28 @@ class DeviceErv extends EventEmitter {
1239
1240
  const info7 = hasPM25Sensor ? this.emit('info', `PM2.5 air quality: ${Ventilation.PM25AirQuality[pM25AirQuality]}`) : false;
1240
1241
  const info8 = hasPM25Sensor ? this.emit('info', `PM2.5 level: ${pM25Level} µg/m`) : false;
1241
1242
  };
1242
-
1243
- //prepare accessory
1244
- if (this.startPrepareAccessory) {
1245
- const accessory = await this.prepareAccessory(deviceData);
1246
- this.emit('publishAccessory', accessory);
1247
- this.startPrepareAccessory = false;
1248
- }
1249
- })
1250
- .on('success', (success) => {
1251
- this.emit('success', success);
1252
- })
1253
- .on('info', (info) => {
1254
- this.emit('info', info);
1255
- })
1256
- .on('debug', (debug) => {
1257
- this.emit('debug', debug);
1258
- })
1259
- .on('warn', (warn) => {
1260
- this.emit('warn', warn);
1261
- })
1262
- .on('error', (error) => {
1263
- this.emit('error', error);
1264
1243
  })
1244
+ .on('success', (success) => this.emit('success', success))
1245
+ .on('info', (info) => this.emit('info', info))
1246
+ .on('debug', (debug) => this.emit('debug', debug))
1247
+ .on('warn', (warn) => this.emit('warn', warn))
1248
+ .on('error', (error) => this.emit('error', error))
1265
1249
  .on('restFul', (path, data) => {
1266
- const restFul = this.restFulConnected ? this.restFul1.update(path, data) : false;
1250
+ if (this.restFulConnected) this.restFul1.update(path, data);
1267
1251
  })
1268
1252
  .on('mqtt', (topic, message) => {
1269
- const mqtt = this.mqttConnected ? this.mqtt1.emit('publish', topic, message) : false;
1253
+ if (this.mqttConnected) this.mqtt1.emit('publish', topic, message);
1270
1254
  });
1271
1255
 
1272
1256
  //start external integrations
1273
- const startExternalIntegrations = this.restFul.enable || this.mqtt.enable ? await this.externalIntegrations() : false;
1257
+ if (this.restFul.enable || this.mqtt.enable) await this.externalIntegrations();
1274
1258
 
1275
1259
  //check state
1276
1260
  await this.melCloudErv.checkState();
1277
1261
 
1278
- return true;
1262
+ //prepare accessory
1263
+ const accessory = await this.prepareAccessory(deviceData);
1264
+ return accessory;
1279
1265
  } catch (error) {
1280
1266
  throw new Error(`Start error: ${error}`);
1281
1267
  };
@@ -38,7 +38,7 @@ class MelCloudAta extends EventEmitter {
38
38
  this.emit('error', `Impulse generator error: ${error}`);
39
39
  };
40
40
  }).on('state', (state) => {
41
- const emitState = state ? this.emit('success', `Impulse generator started`) : this.emit('warn', `Impulse generator stopped`);
41
+ this.emit('success', `Impulse generator ${state ? 'started' : 'stopped'}`);
42
42
  });
43
43
  };
44
44
 
@@ -52,7 +52,7 @@ class MelCloudAta extends EventEmitter {
52
52
  return null;
53
53
  }
54
54
  const deviceData = devicesData.find(device => device.DeviceID === this.deviceId);
55
- if (this.enableDebugMode) this.emit('debug', `Device Data: ${JSON.stringify(deviceData, null, 2)}`);
55
+ if (this.enableDebugMode) this.emit('debug', `Device Data: ${JSON.stringify(deviceData, null, 2)}`);
56
56
 
57
57
  //device info
58
58
  const deviceId = deviceData.DeviceID;
@@ -344,7 +344,7 @@ class MelCloudAta extends EventEmitter {
344
344
  //check state changes
345
345
  const deviceDataHasNotChanged = JSON.stringify(deviceState) === JSON.stringify(this.deviceState);
346
346
  if (deviceDataHasNotChanged) {
347
- if (this.enableDebugMode) this.emit('debug', `Device state not changed`);
347
+ if (this.enableDebugMode) this.emit('debug', `Device state not changed`);
348
348
  return;
349
349
  }
350
350
  this.deviceState = deviceState;
@@ -38,7 +38,7 @@ class MelCloudAtw extends EventEmitter {
38
38
  this.emit('error', `Impulse generator error: ${error}`);
39
39
  };
40
40
  }).on('state', (state) => {
41
- const emitState = state ? this.emit('success', `Impulse generator started`) : this.emit('warn', `Impulse generator stopped`);
41
+ this.emit('success', `Impulse generator ${state ? 'started' : 'stopped'}`);
42
42
  });
43
43
  };
44
44
 
@@ -52,7 +52,7 @@ class MelCloudAtw extends EventEmitter {
52
52
  return null;
53
53
  }
54
54
  const deviceData = devicesData.find(device => device.DeviceID === this.deviceId);
55
- if (this.enableDebugMode) this.emit('debug', `Device Data: ${JSON.stringify(deviceData, null, 2)}`);
55
+ if (this.enableDebugMode) this.emit('debug', `Device Data: ${JSON.stringify(deviceData, null, 2)}`);
56
56
 
57
57
  //device info
58
58
  const deviceId = deviceData.DeviceID;
@@ -408,7 +408,7 @@ class MelCloudAtw extends EventEmitter {
408
408
  //check state changes
409
409
  const deviceDataHasNotChanged = JSON.stringify(deviceState) === JSON.stringify(this.deviceState);
410
410
  if (deviceDataHasNotChanged) {
411
- if (this.enableDebugMode) this.emit('debug', `Device state not changed`);
411
+ if (this.enableDebugMode) this.emit('debug', `Device state not changed`);
412
412
  return;
413
413
  }
414
414
  this.deviceState = deviceState;
@@ -38,7 +38,7 @@ class MelCloudErv extends EventEmitter {
38
38
  this.emit('error', `Impulse generator error: ${error}`);
39
39
  };
40
40
  }).on('state', (state) => {
41
- const emitState = state ? this.emit('success', `Impulse generator started`) : this.emit('warn', `Impulse generator stopped`);
41
+ this.emit('success', `Impulse generator ${state ? 'started' : 'stopped'}`);
42
42
  });
43
43
  };
44
44
 
@@ -52,7 +52,7 @@ class MelCloudErv extends EventEmitter {
52
52
  return null;
53
53
  }
54
54
  const deviceData = devicesData.find(device => device.DeviceID === this.deviceId);
55
- if (this.enableDebugMode) this.emit('debug', `Device Data: ${JSON.stringify(deviceData, null, 2)}`);
55
+ if (this.enableDebugMode) this.emit('debug', `Device Data: ${JSON.stringify(deviceData, null, 2)}`);
56
56
 
57
57
  //deviceData
58
58
  const deviceId = deviceData.DeviceID;
@@ -332,7 +332,7 @@ class MelCloudErv extends EventEmitter {
332
332
  //check state changes
333
333
  const deviceDataHasNotChanged = JSON.stringify(deviceState) === JSON.stringify(this.deviceState);
334
334
  if (deviceDataHasNotChanged) {
335
- if (this.enableDebugMode) this.emit('debug', `Device state not changed`);
335
+ if (this.enableDebugMode) this.emit('debug', `Device state not changed`);
336
336
  return;
337
337
  }
338
338
  this.deviceState = deviceState;