homebridge-melcloud-control 4.2.5-beta.4 → 4.2.5-beta.6

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/README.md CHANGED
@@ -272,7 +272,7 @@ Homebridge plugin for Air Conditioner, Heat Pump and Energy Recovery Ventilation
272
272
  | `ataDevices[].buttonsSensors[]` | Array of buttons sensors. |
273
273
  | `ataDevices[].buttonsSensors[].name` | Here set `Button Name` which You want expose to the `Homebridge/HomeKit`. |
274
274
  | `ataDevices[].buttonsSensors[].mode` | Here select button mode, VH - Vane Horizontal, VV - Vane Horizontal. |
275
- | `ataDevices[].buttonsSensors[].displayType` | Here select display type in HomeKit, `0 - None/Disabled`, `1 - Outlet`, `2 - Switch`, `3 - Motion Sensor`, `4 - Occupancy Sensor`, `5 - Contact Sensor`. |
275
+ | `ataDevices[].buttonsSensors[].displayType` | Here select display type in HomeKit, `0 - None/Disabled`, `1 - Motion Sensor`, `2 - Occupancy Sensor`, `3 - Contact Sensor`, `4 - Switch + Motion Sensor`, `5 - Switch +Occupancy Sensor`, `6 - Switch +Contact Sensor`. |
276
276
  | `ataDevices[].buttonsSensors[].namePrefix` | Here enable/disable the accessory name as a prefix for button/sensor name. |
277
277
  | `atwDevices[]` | Array of ATA devices created automatically after login to MELCloud from plugin config UI. |
278
278
  | `atwDevices[].id` | Read only data, do not change it. |
@@ -309,7 +309,7 @@ Homebridge plugin for Air Conditioner, Heat Pump and Energy Recovery Ventilation
309
309
  | `atwDevices[].buttonsSensors[]` | Array of buttons sensors. |
310
310
  | `atwDevices[].buttonsSensors[].name` | Here set `Button Name` which You want expose to the `Homebridge/HomeKit`. |
311
311
  | `atwDevices[].buttonsSensors[].mode` | Here select button mode. |
312
- | `atwDevices[].buttonsSensors[].displayType` | Here select display type in HomeKit, `0 - None/Disabled`, `1 - Outlet`, `2 - Switch`, `3 - Motion Sensor`, `4 - Occupancy Sensor`, `5 - Contact Sensor`. |
312
+ | `atwDevices[].buttonsSensors[].displayType` | Here select display type in HomeKit, `0 - None/Disabled`, `1 - Motion Sensor`, `2 - Occupancy Sensor`, `3 - Contact Sensor`, `4 - Switch + Motion Sensor`, `5 - Switch +Occupancy Sensor`, `6 - Switch +Contact Sensor`. |
313
313
  | `atwDevices[].buttonsSensors[].namePrefix` | Here enable/disable the accessory name as a prefix for button/sensor name. |
314
314
  | `ervDevices[]` | Array of ATA devices created automatically after login to MELCloud from plugin config UI. |
315
315
  | `ervDevices[].id` | Read only data, do not change it. |
@@ -339,7 +339,7 @@ Homebridge plugin for Air Conditioner, Heat Pump and Energy Recovery Ventilation
339
339
  | `ervDevices[].buttonsSensors[]` | Array of buttons sensors. |
340
340
  | `ervDevices[].buttonsSensors[].name` | Here set `Button Name` which You want expose to the `Homebridge/HomeKit`. |
341
341
  | `ervDevices[].buttonsSensors[].mode` | Here select button mode. |
342
- | `ervDevices[].buttonsSensors[].displayType` | Here select display type in HomeKit, `0 - None/Disabled`, `1 - Outlet`, `2 - Switch`, `3 - Motion Sensor`, `4 - Occupancy Sensor`, `5 - Contact Sensor`. |
342
+ | `ervDevices[].buttonsSensors[].displayType` | Here select display type in HomeKit, `0 - None/Disabled`, `1 - Motion Sensor`, `2 - Occupancy Sensor`, `3 - Contact Sensor`, `4 - Switch + Motion Sensor`, `5 - Switch +Occupancy Sensor`, `6 - Switch +Contact Sensor`. |
343
343
  | `ervDevices[].buttonsSensors[].namePrefix` | Here enable/disable the accessory name as a prefix for button/sensor name. |
344
344
  | `refreshInterval` | Here set the background account data refresh time in (sec) , only for old MELCLoud, default `120s`. |
345
345
  | `log{}` | Log object. |
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.2.5-beta.4",
4
+ "version": "4.2.5-beta.6",
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
@@ -57,12 +57,7 @@ class MelCloud extends EventEmitter {
57
57
  try {
58
58
  const devicesList = { State: false, Info: null, Devices: [], Scenes: [] }
59
59
  if (this.logDebug) this.emit('debug', `Scanning for devices...`);
60
- const listDevicesData = await axios(ApiUrls.ListDevices, {
61
- method: 'GET',
62
- baseURL: ApiUrls.BaseURL,
63
- timeout: 15000,
64
- headers: this.headers
65
- });
60
+ const listDevicesData = await this.axiosInstance(ApiUrls.ListDevices, { method: 'GET', });
66
61
 
67
62
  if (!listDevicesData || !listDevicesData.data) {
68
63
  devicesList.Info = 'Invalid or empty response from MELCloud API'
@@ -168,15 +163,20 @@ class MelCloud extends EventEmitter {
168
163
  return accountInfo;
169
164
  }
170
165
 
171
- this.headers = {
166
+ const headers = {
172
167
  'X-MitsContextKey': contextKey,
173
168
  'Content-Type': 'application/json'
174
169
  };
170
+ this.headers = headers;
171
+ this.axiosInstance = axios.create({
172
+ baseURL: ApiUrls.BaseURL,
173
+ timeout: 30000,
174
+ headers: headers
175
+ });
175
176
 
176
177
  accountInfo.State = true;
177
178
  accountInfo.Info = 'Connect to MELCloud Success';
178
179
  accountInfo.LoginData = loginData;
179
- accountInfo.Headers = this.headers;
180
180
  await this.functions.saveData(this.accountFile, accountInfo);
181
181
 
182
182
  return accountInfo
@@ -188,13 +188,7 @@ class MelCloud extends EventEmitter {
188
188
  async send(accountInfo) {
189
189
  try {
190
190
  const payload = { data: accountInfo.LoginData };
191
- await axios(ApiUrls.UpdateApplicationOptions, {
192
- method: 'POST',
193
- baseURL: ApiUrls.BaseURL,
194
- timeout: 15000,
195
- headers: accountInfo.Headers,
196
- data: payload
197
- });
191
+ await this.axiosInstance(ApiUrls.UpdateApplicationOptions, { method: 'POST', data: payload });
198
192
  await this.functions.saveData(this.accountFile, accountInfo);
199
193
  return true;
200
194
  } catch (error) {
@@ -23,7 +23,7 @@ class MelCloudAta extends EventEmitter {
23
23
 
24
24
  //set default values
25
25
  this.deviceData = {};
26
- this.headers = {};
26
+ this.baseURL = this.accountType === 'melcloud' ? ApiUrls.BaseURL : ApiUrlsHome.BaseURL;
27
27
 
28
28
  //lock flag
29
29
  this.locks = true;
@@ -53,12 +53,15 @@ class MelCloudAta extends EventEmitter {
53
53
  try {
54
54
  //read device info from file
55
55
  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);
56
+ this.axiosInstance = axios.create({
57
+ baseURL: this.baseURL,
58
+ timeout: 30000,
59
+ headers: devicesData.Headers,
60
+ });
59
61
 
62
+ const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
60
63
  if (this.accountType === 'melcloudhome') {
61
- deviceData.Scenes = scenes;
64
+ deviceData.Scenes = devicesData.Scenes ?? [];
62
65
  deviceData.Device.OperationMode = AirConditioner.OperationModeMapStringToEnum[deviceData.Device.OperationMode] ?? deviceData.Device.OperationMode;
63
66
  deviceData.Device.ActualFanSpeed = AirConditioner.FanSpeedMapStringToEnum[deviceData.Device.ActualFanSpeed] ?? deviceData.Device.ActualFanSpeed;
64
67
  deviceData.Device.SetFanSpeed = AirConditioner.FanSpeedMapStringToEnum[deviceData.Device.SetFanSpeed] ?? deviceData.Device.SetFanSpeed;
@@ -163,13 +166,7 @@ class MelCloudAta extends EventEmitter {
163
166
  };
164
167
 
165
168
  if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}`);
166
- await axios(ApiUrls.SetAta, {
167
- method: 'POST',
168
- baseURL: ApiUrls.BaseURL,
169
- timeout: 10000,
170
- headers: this.headers,
171
- data: payload
172
- });
169
+ await this.axiosInstance(path, { method: 'POST', data: payload });
173
170
  this.updateData(deviceData);
174
171
  return true;
175
172
  case "melcloudhome":
@@ -244,20 +241,14 @@ class MelCloudAta extends EventEmitter {
244
241
  };
245
242
  method = 'PUT';
246
243
  path = ApiUrlsHome.PutAta.replace('deviceid', deviceData.DeviceID);
247
- this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
244
+ this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings;
248
245
  break
249
246
  }
250
247
 
251
248
  this.headers['Content-Type'] = 'application/json; charset=utf-8';
252
249
  this.headers.Origin = ApiUrlsHome.Origin;
253
250
  if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}, Headers: ${JSON.stringify(this.headers, null, 2)}`);
254
- await axios(path, {
255
- method: method,
256
- baseURL: ApiUrlsHome.BaseURL,
257
- timeout: 10000,
258
- headers: this.headers,
259
- data: payload
260
- });
251
+ await this.axiosInstance(path, { method: method, data: payload });
261
252
  this.updateData(deviceData);
262
253
  return true;
263
254
  default:
@@ -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 ?? [];
@@ -352,7 +342,7 @@ class MelCloud extends EventEmitter {
352
342
  `__Secure-monitorandcontrolC2=${c2}`
353
343
  ].join('; ');
354
344
 
355
- this.headers = {
345
+ const headers = {
356
346
  'Accept': '*/*',
357
347
  'Accept-Encoding': 'gzip, deflate, br',
358
348
  'Accept-Language': LanguageLocaleMap[this.language],
@@ -364,10 +354,15 @@ class MelCloud extends EventEmitter {
364
354
  'Sec-Fetch-Site': 'same-origin',
365
355
  'x-csrf': '1'
366
356
  };
357
+ this.headers = headers;
358
+ this.axiosInstance = axios.create({
359
+ baseURL: ApiUrlsHome.BaseURL,
360
+ timeout: 30000,
361
+ headers: headers
362
+ })
367
363
 
368
364
  accountInfo.State = true;
369
365
  accountInfo.Info = 'Connect to MELCloud Home Success';
370
- accountInfo.Headers = this.headers;
371
366
  await this.functions.saveData(this.accountFile, accountInfo);
372
367
 
373
368
  return accountInfo;
@@ -385,13 +380,8 @@ class MelCloud extends EventEmitter {
385
380
 
386
381
  async send(accountInfo) {
387
382
  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);
383
+ //await this.axiosInstance(ApiUrlsHome.UpdateApplicationOptions, { method: 'POST' });
384
+ //await this.functions.saveData(this.accountFile, accountInfo);
395
385
  return true;
396
386
  } catch (error) {
397
387
  throw new Error(`Send data error: ${error.message}`);