homebridge-melcloud-control 4.0.0-beta.46 → 4.0.0-beta.48

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.
@@ -118,7 +118,7 @@
118
118
 
119
119
  button.addEventListener('click', async () => {
120
120
  for (let j = 0; j < accountsCount; j++) {
121
- document.getElementById(`button${j}`).className = (j === i ? 'btn btn-secondary' : 'btn btn-primary');
121
+ document.getElementById(`button${j}`).className = (j === i ? 'btn btn-primary' : 'btn btn-secondary');
122
122
  }
123
123
 
124
124
  const acc = pluginConfig[0].accounts[i];
@@ -157,7 +157,7 @@
157
157
  configButton.addEventListener('click', () => {
158
158
  configButtonState = !configButtonState;
159
159
  homebridge[configButtonState ? 'showSchemaForm' : 'hideSchemaForm']();
160
- configButton.className = configButtonState ? 'btn btn-secondary' : 'btn btn-primary';
160
+ configButton.className = configButtonState ? 'btn btn-primary' : 'btn btn-secondary';
161
161
  });
162
162
 
163
163
  // Password toggle
@@ -24,8 +24,8 @@ class PluginUiServer extends HomebridgePluginUiServer {
24
24
  const melCloud = new MelCloud(displayType, user, passwd, language, accountFile, buildingsFile, devicesFile, false, true);
25
25
 
26
26
  try {
27
- const response = await melCloud.connect();
28
- const devices = await melCloud.checkDevicesList(response.contextKey);
27
+ const accountInfo = await melCloud.connect();
28
+ const devices = await melCloud.checkDevicesList(accountInfo.contextKey);
29
29
  return devices;
30
30
  } catch (error) {
31
31
  throw new Error(`MELCloud error: ${error.message ?? error}.`);
package/index.js CHANGED
@@ -98,17 +98,16 @@ class MelCloudPlatform {
98
98
  .on('error', (msg) => logLevel.error && log.error(`${accountName}, ${msg}`));
99
99
 
100
100
  //connect
101
- let response;
101
+ let accountInfo;
102
102
  try {
103
- response = await melCloud.connect();
103
+ accountInfo = await melCloud.connect();
104
104
  } catch (error) {
105
105
  if (logLevel.error) log.error(`${accountName}, Connect error: ${error.message ?? error}`);
106
106
  return;
107
107
  }
108
108
 
109
- const accountInfo = response.accountInfo;
110
- const contextKey = response.contextKey;
111
- const useFahrenheit = response.useFahrenheit;
109
+ const contextKey = accountInfo.contextKey;
110
+ const useFahrenheit = accountInfo.useFahrenheit;
112
111
 
113
112
  if (!contextKey) {
114
113
  return;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.0.0-beta.46",
4
+ "version": "4.0.0-beta.48",
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/melcloud.js CHANGED
@@ -123,7 +123,6 @@ class MelCloud extends EventEmitter {
123
123
  const account = accountData.data;
124
124
  const accountInfo = account.LoginData;
125
125
  const contextKey = accountInfo?.ContextKey;
126
- const useFahrenheit = accountInfo?.UseFahrenheit ?? false;
127
126
  this.contextKey = contextKey;
128
127
 
129
128
  const debugData = {
@@ -153,10 +152,9 @@ class MelCloud extends EventEmitter {
153
152
  });
154
153
 
155
154
  await this.functions.saveData(this.accountFile, accountInfo);
156
-
157
155
  this.emit('success', `Connect to MELCloud Success`);
158
156
 
159
- return { accountInfo, contextKey, useFahrenheit };
157
+ return accountInfo
160
158
  } catch (error) {
161
159
  throw new Error(`Connect to MELCloud error: ${error.message}`);
162
160
  }
@@ -196,17 +194,43 @@ class MelCloud extends EventEmitter {
196
194
  await this.functions.saveData(this.buildingsFile, buildingsList);
197
195
  if (this.logDebug) this.emit('debug', `Buildings list saved`);
198
196
 
199
- const devices = buildingsList.flatMap(building => [
200
- ...(building.airToAirUnits || []),
201
- ...(building.airToWaterUnits || [])
197
+ const allDevices = buildingsList.flatMap(building => [
198
+ ...(building.airToAirUnits || []).map(device => ({
199
+ ...Object.fromEntries(
200
+ Object.entries(device).map(([key, value]) => [key.charAt(0).toUpperCase() + key.slice(1), value])
201
+ ),
202
+ Type: 0
203
+ })),
204
+ ...(building.airToWaterUnits || []).map(device => ({
205
+ ...Object.fromEntries(
206
+ Object.entries(device).map(([key, value]) => [key.charAt(0).toUpperCase() + key.slice(1), value])
207
+ ),
208
+ Type: 1
209
+ })),
210
+ ...(building.airToVentilationUnits || []).map(device => ({
211
+ ...Object.fromEntries(
212
+ Object.entries(device).map(([key, value]) => [key.charAt(0).toUpperCase() + key.slice(1), value])
213
+ ),
214
+ Type: 3
215
+ }))
202
216
  ]);
203
217
 
204
- const devicesCount = devices.length;
218
+ const devicesCount = allDevices.length;
205
219
  if (devicesCount === 0) {
206
220
  if (this.logWarn) this.emit('warn', `No devices found`);
207
221
  return null;
208
222
  }
209
223
 
224
+ const devices = [];
225
+ for (const device of allDevices) {
226
+ devices.push({
227
+ DeviceID: device.Id,
228
+ DeviceName: device.GivenDisplayName,
229
+ Settings: Object.fromEntries(device.Settings.map(({ Name, Value }) => [Name, Value])),
230
+ Device: device.Capabilities
231
+ });
232
+ }
233
+
210
234
  await this.functions.saveData(this.devicesFile, devices);
211
235
  if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
212
236
 
@@ -263,14 +287,14 @@ class MelCloud extends EventEmitter {
263
287
  return null;
264
288
  }
265
289
 
266
- const accountInfo = {};
267
290
  const contextKey = ['__Secure-monitorandcontrol=chunks-2', `__Secure-monitorandcontrolC1=${c1}`, `__Secure-monitorandcontrolC2=${c2}`,].join('; ');
268
- const useFahrenheit = false;
291
+ const accountInfo = { ContextKey: contextKey, UseFahrenheit: false };
269
292
  this.contextKey = contextKey;
270
293
 
294
+ await this.functions.saveData(this.accountFile, accountInfo);
271
295
  this.emit('success', `Connect to MELCloud Home Success`);
272
296
 
273
- return { accountInfo, contextKey, useFahrenheit };
297
+ return accountInfo;
274
298
  } catch (error) {
275
299
  throw new Error(`Connect to MELCloud Home error: ${error.message}`);
276
300
  } finally {