homebridge-melcloud-control 3.9.7 → 3.9.8-beta.0
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/homebridge-ui/server.js +2 -2
- package/package.json +1 -1
- package/src/melcloud.js +27 -45
package/homebridge-ui/server.js
CHANGED
|
@@ -23,8 +23,8 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
23
23
|
const melCloud = new MelCloud(user, passwd, language, accountFile, buildingsFile, devicesFile, false, true);
|
|
24
24
|
|
|
25
25
|
try {
|
|
26
|
-
|
|
27
|
-
const devices = await melCloud.chackDevicesList(
|
|
26
|
+
await melCloud.connect();
|
|
27
|
+
const devices = await melCloud.chackDevicesList();
|
|
28
28
|
return devices;
|
|
29
29
|
} catch (error) {
|
|
30
30
|
throw new Error(`MELCloud error: ${error.message ?? error}.`);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "3.9.
|
|
4
|
+
"version": "3.9.8-beta.0",
|
|
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
|
@@ -29,41 +29,36 @@ class MelCloud extends EventEmitter {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
this.axiosInstance = axios.create({
|
|
33
|
+
baseURL: ApiUrls.BaseURL,
|
|
34
|
+
timeout: 15000,
|
|
35
|
+
withCredentials: true,
|
|
36
|
+
maxContentLength: 100000000,
|
|
37
|
+
maxBodyLength: 1000000000,
|
|
38
|
+
httpsAgent: new Agent({
|
|
39
|
+
keepAlive: false,
|
|
40
|
+
rejectUnauthorized: false
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
|
|
32
44
|
if (!requestConfig) {
|
|
33
|
-
this.impulseGenerator = new ImpulseGenerator()
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
this.impulseGenerator = new ImpulseGenerator()
|
|
46
|
+
.on('checkDevicesList', async () => {
|
|
47
|
+
try {
|
|
48
|
+
await this.chackDevicesList(this.contextKey);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
this.emit('error', `Impulse generator error: ${error}`);
|
|
51
|
+
};
|
|
52
|
+
}).on('state', (state) => {
|
|
53
|
+
this.emit('success', `Impulse generator ${state ? 'started' : 'stopped'}.`);
|
|
54
|
+
});
|
|
43
55
|
};
|
|
44
56
|
};
|
|
45
57
|
|
|
46
|
-
async chackDevicesList(
|
|
58
|
+
async chackDevicesList() {
|
|
47
59
|
try {
|
|
48
|
-
//create axios instance get
|
|
49
|
-
const axiosInstanceGet = axios.create({
|
|
50
|
-
method: 'GET',
|
|
51
|
-
baseURL: ApiUrls.BaseURL,
|
|
52
|
-
timeout: 10000,
|
|
53
|
-
headers: {
|
|
54
|
-
'X-MitsContextKey': contextKey
|
|
55
|
-
},
|
|
56
|
-
maxContentLength: 100000000,
|
|
57
|
-
maxBodyLength: 1000000000,
|
|
58
|
-
withCredentials: true,
|
|
59
|
-
httpsAgent: new Agent({
|
|
60
|
-
keepAlive: false,
|
|
61
|
-
rejectUnauthorized: false
|
|
62
|
-
})
|
|
63
|
-
});
|
|
64
|
-
|
|
65
60
|
if (this.enableDebugMode) this.emit('debug', `Scanning for devices`);
|
|
66
|
-
const listDevicesData = await
|
|
61
|
+
const listDevicesData = await this.axiosInstance.get(ApiUrls.ListDevices);
|
|
67
62
|
const buildingsList = listDevicesData.data;
|
|
68
63
|
if (this.enableDebugMode) this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`);
|
|
69
64
|
|
|
@@ -112,19 +107,7 @@ class MelCloud extends EventEmitter {
|
|
|
112
107
|
if (this.enableDebugMode) this.emit('debug', `Connecting to MELCloud`);
|
|
113
108
|
|
|
114
109
|
try {
|
|
115
|
-
const
|
|
116
|
-
method: 'POST',
|
|
117
|
-
baseURL: ApiUrls.BaseURL,
|
|
118
|
-
timeout: 10000,
|
|
119
|
-
withCredentials: true,
|
|
120
|
-
maxContentLength: 100000000,
|
|
121
|
-
maxBodyLength: 1000000000,
|
|
122
|
-
httpsAgent: new Agent({
|
|
123
|
-
keepAlive: false,
|
|
124
|
-
rejectUnauthorized: false
|
|
125
|
-
})
|
|
126
|
-
});
|
|
127
|
-
const accountData = await axiosInstanceLogin(ApiUrls.ClientLogin, this.options);
|
|
110
|
+
const accountData = await this.axiosInstance.post(ApiUrls.ClientLogin, this.options);
|
|
128
111
|
const account = accountData.data;
|
|
129
112
|
const accountInfo = account.LoginData;
|
|
130
113
|
const contextKey = accountInfo.ContextKey;
|
|
@@ -149,8 +132,7 @@ class MelCloud extends EventEmitter {
|
|
|
149
132
|
};
|
|
150
133
|
|
|
151
134
|
//create axios instance post
|
|
152
|
-
this.
|
|
153
|
-
method: 'POST',
|
|
135
|
+
this.axiosInstance = axios.create({
|
|
154
136
|
baseURL: ApiUrls.BaseURL,
|
|
155
137
|
timeout: 10000,
|
|
156
138
|
headers: {
|
|
@@ -190,7 +172,7 @@ class MelCloud extends EventEmitter {
|
|
|
190
172
|
data: accountInfo
|
|
191
173
|
};
|
|
192
174
|
|
|
193
|
-
await this.
|
|
175
|
+
await this.axiosInstance.post(ApiUrls.UpdateApplicationOptions, options);
|
|
194
176
|
await this.functions.saveData(this.accountFile, accountInfo);
|
|
195
177
|
return true;
|
|
196
178
|
} catch (error) {
|