homebridge-melcloud-control 4.3.11-beta.24 → 4.3.11-beta.25

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.3.11-beta.24",
4
+ "version": "4.3.11-beta.25",
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
@@ -56,7 +56,7 @@ class MelCloud extends EventEmitter {
56
56
  try {
57
57
  const devicesList = { State: false, Info: null, Devices: [], Scenes: [] }
58
58
  if (this.logDebug) this.emit('debug', `Scanning for devices...`);
59
- const listDevicesData = await this.axiosInstance(ApiUrls.ListDevices, { method: 'GET', });
59
+ const listDevicesData = await this.client(ApiUrls.ListDevices, { method: 'GET', });
60
60
 
61
61
  if (!listDevicesData || !listDevicesData.data) {
62
62
  devicesList.Info = 'Invalid or empty response from MELCloud API'
@@ -165,11 +165,12 @@ class MelCloud extends EventEmitter {
165
165
  this.emit('headers', headers);
166
166
 
167
167
  this.headers = headers;
168
- this.axiosInstance = axios.create({
168
+ this.client = axios.create({
169
169
  baseURL: ApiUrls.BaseURL,
170
170
  timeout: 30000,
171
171
  headers: headers
172
172
  });
173
+ this.emit('client', this.client);
173
174
 
174
175
  accountInfo.State = true;
175
176
  accountInfo.Info = 'Connect Success';
@@ -24,11 +24,14 @@ class MelCloudAta extends EventEmitter {
24
24
 
25
25
  //set default values
26
26
  this.deviceData = {};
27
+ this.client = melcloud.client;
27
28
  this.headers = melcloud.headers;
28
29
 
29
30
  //handle melcloud events
30
31
  let deviceData = null;
31
- melcloud.on('headers', (headers) => {
32
+ melcloud.on('client', (client) => {
33
+ this.client = client;
34
+ }).on('headers', (headers) => {
32
35
  this.headers = headers;
33
36
  }).on('devicesList', async (devicesData) => {
34
37
  try {
@@ -326,11 +329,8 @@ class MelCloudAta extends EventEmitter {
326
329
  headers.Origin = ApiUrlsHome.Origin;
327
330
  if (!this.logDebug) this.emit('debug', `Send data: ${JSON.stringify(payload, null, 2)}`);
328
331
 
329
- await axios(path, {
332
+ await this.client(path, {
330
333
  method: method,
331
- baseURL: ApiUrlsHome.BaseURL,
332
- timeout: 30000,
333
- headers: headers,
334
334
  data: payload
335
335
  });
336
336
 
@@ -85,7 +85,7 @@ class MelCloudHome extends EventEmitter {
85
85
  async checkScenesList() {
86
86
  try {
87
87
  if (this.logDebug) this.emit('debug', `Scanning for scenes`);
88
- const listScenesData = await this.axiosInstance(ApiUrlsHome.GetUserScenes, { method: 'GET', });
88
+ const listScenesData = await this.client(ApiUrlsHome.GetUserScenes, { method: 'GET', });
89
89
 
90
90
  const scenesList = listScenesData.data;
91
91
  if (this.logDebug) this.emit('debug', `Scenes: ${JSON.stringify(scenesList, null, 2)}`);
@@ -117,7 +117,7 @@ class MelCloudHome extends EventEmitter {
117
117
  try {
118
118
  const devicesList = { State: false, Info: null, Devices: [], Scenes: [] }
119
119
  if (this.logDebug) this.emit('debug', `Scanning for devices`);
120
- const listDevicesData = await this.axiosInstance(ApiUrlsHome.GetUserContext, { method: 'GET' });
120
+ const listDevicesData = await this.client(ApiUrlsHome.GetUserContext, { method: 'GET' });
121
121
 
122
122
  const userContext = listDevicesData.data;
123
123
  const buildings = userContext.buildings ?? [];
@@ -422,11 +422,12 @@ class MelCloudHome extends EventEmitter {
422
422
  this.emit('headers', headers);
423
423
 
424
424
  this.headers = headers;
425
- this.axiosInstance = axios.create({
425
+ this.client = axios.create({
426
426
  baseURL: ApiUrlsHome.BaseURL,
427
427
  timeout: 30000,
428
428
  headers: headers
429
429
  })
430
+ this.emit('client', this.client);
430
431
 
431
432
  this.webSocketOptions = {
432
433
  Hash: hash,