homebridge-melcloud-control 4.3.11-beta.23 → 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.23",
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
 
@@ -5,7 +5,6 @@ import { exec } from 'child_process';
5
5
  import { promisify } from 'util';
6
6
  import EventEmitter from 'events';
7
7
  import puppeteer from 'puppeteer';
8
- import MELCloudHomeAuth from "./melcloudhomeauth.js";
9
8
  import ImpulseGenerator from './impulsegenerator.js';
10
9
  import Functions from './functions.js';
11
10
  import { ApiUrlsHome, LanguageLocaleMap } from './constants.js';
@@ -86,7 +85,7 @@ class MelCloudHome extends EventEmitter {
86
85
  async checkScenesList() {
87
86
  try {
88
87
  if (this.logDebug) this.emit('debug', `Scanning for scenes`);
89
- const listScenesData = await this.axiosInstance(ApiUrlsHome.GetUserScenes, { method: 'GET', });
88
+ const listScenesData = await this.client(ApiUrlsHome.GetUserScenes, { method: 'GET', });
90
89
 
91
90
  const scenesList = listScenesData.data;
92
91
  if (this.logDebug) this.emit('debug', `Scenes: ${JSON.stringify(scenesList, null, 2)}`);
@@ -118,7 +117,7 @@ class MelCloudHome extends EventEmitter {
118
117
  try {
119
118
  const devicesList = { State: false, Info: null, Devices: [], Scenes: [] }
120
119
  if (this.logDebug) this.emit('debug', `Scanning for devices`);
121
- const listDevicesData = await this.axiosInstance(ApiUrlsHome.GetUserContext, { method: 'GET' });
120
+ const listDevicesData = await this.client(ApiUrlsHome.GetUserContext, { method: 'GET' });
122
121
 
123
122
  const userContext = listDevicesData.data;
124
123
  const buildings = userContext.buildings ?? [];
@@ -423,11 +422,12 @@ class MelCloudHome extends EventEmitter {
423
422
  this.emit('headers', headers);
424
423
 
425
424
  this.headers = headers;
426
- this.axiosInstance = axios.create({
425
+ this.client = axios.create({
427
426
  baseURL: ApiUrlsHome.BaseURL,
428
427
  timeout: 30000,
429
428
  headers: headers
430
429
  })
430
+ this.emit('client', this.client);
431
431
 
432
432
  this.webSocketOptions = {
433
433
  Hash: hash,