homebridge-melcloud-control 4.0.0-beta.33 → 4.0.0-beta.35

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
@@ -90,7 +90,7 @@ class MelCloudPlatform {
90
90
  .on('start', async () => {
91
91
  try {
92
92
  //melcloud account
93
- const melCloud = new MelCloud(user, passwd, language, accountFile, buildingsFile, devicesFile, logLevel.warn, logLevel.debug, false)
93
+ const melCloud = new MelCloud(displayType, user, passwd, language, accountFile, buildingsFile, devicesFile, logLevel.warn, logLevel.debug, false)
94
94
  .on('success', (msg) => logLevel.success && log.success(`${accountName}, ${msg}`))
95
95
  .on('info', (msg) => logLevel.info && log.info(`${accountName}, ${msg}`))
96
96
  .on('debug', (msg) => logLevel.debug && log.info(`${accountName}, debug: ${msg}`))
@@ -100,24 +100,24 @@ class MelCloudPlatform {
100
100
  //connect
101
101
  let response;
102
102
  try {
103
- response = await melCloud.connect(displayType);
103
+ response = 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
109
  const accountInfo = response.accountInfo ?? false;
110
- const contextKey = displayType === 1 ? response.contextKey : response;
110
+ const contextKey = response.contextKey;
111
111
  const useFahrenheit = response.useFahrenheit ?? false;
112
112
 
113
- if (contextKey === false) {
113
+ if (!contextKey) {
114
114
  return;
115
115
  }
116
116
 
117
117
  //check devices list
118
118
  let devicesInMelcloud;
119
119
  try {
120
- devicesInMelcloud = await melCloud.checkDevicesList(displayType, contextKey);
120
+ devicesInMelcloud = await melCloud.checkDevicesList(contextKey);
121
121
  return
122
122
  } catch (error) {
123
123
  if (logLevel.error) log.error(`${accountName}, Check devices list error: ${error.message ?? error}`);
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.33",
4
+ "version": "4.0.0-beta.35",
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
@@ -7,8 +7,9 @@ import Functions from './functions.js';
7
7
  import { ApiUrls, ApiUrlsHome } from './constants.js';
8
8
 
9
9
  class MelCloud extends EventEmitter {
10
- constructor(user, passwd, language, accountFile, buildingsFile, devicesFile, logWarn, logDebug, requestConfig) {
10
+ constructor(displayType, user, passwd, language, accountFile, buildingsFile, devicesFile, logWarn, logDebug, requestConfig) {
11
11
  super();
12
+ this.displayType = displayType;
12
13
  this.user = user;
13
14
  this.passwd = passwd;
14
15
  this.language = language;
@@ -162,8 +163,6 @@ class MelCloud extends EventEmitter {
162
163
  }
163
164
 
164
165
  async checkMelcloudHomeDevicesList(cookies) {
165
- if (this.logDebug) this.emit('debug', `Connecting to MELCloud Home`);
166
-
167
166
  try {
168
167
  const c1 = cookies.c1.trim();
169
168
  const c2 = cookies.c2.trim();
@@ -176,7 +175,7 @@ class MelCloud extends EventEmitter {
176
175
 
177
176
  const axiosInstance = axios.create({
178
177
  baseURL: ApiUrlsHome.BaseURL,
179
- timeout: 10000,
178
+ timeout: 20000,
180
179
  httpsAgent: new Agent({
181
180
  keepAlive: false,
182
181
  rejectUnauthorized: false
@@ -276,9 +275,14 @@ class MelCloud extends EventEmitter {
276
275
  return null;
277
276
  }
278
277
 
278
+ const accountInfo = {};
279
+ const contextKey = { c1, c2 };
280
+ const useFahrenheit = false;
281
+ this.contextKey = contextKey;
282
+
279
283
  this.emit('success', `Connect to MELCloud Home Success`);
280
284
 
281
- return { c1, c2 };
285
+ return { accountInfo, contextKey, useFahrenheit };
282
286
  } catch (error) {
283
287
  throw new Error(`Connect to MELCloud Home error: ${error.message}`);
284
288
  } finally {
@@ -286,9 +290,9 @@ class MelCloud extends EventEmitter {
286
290
  }
287
291
  }
288
292
 
289
- async connect(type) {
293
+ async connect() {
290
294
  let response = null;
291
- switch (type) {
295
+ switch (this.displayType) {
292
296
  case 1:
293
297
  response = await this.connectToMelCloud();
294
298
  return response
@@ -300,9 +304,9 @@ class MelCloud extends EventEmitter {
300
304
  }
301
305
  }
302
306
 
303
- async checkDevicesList(type, key) {
307
+ async checkDevicesList(key) {
304
308
  let devices = null;
305
- switch (type) {
309
+ switch (this.displayType) {
306
310
  case 1:
307
311
  devices = await this.checkMelcloudDevicesList(key);
308
312
  return devices