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/deviceerv.js CHANGED
@@ -29,7 +29,7 @@ class DeviceErv 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.temperatureSensor = device.temperatureSensor || false;
35
35
  this.temperatureOutdoorSensor = device.temperatureOutdoorSensor || false;
@@ -42,11 +42,12 @@ class DeviceErv extends EventEmitter {
42
42
  this.schedules = this.accountType === 'melcloudhome' ? (device.schedules || []).filter(schedule => (schedule.displayType ?? 0) > 0 && schedule.id !== '0') : [];
43
43
  this.scenes = this.accountType === 'melcloudhome' ? (device.scenes || []).filter(scene => (scene.displayType ?? 0) > 0 && scene.id !== '0') : [];
44
44
  this.buttons = (device.buttonsSensors || []).filter(button => (button.displayType ?? 0) > 0);
45
+
46
+ //files
45
47
  this.devicesFile = devicesFile;
46
48
  this.defaultTempsFile = defaultTempsFile;
47
49
  this.accountInfo = accountInfo;
48
50
  this.accountFile = accountFile;
49
- this.displayDeviceInfo = true;
50
51
 
51
52
  //external integrations
52
53
  this.restFul = account.restFul ?? {};
@@ -54,8 +55,8 @@ class DeviceErv extends EventEmitter {
54
55
  this.mqtt = account.mqtt ?? {};
55
56
  this.mqttConnected = false;
56
57
 
57
- const serviceType = [null, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor];
58
- const characteristicType = [null, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState];
58
+ const serviceType = [null, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor, null];
59
+ const characteristicType = [null, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState, null];
59
60
 
60
61
  //presets configured
61
62
  for (const preset of this.presets) {
@@ -96,13 +97,22 @@ class DeviceErv extends EventEmitter {
96
97
  .on('error', error => this.emit('error', error))
97
98
  .on('debug', debug => this.emit('debug', debug));
98
99
 
99
- //device data
100
+ //other variables
101
+ this.displayDeviceInfo = true;
100
102
  this.deviceData = {};
101
-
102
- //accessory
103
103
  this.accessory = {};
104
104
  };
105
105
 
106
+ async startStopImpulseGenerator(state, timers = []) {
107
+ try {
108
+ //start impulse generator
109
+ await this.melCloudErv.impulseGenerator.state(state, timers)
110
+ return true;
111
+ } catch (error) {
112
+ throw new Error(`Impulse generator start error: ${error}`);
113
+ }
114
+ }
115
+
106
116
  async externalIntegrations() {
107
117
  //RESTFul server
108
118
  const restFulEnabled = this.restFul.enable || false;
@@ -150,7 +160,7 @@ class DeviceErv extends EventEmitter {
150
160
  host: this.mqtt.host,
151
161
  port: this.mqtt.port || 1883,
152
162
  clientId: this.mqtt.clientId ? `melcloud_${this.mqtt.clientId}_${Math.random().toString(16).slice(3)}` : `melcloud_${Math.random().toString(16).slice(3)}`,
153
- prefix: this.mqtt.prefix ? `melcloud/${this.mqtt.prefix}/${this.deviceTypeText}/${this.deviceName}` : `melcloud/${this.deviceTypeText}/${this.deviceName}`,
163
+ prefix: this.mqtt.prefix ? `melcloud/${this.mqtt.prefix}/${this.deviceTypeString}/${this.deviceName}` : `melcloud/${this.deviceTypeString}/${this.deviceName}`,
154
164
  user: this.mqtt.auth?.user,
155
165
  passwd: this.mqtt.auth?.passwd,
156
166
  logWarn: this.logWarn,
@@ -267,22 +277,12 @@ class DeviceErv extends EventEmitter {
267
277
  };
268
278
  }
269
279
 
270
- async startStopImpulseGenerator(state, timers = []) {
271
- try {
272
- //start impulse generator
273
- await this.melCloudErv.impulseGenerator.state(state, timers)
274
- return true;
275
- } catch (error) {
276
- throw new Error(`Impulse generator start error: ${error}`);
277
- }
278
- }
279
-
280
280
  //prepare accessory
281
281
  async prepareAccessory() {
282
282
  try {
283
283
  const deviceData = this.deviceData;
284
284
  const deviceId = this.deviceId;
285
- const deviceTypeText = this.deviceTypeText;
285
+ const deviceTypeString = this.deviceTypeString;
286
286
  const deviceName = this.deviceName;
287
287
  const accountName = this.accountName;
288
288
  const presetsOnServer = this.accessory.presets;
@@ -318,7 +318,7 @@ class DeviceErv extends EventEmitter {
318
318
  .setCharacteristic(Characteristic.ConfiguredName, accessoryName);
319
319
 
320
320
  //services
321
- const serviceName = `${deviceTypeText} ${accessoryName}`;
321
+ const serviceName = `${deviceTypeString} ${accessoryName}`;
322
322
  switch (this.displayType) {
323
323
  case 1: //Heater Cooler
324
324
  if (this.logDebug) this.emit('debug', `Prepare heather/cooler service`);
@@ -835,17 +835,19 @@ class DeviceErv extends EventEmitter {
835
835
  }
836
836
 
837
837
  //sensor
838
- if (this.logDebug) this.emit('debug', `Prepare preset control sensor s${name} ervice`);
839
- const presetControlSensorService = new serviceType(serviceName1, `presetControlSensorService${deviceId} ${i}`);
840
- presetControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
841
- presetControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName1} Control`);
842
- presetControlSensorService.getCharacteristic(characteristicType)
843
- .onGet(async () => {
844
- const state = this.accessory.scheduleEnabled;
845
- return state;
846
- })
847
- this.presetControlSensorServices.push(presetControlSensorService);
848
- accessory.addService(presetControlSensorService);
838
+ if (preset.displayType < 7) {
839
+ if (this.logDebug) this.emit('debug', `Prepare preset control sensor s${name} ervice`);
840
+ const presetControlSensorService = new serviceType(serviceName1, `presetControlSensorService${deviceId} ${i}`);
841
+ presetControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
842
+ presetControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName1} Control`);
843
+ presetControlSensorService.getCharacteristic(characteristicType)
844
+ .onGet(async () => {
845
+ const state = this.accessory.scheduleEnabled;
846
+ return state;
847
+ })
848
+ this.presetControlSensorServices.push(presetControlSensorService);
849
+ accessory.addService(presetControlSensorService);
850
+ }
849
851
  });
850
852
  };
851
853
 
@@ -892,30 +894,34 @@ class DeviceErv extends EventEmitter {
892
894
  }
893
895
 
894
896
  //sensor
895
- if (this.logDebug) this.emit('debug', `Prepare schedule control sensor ${name} service`);
896
- this.scheduleControlSensorService = new serviceType(`${serviceName2} Control`, `scheduleControlSensorService${deviceId} ${i}`);
897
- this.scheduleControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
898
- this.scheduleControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName2} Control`);
899
- this.scheduleControlSensorService.getCharacteristic(characteristicType)
900
- .onGet(async () => {
901
- const state = this.accessory.scheduleEnabled;
902
- return state;
903
- })
904
- accessory.addService(this.scheduleControlSensorService);
897
+ if (schedule.displayType < 7) {
898
+ if (this.logDebug) this.emit('debug', `Prepare schedule control sensor ${name} service`);
899
+ this.scheduleControlSensorService = new serviceType(`${serviceName2} Control`, `scheduleControlSensorService${deviceId} ${i}`);
900
+ this.scheduleControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
901
+ this.scheduleControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName2} Control`);
902
+ this.scheduleControlSensorService.getCharacteristic(characteristicType)
903
+ .onGet(async () => {
904
+ const state = this.accessory.scheduleEnabled;
905
+ return state;
906
+ })
907
+ accessory.addService(this.scheduleControlSensorService);
908
+ }
905
909
  }
906
910
 
907
911
  //sensors
908
- if (this.logDebug) this.emit('debug', `Prepare schedule sensor ${name} service`);
909
- const scheduleSensorService = new serviceType(serviceName1, `scheduleSensorService${deviceId} ${i}`);
910
- scheduleSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
911
- scheduleSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
912
- scheduleSensorService.getCharacteristic(characteristicType)
913
- .onGet(async () => {
914
- const state = schedule.state;
915
- return state;
916
- });
917
- this.scheduleSensorServices.push(scheduleSensorService);
918
- accessory.addService(scheduleSensorService);
912
+ if (schedule.displayType < 7) {
913
+ if (this.logDebug) this.emit('debug', `Prepare schedule sensor ${name} service`);
914
+ const scheduleSensorService = new serviceType(serviceName1, `scheduleSensorService${deviceId} ${i}`);
915
+ scheduleSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
916
+ scheduleSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
917
+ scheduleSensorService.getCharacteristic(characteristicType)
918
+ .onGet(async () => {
919
+ const state = schedule.state;
920
+ return state;
921
+ });
922
+ this.scheduleSensorServices.push(scheduleSensorService);
923
+ accessory.addService(scheduleSensorService);
924
+ }
919
925
  });
920
926
  };
921
927
 
@@ -961,17 +967,20 @@ class DeviceErv extends EventEmitter {
961
967
  accessory.addService(sceneControlService);
962
968
  }
963
969
 
964
- if (this.logDebug) this.emit('debug', `Prepare scene control sensor ${name} service`);
965
- const sceneControlSensorService = new serviceType(`${serviceName1} Control`, `sceneControlSensorService${deviceId} ${i}`);
966
- sceneControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
967
- sceneControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName1} Control`);
968
- sceneControlSensorService.getCharacteristic(characteristicType)
969
- .onGet(async () => {
970
- const state = scene.state;
971
- return state;
972
- })
973
- this.sceneControlSensorServices.push(sceneControlSensorService);
974
- accessory.addService(sceneControlSensorService);
970
+ //sensor
971
+ if (scene.displayType < 7) {
972
+ if (this.logDebug) this.emit('debug', `Prepare scene control sensor ${name} service`);
973
+ const sceneControlSensorService = new serviceType(`${serviceName1} Control`, `sceneControlSensorService${deviceId} ${i}`);
974
+ sceneControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
975
+ sceneControlSensorService.setCharacteristic(Characteristic.ConfiguredName, `${serviceName1} Control`);
976
+ sceneControlSensorService.getCharacteristic(characteristicType)
977
+ .onGet(async () => {
978
+ const state = scene.state;
979
+ return state;
980
+ })
981
+ this.sceneControlSensorServices.push(sceneControlSensorService);
982
+ accessory.addService(sceneControlSensorService);
983
+ }
975
984
  });
976
985
  };
977
986
 
@@ -1095,17 +1104,19 @@ class DeviceErv extends EventEmitter {
1095
1104
  }
1096
1105
 
1097
1106
  //sensor
1098
- if (this.logDebug) this.emit('debug', `Prepare button control sensor ${name} service`);
1099
- const buttonControlSensorService = new serviceType(serviceName1, `buttonControlSensorService${deviceId} ${i}`);
1100
- buttonControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1101
- buttonControlSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
1102
- buttonControlSensorService.getCharacteristic(characteristicType)
1103
- .onGet(async () => {
1104
- const state = button.state;
1105
- return state;
1106
- })
1107
- this.buttonControlSensorServices.push(buttonControlSensorService);
1108
- accessory.addService(buttonControlSensorService);
1107
+ if (button.displayType < 7) {
1108
+ if (this.logDebug) this.emit('debug', `Prepare button control sensor ${name} service`);
1109
+ const buttonControlSensorService = new serviceType(serviceName1, `buttonControlSensorService${deviceId} ${i}`);
1110
+ buttonControlSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1111
+ buttonControlSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
1112
+ buttonControlSensorService.getCharacteristic(characteristicType)
1113
+ .onGet(async () => {
1114
+ const state = button.state;
1115
+ return state;
1116
+ })
1117
+ this.buttonControlSensorServices.push(buttonControlSensorService);
1118
+ accessory.addService(buttonControlSensorService);
1119
+ }
1109
1120
  });
1110
1121
  };
1111
1122
 
@@ -1122,7 +1133,7 @@ class DeviceErv extends EventEmitter {
1122
1133
  this.melCloudErv = new MelCloudErv(this.account, this.device, this.devicesFile, this.defaultTempsFile, this.accountFile)
1123
1134
  .on('deviceInfo', (modelIndoor, modelOutdoor, serialNumber, firmwareAppVersion) => {
1124
1135
  if (this.logDeviceInfo && this.displayDeviceInfo) {
1125
- this.emit('devInfo', `---- ${this.deviceTypeText}: ${this.deviceName} ----`);
1136
+ this.emit('devInfo', `---- ${this.deviceTypeString}: ${this.deviceName} ----`);
1126
1137
  this.emit('devInfo', `Account: ${this.accountName}`);
1127
1138
  if (modelIndoor) this.emit('devInfo', `Indoor: ${modelIndoor}`);
1128
1139
  if (modelOutdoor) this.emit('devInfo', `Outdoor: ${modelOutdoor}`);
@@ -1135,7 +1146,7 @@ class DeviceErv extends EventEmitter {
1135
1146
 
1136
1147
  //accessory info
1137
1148
  this.manufacturer = 'Mitsubishi';
1138
- this.model = modelIndoor ? modelIndoor : modelOutdoor ? modelOutdoor : `${this.deviceTypeText} ${this.deviceId}`;
1149
+ this.model = modelIndoor ? modelIndoor : modelOutdoor ? modelOutdoor : `${this.deviceTypeString} ${this.deviceId}`;
1139
1150
  this.serialNumber = serialNumber.toString();
1140
1151
  this.firmwareRevision = firmwareAppVersion.toString();
1141
1152
 
@@ -1436,12 +1447,10 @@ class DeviceErv extends EventEmitter {
1436
1447
  && presetData.SetFanSpeed === setFanSpeed) : false;
1437
1448
 
1438
1449
  //control
1439
- if (preset.displayType > 3) {
1440
- this.presetControlServices?.[i]?.updateCharacteristic(Characteristic.On, preset.state);
1441
- }
1450
+ if (preset.displayType > 3) this.presetControlServices?.[i]?.updateCharacteristic(Characteristic.On, preset.state);
1442
1451
 
1443
1452
  //sencor
1444
- this.presetControlSensorServices?.[i]?.updateCharacteristic(characteristicType, preset.state);
1453
+ if (preset.displayType < 7) this.presetControlSensorServices?.[i]?.updateCharacteristic(characteristicType, preset.state);
1445
1454
  });
1446
1455
  };
1447
1456
 
@@ -1454,38 +1463,35 @@ class DeviceErv extends EventEmitter {
1454
1463
 
1455
1464
  //control
1456
1465
  if (i === 0) {
1457
- if (schedule.displayType > 3) {
1458
- this.scheduleControlService?.updateCharacteristic(Characteristic.On, scheduleEnabled);
1459
- }
1460
- this.scheduleControlSensorService?.updateCharacteristic(characteristicType, scheduleEnabled);
1466
+ if (schedule.displayType > 3) this.scheduleControlService?.updateCharacteristic(Characteristic.On, scheduleEnabled);
1467
+ if (schedule.displayType < 7) this.scheduleControlSensorService?.updateCharacteristic(characteristicType, scheduleEnabled);
1461
1468
  }
1462
1469
 
1463
1470
  //sensor
1464
- this.scheduleSensorServices?.[i]?.updateCharacteristic(characteristicType, schedule.state);
1471
+ if (schedule.displayType < 7) this.scheduleSensorServices?.[i]?.updateCharacteristic(characteristicType, schedule.state);
1465
1472
  });
1466
1473
  };
1467
1474
 
1468
- //schedules
1475
+ //scenes
1469
1476
  if (this.scenes.length > 0) {
1470
1477
  this.scenes.forEach((scene, i) => {
1471
1478
  const sceneData = scenesOnServer.find(s => s.Id === scene.id);
1479
+ const characteristicType = scene.characteristicType;
1472
1480
  scene.state = sceneData.Enabled;
1473
1481
 
1474
1482
  //control
1475
- if (scene.displayType > 3) {
1476
- this.sceneControlServices?.[i]?.updateCharacteristic(Characteristic.On, scene.state);
1477
- }
1483
+ if (scene.displayType > 3) this.sceneControlServices?.[i]?.updateCharacteristic(Characteristic.On, scene.state);
1478
1484
 
1479
1485
  //sensor
1480
- const characteristicType = scene.characteristicType;
1481
- this.sceneControlSensorServices?.[i]?.updateCharacteristic(characteristicType, scene.state);
1486
+ if (scene.displayType < 7) this.sceneControlSensorServices?.[i]?.updateCharacteristic(characteristicType, scene.state);
1482
1487
  });
1483
1488
  };
1484
1489
 
1485
1490
  //buttons
1486
1491
  if (this.buttons.length > 0) {
1487
1492
  this.buttons.forEach((button, i) => {
1488
- const mode = button.mode;;
1493
+ const characteristicType = button.characteristicType;
1494
+ const mode = button.mode;
1489
1495
  switch (mode) {
1490
1496
  case 0: //POWER ON,OFF
1491
1497
  button.state = (power === true);
@@ -1535,13 +1541,10 @@ class DeviceErv extends EventEmitter {
1535
1541
  };
1536
1542
 
1537
1543
  //control
1538
- if (button.displayType > 3) {
1539
- this.buttonControlServices?.[i]?.updateCharacteristic(Characteristic.On, button.state);
1540
- }
1544
+ if (button.displayType > 3) this.buttonControlServices?.[i]?.updateCharacteristic(Characteristic.On, button.state);
1541
1545
 
1542
1546
  //sensor
1543
- const characteristicType = scene.characteristicType;
1544
- this.buttonControlSensorServices?.[i]?.updateCharacteristic(characteristicType, button.state);
1547
+ if (button.displayType < 7) this.buttonControlSensorServices?.[i]?.updateCharacteristic(characteristicType, button.state);
1545
1548
  });
1546
1549
  };
1547
1550