homebridge-melcloud-control 4.0.0-beta.363 → 4.0.0-beta.365

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.0.0-beta.363",
4
+ "version": "4.0.0-beta.365",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -3,8 +3,8 @@ import crypto from 'crypto';
3
3
  import { wrapper } from 'axios-cookiejar-support';
4
4
  import { CookieJar } from 'tough-cookie';
5
5
  import { JSDOM } from 'jsdom';
6
- import QueryString from 'querystring';
7
6
  import EventEmitter from 'events';
7
+ import { ApiUrls, ApiUrlsHome } from './constants.js';
8
8
 
9
9
  const MOBILE_USER_AGENT = 'MonitorAndControl.App.Mobile/35 CFNetwork/3860.100.1 Darwin/25.0.0';
10
10
  const CLIENT_ID = 'homemobile';
@@ -157,7 +157,7 @@ class MelCloudHomeToken extends EventEmitter {
157
157
  const redirectUrl = response.headers.location;
158
158
  if (this.logWarn) this.emit('warn', `Redirect URL: ${redirectUrl}`);
159
159
 
160
- const getResp = await this.client.get('https://melcloudhome.com/dashboard', {
160
+ const getResp = await this.client.get('https://melcloudhome.com/ws/token', {
161
161
  headers: {
162
162
  'Accept': 'text/html',
163
163
  },
@@ -166,6 +166,26 @@ class MelCloudHomeToken extends EventEmitter {
166
166
 
167
167
  if (this.logWarn) this.emit('warn', `Redirect URL found code: ${getResp.data}, ${getResp.headers}`);
168
168
 
169
+ const listDevicesData = await this.client.get(ApiUrlsHome.GetUserContext, {
170
+ method: 'GET',
171
+ baseURL: ApiUrlsHome.BaseURL,
172
+ timeout: 25000,
173
+ headers: {
174
+ 'Accept': '*/*',
175
+ 'Accept-Language': 'en-US,en;q=0.9',
176
+ 'User-Agent': 'homebridge-melcloud-control/4.0.0',
177
+ 'DNT': '1',
178
+ 'Origin': 'https://melcloudhome.com',
179
+ 'Referer': 'https://melcloudhome.com/dashboard',
180
+ 'Sec-Fetch-Dest': 'empty',
181
+ 'Sec-Fetch-Mode': 'cors',
182
+ 'Sec-Fetch-Site': 'same-origin',
183
+ 'X-CSRF': '1'
184
+ }
185
+ });
186
+ const buildingsList = listDevicesData.data.buildings;
187
+ if (this.logDebug) this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`);
188
+
169
189
  const match = redirectUrl.match(/[?&]code=([^&]+)/);
170
190
  if (match) {
171
191
  const code = match[1];