homebridge-melcloud-control 4.2.5-beta.0 → 4.2.5-beta.11

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.
@@ -23,7 +23,6 @@ class MelCloudAtw extends EventEmitter {
23
23
 
24
24
  //set default values
25
25
  this.devicesData = {};
26
- this.headers = {};
27
26
 
28
27
  //lock flags
29
28
  this.locks = true;
@@ -53,12 +52,15 @@ class MelCloudAtw extends EventEmitter {
53
52
  try {
54
53
  //read device info from file
55
54
  const devicesData = await this.functions.readData(this.devicesFile, true);
56
- this.headers = devicesData.Headers;
57
- const scenes = devicesData.Scenes ?? [];
58
- const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
55
+ this.axiosInstance = axios.create({
56
+ baseURL: this.baseURL,
57
+ timeout: 30000,
58
+ headers: devicesData.Headers
59
+ });
59
60
 
61
+ const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
60
62
  if (this.accountType === 'melcloudhome') {
61
- deviceData.Scenes = scenes;
63
+ deviceData.Scenes = devicesData.Scenes ?? [];
62
64
  }
63
65
 
64
66
  const safeConfig = {
@@ -169,13 +171,7 @@ class MelCloudAtw extends EventEmitter {
169
171
  }
170
172
 
171
173
  if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}`);
172
- await axios(ApiUrls.SetAtw, {
173
- method: 'POST',
174
- baseURL: ApiUrls.BaseURL,
175
- timeout: 10000,
176
- headers: this.headers,
177
- data: payload
178
- });
174
+ await this.axiosInstance(path, { method: 'POST', data: payload });
179
175
  this.updateData(deviceData);
180
176
  return true;
181
177
  case "melcloudhome":
@@ -221,20 +217,14 @@ class MelCloudAtw extends EventEmitter {
221
217
  };
222
218
  method = 'PUT';
223
219
  path = ApiUrlsHome.PutAtw.replace('deviceid', deviceData.DeviceID);
224
- this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
220
+ this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings;
225
221
  break
226
222
  }
227
223
 
228
224
  this.headers['Content-Type'] = 'application/json; charset=utf-8';
229
225
  this.headers.Origin = ApiUrlsHome.Origin;
230
226
  if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}, Headers: ${JSON.stringify(this.headers, null, 2)}`);
231
- await axios(path, {
232
- method: method,
233
- baseURL: ApiUrlsHome.BaseURL,
234
- timeout: 10000,
235
- headers: this.headers,
236
- data: payload
237
- });
227
+ await this.axiosInstance(path, { method: method, data: payload });
238
228
  this.updateData(deviceData);
239
229
  return true;
240
230
  default:
@@ -23,7 +23,6 @@ class MelCloudErv extends EventEmitter {
23
23
 
24
24
  //set default values
25
25
  this.devicesData = {};
26
- this.headers = {};
27
26
 
28
27
  //lock flags
29
28
  this.locks = true;
@@ -53,12 +52,15 @@ class MelCloudErv extends EventEmitter {
53
52
  try {
54
53
  //read device info from file
55
54
  const devicesData = await this.functions.readData(this.devicesFile, true);
56
- this.headers = devicesData.Headers;
57
- const scenes = devicesData.Scenes ?? [];
58
- const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
55
+ this.axiosInstance = axios.create({
56
+ baseURL: this.baseURL,
57
+ timeout: 30000,
58
+ headers: devicesData.Headers
59
+ });
59
60
 
61
+ const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
60
62
  if (this.accountType === 'melcloudhome') {
61
- deviceData.Scenes = scenes;
63
+ deviceData.Scenes = devicesData.Scenes ?? [];
62
64
 
63
65
  //read default temps
64
66
  const temps = await this.functions.readData(this.defaultTempsFile, true);
@@ -172,13 +174,7 @@ class MelCloudErv extends EventEmitter {
172
174
  }
173
175
 
174
176
  if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}`);
175
- await axios(ApiUrls.SetErv, {
176
- method: 'POST',
177
- baseURL: ApiUrls.BaseURL,
178
- timeout: 10000,
179
- headers: this.headers,
180
- data: payload
181
- });
177
+ await this.axiosInstance(path, { method: 'POST', data: payload });
182
178
  this.updateData(deviceData);
183
179
  return true;
184
180
  case "melcloudhome":
@@ -228,20 +224,14 @@ class MelCloudErv extends EventEmitter {
228
224
  };
229
225
  method = 'PUT';
230
226
  path = ApiUrlsHome.PutErv.replace('deviceid', deviceData.DeviceID);
231
- this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
227
+ this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings;
232
228
  break
233
229
  }
234
230
 
235
231
  this.headers['Content-Type'] = 'application/json; charset=utf-8';
236
232
  this.headers.Origin = ApiUrlsHome.Origin;
237
233
  if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}, Headers: ${JSON.stringify(this.headers, null, 2)}`);
238
- await axios(path, {
239
- method: method,
240
- baseURL: ApiUrlsHome.BaseURL,
241
- timeout: 10000,
242
- headers: this.headers,
243
- data: payload
244
- });
234
+ await this.axiosInstance(path, { method: method, data: payload });
245
235
  this.updateData(deviceData);
246
236
  return true;
247
237
  default:
@@ -65,12 +65,7 @@ class MelCloud extends EventEmitter {
65
65
  async checkScenesList() {
66
66
  try {
67
67
  if (this.logDebug) this.emit('debug', `Scanning for scenes`);
68
- const listScenesData = await axios(ApiUrlsHome.GetUserScenes, {
69
- method: 'GET',
70
- baseURL: ApiUrlsHome.BaseURL,
71
- timeout: 25000,
72
- headers: this.headers
73
- });
68
+ const listScenesData = await this.axiosInstance(ApiUrlsHome.GetUserScenes, { method: 'GET', });
74
69
 
75
70
  const scenesList = listScenesData.data;
76
71
  if (this.logDebug) this.emit('debug', `Scenes: ${JSON.stringify(scenesList, null, 2)}`);
@@ -102,12 +97,7 @@ class MelCloud extends EventEmitter {
102
97
  try {
103
98
  const devicesList = { State: false, Info: null, Devices: [], Scenes: [] }
104
99
  if (this.logDebug) this.emit('debug', `Scanning for devices`);
105
- const listDevicesData = await axios(ApiUrlsHome.GetUserContext, {
106
- method: 'GET',
107
- baseURL: ApiUrlsHome.BaseURL,
108
- timeout: 25000,
109
- headers: this.headers
110
- });
100
+ const listDevicesData = await this.axiosInstance(ApiUrlsHome.GetUserContext, { method: 'GET' });
111
101
 
112
102
  const userContext = listDevicesData.data;
113
103
  const buildings = userContext.buildings ?? [];
@@ -330,7 +320,7 @@ class MelCloud extends EventEmitter {
330
320
  return accountInfo;
331
321
  }
332
322
  await Promise.race([Promise.all([submitButton.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: GLOBAL_TIMEOUT / 4 })]), new Promise(r => setTimeout(r, GLOBAL_TIMEOUT / 3))]);
333
-
323
+ this.emit('warn', `Cookies: ${JSON.stringify(await browser.cookies())}`);
334
324
  // Extract cookies
335
325
  let c1 = null, c2 = null;
336
326
  const start = Date.now();
@@ -352,7 +342,8 @@ class MelCloud extends EventEmitter {
352
342
  `__Secure-monitorandcontrolC2=${c2}`
353
343
  ].join('; ');
354
344
 
355
- this.headers = {
345
+ const userAgent = await page.evaluate(() => navigator.userAgent);
346
+ const headers = {
356
347
  'Accept': '*/*',
357
348
  'Accept-Encoding': 'gzip, deflate, br',
358
349
  'Accept-Language': LanguageLocaleMap[this.language],
@@ -362,12 +353,18 @@ class MelCloud extends EventEmitter {
362
353
  'Sec-Fetch-Dest': 'empty',
363
354
  'Sec-Fetch-Mode': 'cors',
364
355
  'Sec-Fetch-Site': 'same-origin',
356
+ 'User-Agent': userAgent,
365
357
  'x-csrf': '1'
366
358
  };
359
+ this.headers = headers;
360
+ this.axiosInstance = axios.create({
361
+ baseURL: ApiUrlsHome.BaseURL,
362
+ timeout: 30000,
363
+ headers: headers
364
+ })
367
365
 
368
366
  accountInfo.State = true;
369
367
  accountInfo.Info = 'Connect to MELCloud Home Success';
370
- accountInfo.Headers = this.headers;
371
368
  await this.functions.saveData(this.accountFile, accountInfo);
372
369
 
373
370
  return accountInfo;
@@ -385,13 +382,8 @@ class MelCloud extends EventEmitter {
385
382
 
386
383
  async send(accountInfo) {
387
384
  try {
388
- await axios(ApiUrlsHome.UpdateApplicationOptions, {
389
- method: 'POST',
390
- baseURL: ApiUrlsHome.BaseURL,
391
- timeout: 15000,
392
- headers: accountInfo.Headers
393
- });
394
- await this.functions.saveData(this.accountFile, accountInfo);
385
+ //await this.axiosInstance(ApiUrlsHome.UpdateApplicationOptions, { method: 'POST' });
386
+ //await this.functions.saveData(this.accountFile, accountInfo);
395
387
  return true;
396
388
  } catch (error) {
397
389
  throw new Error(`Send data error: ${error.message}`);