homebridge-melcloud-control 4.3.5-beta.21 → 4.3.5-beta.23

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
@@ -120,18 +120,19 @@ class MelCloudPlatform {
120
120
  if (logLevel.success) log.success(`${accountName}, ${accountInfo.Info}`);
121
121
 
122
122
  //check devices list
123
- let melcloudDevicesList;
123
+ let devicesList;
124
124
  try {
125
- melcloudDevicesList = await melcloud.checkDevicesList();
126
- if (!melcloudDevicesList.State) {
127
- if (logLevel.warn) log.warn(`${accountName}, ${melcloudDevicesList.Info}`);
125
+ devicesList = await melcloud.checkDevicesList();
126
+ if (!devicesList.State) {
127
+ if (logLevel.warn) log.warn(`${accountName}, ${devicesList.Info}`);
128
128
  return;
129
129
  }
130
130
  } catch (error) {
131
131
  if (logLevel.error) log.error(`${accountName}, Check devices list error: ${error.message ?? error}`);
132
132
  return;
133
133
  }
134
- if (logLevel.debug) log.info(melcloudDevicesList.Info);
134
+ if (logLevel.debug) log.info(devicesList.Info);
135
+ const melcloudDevices = devicesList.Devices;
135
136
 
136
137
  //start account impulse generator
137
138
  await melcloud.impulseGenerator.state(true, timmers, false);
@@ -146,7 +147,7 @@ class MelCloudPlatform {
146
147
  for (const [index, device] of devices.entries()) {
147
148
  //chack device from config exist on melcloud
148
149
  const displayType = device.displayType > 0;
149
- const deviceExistInMelCloud = melcloudDevicesList.Devices.some(dev => dev.DeviceID === device.id);
150
+ const deviceExistInMelCloud = melcloudDevices.some(dev => dev.DeviceID === device.id);
150
151
  if (!deviceExistInMelCloud || !displayType) continue;
151
152
 
152
153
  device.id = String(device.id);
@@ -180,15 +181,15 @@ class MelCloudPlatform {
180
181
  let configuredDevice;
181
182
  switch (deviceType) {
182
183
  case 0: //ATA
183
- configuredDevice = new DeviceAta(api, account, device, defaultTempsFile, accountInfo, accountFile, melcloud, melcloudDevicesList);
184
+ configuredDevice = new DeviceAta(api, account, device, defaultTempsFile, accountInfo, accountFile, melcloud, melcloudDevices);
184
185
  break;
185
186
  case 1: //ATW
186
- configuredDevice = new DeviceAtw(api, account, device, defaultTempsFile, accountInfo, accountFile, melcloud, melcloudDevicesList);
187
+ configuredDevice = new DeviceAtw(api, account, device, defaultTempsFile, accountInfo, accountFile, melcloud);
187
188
  break;
188
189
  case 2:
189
190
  break;
190
191
  case 3: //ERV
191
- configuredDevice = new DeviceErv(api, account, device, defaultTempsFile, accountInfo, accountFile, melcloud, melcloudDevicesList);
192
+ configuredDevice = new DeviceErv(api, account, device, defaultTempsFile, accountInfo, accountFile, melcloud);
192
193
  break;
193
194
  default:
194
195
  if (logLevel.warn) log.warn(`${accountName}, ${deviceTypeString}, ${deviceName}, unknown device: ${deviceType}.`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.3.5-beta.21",
4
+ "version": "4.3.5-beta.23",
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
@@ -7,7 +7,7 @@ import { TemperatureDisplayUnits, AirConditioner } from './constants.js';
7
7
  let Accessory, Characteristic, Service, Categories, AccessoryUUID;
8
8
 
9
9
  class DeviceAta extends EventEmitter {
10
- constructor(api, account, device, defaultTempsFile, accountInfo, accountFile, melcloud) {
10
+ constructor(api, account, device, defaultTempsFile, accountInfo, accountFile, melcloud, melcloudDevices) {
11
11
  super();
12
12
 
13
13
  Accessory = api.platformAccessory;
@@ -18,6 +18,7 @@ class DeviceAta extends EventEmitter {
18
18
 
19
19
  //account config
20
20
  this.melcloud = melcloud;
21
+ this.melcloudDevices = melcloudDevices;
21
22
  this.account = account;
22
23
  this.accountType = account.type;
23
24
  this.accountName = account.name;
@@ -1320,7 +1321,7 @@ class DeviceAta extends EventEmitter {
1320
1321
  async start() {
1321
1322
  try {
1322
1323
  //melcloud device
1323
- this.melCloudAta = new MelCloudAta(this.account, this.device, this.defaultTempsFile, this.accountFile, this.melcloud)
1324
+ this.melCloudAta = new MelCloudAta(this.account, this.device, this.defaultTempsFile, this.accountFile, this.melcloud, this.melcloudDevices)
1324
1325
  .on('deviceInfo', (modelIndoor, modelOutdoor, serialNumber, firmwareAppVersion) => {
1325
1326
  if (this.logDeviceInfo && this.displayDeviceInfo) {
1326
1327
  this.emit('devInfo', `---- ${this.deviceTypeString}: ${this.deviceName} ----`);
@@ -4,7 +4,7 @@ import Functions from './functions.js';
4
4
  import { ApiUrls, ApiUrlsHome, AirConditioner } from './constants.js';
5
5
 
6
6
  class MelCloudAta extends EventEmitter {
7
- constructor(account, device, defaultTempsFile, accountFile, melcloud, melcloudDevicesList) {
7
+ constructor(account, device, defaultTempsFile, accountFile, melcloud, melcloudDevices) {
8
8
  super();
9
9
  this.accountType = account.type;
10
10
  this.logSuccess = account.log?.success;
@@ -23,7 +23,7 @@ class MelCloudAta extends EventEmitter {
23
23
 
24
24
  //set default values
25
25
  this.deviceData = {};
26
- this.headers = {};
26
+ this.headers = melcloudDevices.Headers;
27
27
 
28
28
  let deviceData = null;
29
29
  melcloud.on('devicesList', async (devicesData) => {
@@ -32,7 +32,7 @@ class MelCloudAta extends EventEmitter {
32
32
  if (!deviceData) return;
33
33
  deviceData.Scenes = devicesData.Scenes ?? [];
34
34
 
35
- if (!this.logDebug) this.emit('debug', `MELCloud: ${melcloud}`);
35
+ if (!this.logDebug) this.emit('debug', `MELCloud: ${JSON.stringify(melcloudDevices, null, 2)}`);
36
36
 
37
37
  //update state
38
38
  await this.updateState(deviceData);
@@ -93,6 +93,11 @@ class MelCloudAta extends EventEmitter {
93
93
  if (this.logError) this.emit('error', `Web socket process message error: ${error}`);
94
94
  }
95
95
  });
96
+
97
+ //only update state once at the beginning
98
+ const deviceInMelcloud = melcloudDevices.find(device => device.DeviceID === this.deviceId)
99
+ deviceInMelcloud.Scenes = melcloudDevices.Scenes ?? [];
100
+ this.updateState(deviceInMelcloud);
96
101
  }
97
102
 
98
103
  async updateState(deviceData) {