homebridge-melcloud-control 4.2.6 → 4.2.8-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/deviceatw.js CHANGED
@@ -29,7 +29,7 @@ class DeviceAtw extends EventEmitter {
29
29
  this.device = device;
30
30
  this.deviceId = device.id;
31
31
  this.deviceName = device.name;
32
- this.deviceTypeText = device.typeString;
32
+ this.deviceTypeString = device.typeString;
33
33
  this.displayType = device.displayType;
34
34
  this.hideZone = device.hideZone;
35
35
  this.temperatureSensor = device.temperatureSensor || false;
@@ -49,11 +49,12 @@ class DeviceAtw extends EventEmitter {
49
49
  this.schedules = this.accountType === 'melcloudhome' ? (device.schedules || []).filter(schedule => (schedule.displayType ?? 0) > 0 && schedule.id !== '0') : [];
50
50
  this.scenes = this.accountType === 'melcloudhome' ? (device.scenes || []).filter(scene => (scene.displayType ?? 0) > 0 && scene.id !== '0') : [];
51
51
  this.buttons = (device.buttonsSensors || []).filter(button => (button.displayType ?? 0) > 0);
52
+
53
+ //files
52
54
  this.devicesFile = devicesFile;
53
55
  this.defaultTempsFile = defaultTempsFile;
54
56
  this.accountInfo = accountInfo;
55
57
  this.accountFile = accountFile;
56
- this.displayDeviceInfo = true;
57
58
 
58
59
  //external integrations
59
60
  this.restFul = account.restFul ?? {};
@@ -61,8 +62,8 @@ class DeviceAtw extends EventEmitter {
61
62
  this.mqtt = account.mqtt ?? {};
62
63
  this.mqttConnected = false;
63
64
 
64
- const serviceType = [null, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor];
65
- const characteristicType = [null, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState];
65
+ const serviceType = [null, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor, null];
66
+ const characteristicType = [null, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState, null];
66
67
 
67
68
  //presets configured
68
69
  for (const preset of this.presets) {
@@ -103,13 +104,23 @@ class DeviceAtw extends EventEmitter {
103
104
  .on('error', error => this.emit('error', error))
104
105
  .on('debug', debug => this.emit('debug', debug));
105
106
 
106
- //device data
107
+ //other variables
108
+ this.displayDeviceInfo = true;
107
109
  this.deviceData = {};
108
-
109
- //accessory
110
110
  this.accessory = {};
111
111
  };
112
112
 
113
+ async startStopImpulseGenerator(state, timers = []) {
114
+ try {
115
+ //start impulse generator
116
+ await this.melCloudAtw.impulseGenerator.state(state, timers)
117
+ return true;
118
+ } catch (error) {
119
+ throw new Error(`Impulse generator start error: ${error}`);
120
+ }
121
+ }
122
+
123
+
113
124
  async externalIntegrations() {
114
125
  //RESTFul server
115
126
  const restFulEnabled = this.restFul.enable || false;
@@ -157,7 +168,7 @@ class DeviceAtw extends EventEmitter {
157
168
  host: this.mqtt.host,
158
169
  port: this.mqtt.port || 1883,
159
170
  clientId: this.mqtt.clientId ? `melcloud_${this.mqtt.clientId}_${Math.random().toString(16).slice(3)}` : `melcloud_${Math.random().toString(16).slice(3)}`,
160
- prefix: this.mqtt.prefix ? `melcloud/${this.mqtt.prefix}/${this.deviceTypeText}/${this.deviceName}` : `melcloud/${this.deviceTypeText}/${this.deviceName}`,
171
+ prefix: this.mqtt.prefix ? `melcloud/${this.mqtt.prefix}/${this.deviceTypeString}/${this.deviceName}` : `melcloud/${this.deviceTypeString}/${this.deviceName}`,
161
172
  user: this.mqtt.auth?.user,
162
173
  passwd: this.mqtt.auth?.passwd,
163
174
  logWarn: this.logWarn,
@@ -297,22 +308,12 @@ class DeviceAtw extends EventEmitter {
297
308
  };
298
309
  }
299
310
 
300
- async startStopImpulseGenerator(state, timers = []) {
301
- try {
302
- //start impulse generator
303
- await this.melCloudAtw.impulseGenerator.state(state, timers)
304
- return true;
305
- } catch (error) {
306
- throw new Error(`Impulse generator start error: ${error}`);
307
- }
308
- }
309
-
310
311
  //prepare accessory
311
312
  async prepareAccessory() {
312
313
  try {
313
314
  const deviceData = this.deviceData;
314
315
  const deviceId = this.deviceId;
315
- const deviceTypeText = this.deviceTypeText;
316
+ const deviceTypeString = this.deviceTypeString;
316
317
  const deviceName = this.deviceName;
317
318
  const accountName = this.accountName;
318
319
  const presetsOnServer = this.accessory.presets;
@@ -348,12 +349,12 @@ class DeviceAtw extends EventEmitter {
348
349
  .setCharacteristic(Characteristic.ConfiguredName, accessoryName);
349
350
 
350
351
  //services
351
- const serviceName = `${deviceTypeText} ${accessoryName}`;
352
+ const serviceName = `${deviceTypeString} ${accessoryName}`;
352
353
  if (zonesCount > 0) {
353
354
  this.melCloudServices = [];
354
355
  this.accessory.zones.forEach((zone, i) => {
355
356
  const zoneName = zone.name
356
- const serviceName = `${deviceTypeText} ${accessoryName}: ${zoneName}`;
357
+ const serviceName = `${deviceTypeString} ${accessoryName}: ${zoneName}`;
357
358
  switch (this.displayType) {
358
359
  case 1: //Heater Cooler
359
360
  if (this.logDebug) this.emit('debug', `Prepare heather/cooler ${zoneName} service`);
@@ -856,7 +857,7 @@ class DeviceAtw extends EventEmitter {
856
857
  if (zonesSensorsCount > 0) {
857
858
  this.accessory.zonesSensors.forEach((zone, i) => {
858
859
  const zoneName = zone.name
859
- const serviceName = `${deviceTypeText} ${accessoryName}: ${zoneName}`;
860
+ const serviceName = `${deviceTypeString} ${accessoryName}: ${zoneName}`;
860
861
  switch (i) {
861
862
  case caseHeatPumpSensor: //Heat Pump
862
863
  if (zone.roomTemperature !== null) {
@@ -1174,17 +1175,19 @@ class DeviceAtw extends EventEmitter {
1174
1175
  }
1175
1176
 
1176
1177
  //sensor
1177
- if (this.logDebug) this.emit('debug', `Prepare preset control sensor s${name} ervice`);
1178
- const presetControlSensorService = new serviceType(serviceName1, `presetControlSensorService${deviceId} ${i}`);
1179
- presetControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1180
- presetControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName1} Control`);
1181
- presetControlSensorService.getCharacteristic(characteristicType)
1182
- .onGet(async () => {
1183
- const state = this.accessory.scheduleEnabled;
1184
- return state;
1185
- })
1186
- this.presetControlSensorServices.push(presetControlSensorService);
1187
- accessory.addService(presetControlSensorService);
1178
+ if (preset.displayType < 7) {
1179
+ if (this.logDebug) this.emit('debug', `Prepare preset control sensor s${name} ervice`);
1180
+ const presetControlSensorService = new serviceType(serviceName1, `presetControlSensorService${deviceId} ${i}`);
1181
+ presetControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1182
+ presetControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName1} Control`);
1183
+ presetControlSensorService.getCharacteristic(characteristicType)
1184
+ .onGet(async () => {
1185
+ const state = this.accessory.scheduleEnabled;
1186
+ return state;
1187
+ })
1188
+ this.presetControlSensorServices.push(presetControlSensorService);
1189
+ accessory.addService(presetControlSensorService);
1190
+ }
1188
1191
  });
1189
1192
  };
1190
1193
 
@@ -1231,30 +1234,34 @@ class DeviceAtw extends EventEmitter {
1231
1234
  }
1232
1235
 
1233
1236
  //sensor
1234
- if (this.logDebug) this.emit('debug', `Prepare schedule control sensor ${name} service`);
1235
- this.scheduleControlSensorService = new serviceType(`${serviceName2} Control`, `scheduleControlSensorService${deviceId} ${i}`);
1236
- this.scheduleControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1237
- this.scheduleControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName2} Control`);
1238
- this.scheduleControlSensorService.getCharacteristic(characteristicType)
1239
- .onGet(async () => {
1240
- const state = this.accessory.scheduleEnabled;
1241
- return state;
1242
- })
1243
- accessory.addService(this.scheduleControlSensorService);
1237
+ if (schedule.displayType < 7) {
1238
+ if (this.logDebug) this.emit('debug', `Prepare schedule control sensor ${name} service`);
1239
+ this.scheduleControlSensorService = new serviceType(`${serviceName2} Control`, `scheduleControlSensorService${deviceId} ${i}`);
1240
+ this.scheduleControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1241
+ this.scheduleControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName2} Control`);
1242
+ this.scheduleControlSensorService.getCharacteristic(characteristicType)
1243
+ .onGet(async () => {
1244
+ const state = this.accessory.scheduleEnabled;
1245
+ return state;
1246
+ })
1247
+ accessory.addService(this.scheduleControlSensorService);
1248
+ }
1244
1249
  }
1245
1250
 
1246
1251
  //sensors
1247
- if (this.logDebug) this.emit('debug', `Prepare schedule sensor ${name} service`);
1248
- const scheduleSensorService = new serviceType(serviceName1, `scheduleSensorService${deviceId} ${i}`);
1249
- scheduleSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1250
- scheduleSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
1251
- scheduleSensorService.getCharacteristic(characteristicType)
1252
- .onGet(async () => {
1253
- const state = schedule.state;
1254
- return state;
1255
- });
1256
- this.scheduleSensorServices.push(scheduleSensorService);
1257
- accessory.addService(scheduleSensorService);
1252
+ if (schedule.displayType < 7) {
1253
+ if (this.logDebug) this.emit('debug', `Prepare schedule sensor ${name} service`);
1254
+ const scheduleSensorService = new serviceType(serviceName1, `scheduleSensorService${deviceId} ${i}`);
1255
+ scheduleSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1256
+ scheduleSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
1257
+ scheduleSensorService.getCharacteristic(characteristicType)
1258
+ .onGet(async () => {
1259
+ const state = schedule.state;
1260
+ return state;
1261
+ });
1262
+ this.scheduleSensorServices.push(scheduleSensorService);
1263
+ accessory.addService(scheduleSensorService);
1264
+ }
1258
1265
  });
1259
1266
  };
1260
1267
 
@@ -1300,17 +1307,20 @@ class DeviceAtw extends EventEmitter {
1300
1307
  accessory.addService(sceneControlService);
1301
1308
  }
1302
1309
 
1303
- if (this.logDebug) this.emit('debug', `Prepare scene control sensor ${name} service`);
1304
- const sceneControlSensorService = new serviceType(`${serviceName1} Control`, `sceneControlSensorService${deviceId} ${i}`);
1305
- sceneControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1306
- sceneControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName1} Control`);
1307
- sceneControlSensorService.getCharacteristic(characteristicType)
1308
- .onGet(async () => {
1309
- const state = scene.state;
1310
- return state;
1311
- })
1312
- this.sceneControlSensorServices.push(sceneControlSensorService);
1313
- accessory.addService(sceneControlSensorService);
1310
+ //sensor
1311
+ if (scene.displayType < 7) {
1312
+ if (this.logDebug) this.emit('debug', `Prepare scene control sensor ${name} service`);
1313
+ const sceneControlSensorService = new serviceType(`${serviceName1} Control`, `sceneControlSensorService${deviceId} ${i}`);
1314
+ sceneControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1315
+ sceneControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName1} Control`);
1316
+ sceneControlSensorService.getCharacteristic(characteristicType)
1317
+ .onGet(async () => {
1318
+ const state = scene.state;
1319
+ return state;
1320
+ })
1321
+ this.sceneControlSensorServices.push(sceneControlSensorService);
1322
+ accessory.addService(sceneControlSensorService);
1323
+ }
1314
1324
  });
1315
1325
  };
1316
1326
 
@@ -1493,17 +1503,19 @@ class DeviceAtw extends EventEmitter {
1493
1503
  }
1494
1504
 
1495
1505
  //sensor
1496
- if (this.logDebug) this.emit('debug', `Prepare button control sensor ${name} service`);
1497
- const buttonControlSensorService = new serviceType(serviceName1, `buttonControlSensorService${deviceId} ${i}`);
1498
- buttonControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1499
- buttonControlSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
1500
- buttonControlSensorService.getCharacteristic(characteristicType)
1501
- .onGet(async () => {
1502
- const state = button.state;
1503
- return state;
1504
- })
1505
- this.buttonControlSensorServices.push(buttonControlSensorService);
1506
- accessory.addService(buttonControlSensorService);
1506
+ if (button.displayType < 7) {
1507
+ if (this.logDebug) this.emit('debug', `Prepare button control sensor ${name} service`);
1508
+ const buttonControlSensorService = new serviceType(serviceName1, `buttonControlSensorService${deviceId} ${i}`);
1509
+ buttonControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1510
+ buttonControlSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
1511
+ buttonControlSensorService.getCharacteristic(characteristicType)
1512
+ .onGet(async () => {
1513
+ const state = button.state;
1514
+ return state;
1515
+ })
1516
+ this.buttonControlSensorServices.push(buttonControlSensorService);
1517
+ accessory.addService(buttonControlSensorService);
1518
+ }
1507
1519
  });
1508
1520
  };
1509
1521
 
@@ -1520,7 +1532,7 @@ class DeviceAtw extends EventEmitter {
1520
1532
  this.melCloudAtw = new MelCloudAtw(this.account, this.device, this.devicesFile, this.defaultTempsFile, this.accountFile)
1521
1533
  .on('deviceInfo', (modelIndoor, modelOutdoor, serialNumber, firmwareAppVersion, supportsHotWaterTank, supportsZone2) => {
1522
1534
  if (this.logDeviceInfo && this.displayDeviceInfo) {
1523
- this.emit('devInfo', `---- ${this.deviceTypeText}: ${this.deviceName} ----`);
1535
+ this.emit('devInfo', `---- ${this.deviceTypeString}: ${this.deviceName} ----`);
1524
1536
  this.emit('devInfo', `Account: ${this.accountName}`);
1525
1537
  if (modelIndoor) this.emit('devInfo', `Indoor: ${modelIndoor}`);
1526
1538
  if (modelOutdoor) this.emit('devInfo', `Outdoor: ${modelOutdoor}`);
@@ -1537,7 +1549,7 @@ class DeviceAtw extends EventEmitter {
1537
1549
 
1538
1550
  //accessory info
1539
1551
  this.manufacturer = 'Mitsubishi';
1540
- this.model = modelIndoor ? modelIndoor : modelOutdoor ? modelOutdoor : `${this.deviceTypeText} ${this.deviceId}`;
1552
+ this.model = modelIndoor ? modelIndoor : modelOutdoor ? modelOutdoor : `${this.deviceTypeString} ${this.deviceId}`;
1541
1553
  this.serialNumber = serialNumber.toString();
1542
1554
  this.firmwareRevision = firmwareAppVersion.toString();
1543
1555
 
@@ -2093,16 +2105,14 @@ class DeviceAtw extends EventEmitter {
2093
2105
  && presetData.SetCoolFlowTemperatureZone2 === setCoolFlowTemperatureZone2) : false;
2094
2106
 
2095
2107
  //control
2096
- if (preset.displayType > 3) {
2097
- this.presetControlServices?.[i]?.updateCharacteristic(Characteristic.On, preset.state);
2098
- }
2108
+ if (preset.displayType > 3) this.presetControlServices?.[i]?.updateCharacteristic(Characteristic.On, preset.state);
2099
2109
 
2100
2110
  //sencor
2101
- this.presetControlSensorServices?.[i]?.updateCharacteristic(characteristicType, preset.state);
2111
+ if (preset.displayType < 7) this.presetControlSensorServices?.[i]?.updateCharacteristic(characteristicType, preset.state);
2102
2112
  });
2103
2113
  };
2104
2114
 
2105
- //schedules
2115
+ ///schedules
2106
2116
  if (this.schedules.length > 0 && scheduleEnabled !== null) {
2107
2117
  this.schedules.forEach((schedule, i) => {
2108
2118
  const scheduleData = schedulesOnServer.find(s => s.Id === schedule.id);
@@ -2111,37 +2121,34 @@ class DeviceAtw extends EventEmitter {
2111
2121
 
2112
2122
  //control
2113
2123
  if (i === 0) {
2114
- if (schedule.displayType > 3) {
2115
- this.scheduleControlService?.updateCharacteristic(Characteristic.On, scheduleEnabled);
2116
- }
2117
- this.scheduleControlSensorService?.updateCharacteristic(characteristicType, scheduleEnabled);
2124
+ if (schedule.displayType > 3) this.scheduleControlService?.updateCharacteristic(Characteristic.On, scheduleEnabled);
2125
+ if (schedule.displayType < 7) this.scheduleControlSensorService?.updateCharacteristic(characteristicType, scheduleEnabled);
2118
2126
  }
2119
2127
 
2120
2128
  //sensor
2121
- this.scheduleSensorServices?.[i]?.updateCharacteristic(characteristicType, schedule.state);
2129
+ if (schedule.displayType < 7) this.scheduleSensorServices?.[i]?.updateCharacteristic(characteristicType, schedule.state);
2122
2130
  });
2123
2131
  };
2124
2132
 
2125
- //schedules
2133
+ //scenes
2126
2134
  if (this.scenes.length > 0) {
2127
2135
  this.scenes.forEach((scene, i) => {
2128
2136
  const sceneData = scenesOnServer.find(s => s.Id === scene.id);
2137
+ const characteristicType = scene.characteristicType;
2129
2138
  scene.state = sceneData.Enabled;
2130
2139
 
2131
2140
  //control
2132
- if (scene.displayType > 3) {
2133
- this.sceneControlServices?.[i]?.updateCharacteristic(Characteristic.On, scene.state);
2134
- }
2141
+ if (scene.displayType > 3) this.sceneControlServices?.[i]?.updateCharacteristic(Characteristic.On, scene.state);
2135
2142
 
2136
2143
  //sensor
2137
- const characteristicType = scene.characteristicType;
2138
- this.sceneControlSensorServices?.[i]?.updateCharacteristic(characteristicType, scene.state);
2144
+ if (scene.displayType < 7) this.sceneControlSensorServices?.[i]?.updateCharacteristic(characteristicType, scene.state);
2139
2145
  });
2140
2146
  };
2141
2147
 
2142
2148
  //buttons
2143
2149
  if (this.buttons.length > 0) {
2144
2150
  this.buttons.forEach((button, i) => {
2151
+ const characteristicType = button.characteristicType;
2145
2152
  const mode = button.mode;
2146
2153
  switch (mode) {
2147
2154
  case 0: //POWER ON,OFF
@@ -2219,13 +2226,10 @@ class DeviceAtw extends EventEmitter {
2219
2226
  };
2220
2227
 
2221
2228
  //control
2222
- if (button.displayType > 3) {
2223
- this.buttonControlServices?.[i]?.updateCharacteristic(Characteristic.On, button.state);
2224
- }
2229
+ if (button.displayType > 3) this.buttonControlServices?.[i]?.updateCharacteristic(Characteristic.On, button.state);
2225
2230
 
2226
2231
  //sensor
2227
- const characteristicType = scene.characteristicType;
2228
- this.buttonControlSensorServices?.[i]?.updateCharacteristic(characteristicType, button.state);
2232
+ if (button.displayType < 7) this.buttonControlSensorServices?.[i]?.updateCharacteristic(characteristicType, button.state);
2229
2233
  });
2230
2234
  };
2231
2235
  })