homebridge-melcloud-control 2.5.0-beta.16 → 2.5.0-beta.18
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 -1
- package/package.json +1 -1
- package/src/melcloud.js +55 -51
package/homebridge-ui/server.js
CHANGED
|
@@ -28,7 +28,8 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
28
28
|
try {
|
|
29
29
|
let data = {};
|
|
30
30
|
const melCloud = new MelCloud(user, passwd, language, accountInfoFile, deviceInfoFile, buildingsFile, enableDebugMode, refreshInterval, true);
|
|
31
|
-
const
|
|
31
|
+
const contextKey = melCloud.connect();
|
|
32
|
+
const devices = melCloud.chackDevicesList(contextKey);
|
|
32
33
|
return data = {
|
|
33
34
|
info: 'Check devices list complete.',
|
|
34
35
|
status: 0,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "2.5.0-beta.
|
|
4
|
+
"version": "2.5.0-beta.18",
|
|
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
|
@@ -30,16 +30,18 @@ class MelCloud extends EventEmitter {
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
if (!connectForConfig) {
|
|
34
|
+
this.impulseGenerator = new ImpulseGenerator();
|
|
35
|
+
this.impulseGenerator.on('checkDevicesList', async () => {
|
|
36
|
+
try {
|
|
37
|
+
await this.chackDevicesList();
|
|
38
|
+
} catch (error) {
|
|
39
|
+
this.emit('error', `Check devices list: ${error}.`);
|
|
40
|
+
};
|
|
41
|
+
}).on('state', (state) => { });
|
|
42
|
+
|
|
43
|
+
this.connect();
|
|
44
|
+
};
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
async connect() {
|
|
@@ -80,41 +82,6 @@ class MelCloud extends EventEmitter {
|
|
|
80
82
|
return;
|
|
81
83
|
};
|
|
82
84
|
|
|
83
|
-
//create axios instance get
|
|
84
|
-
this.axiosInstanceGet = axios.create({
|
|
85
|
-
method: 'GET',
|
|
86
|
-
baseURL: CONSTANTS.ApiUrls.BaseURL,
|
|
87
|
-
timeout: 5000,
|
|
88
|
-
headers: {
|
|
89
|
-
'X-MitsContextKey': contextKey
|
|
90
|
-
},
|
|
91
|
-
maxContentLength: 100000000,
|
|
92
|
-
maxBodyLength: 1000000000,
|
|
93
|
-
withCredentials: true,
|
|
94
|
-
httpsAgent: new https.Agent({
|
|
95
|
-
keepAlive: false,
|
|
96
|
-
rejectUnauthorized: false
|
|
97
|
-
})
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
//create axios instance post
|
|
101
|
-
this.axiosInstancePost = axios.create({
|
|
102
|
-
method: 'POST',
|
|
103
|
-
baseURL: CONSTANTS.ApiUrls.BaseURL,
|
|
104
|
-
timeout: 5000,
|
|
105
|
-
headers: {
|
|
106
|
-
'X-MitsContextKey': contextKey,
|
|
107
|
-
'content-type': 'application/json'
|
|
108
|
-
},
|
|
109
|
-
maxContentLength: 100000000,
|
|
110
|
-
maxBodyLength: 1000000000,
|
|
111
|
-
withCredentials: true,
|
|
112
|
-
httpsAgent: new https.Agent({
|
|
113
|
-
keepAlive: false,
|
|
114
|
-
rejectUnauthorized: false
|
|
115
|
-
})
|
|
116
|
-
});
|
|
117
|
-
|
|
118
85
|
this.accountInfo = accountInfo;
|
|
119
86
|
this.contextKey = contextKey;
|
|
120
87
|
|
|
@@ -123,11 +90,11 @@ class MelCloud extends EventEmitter {
|
|
|
123
90
|
|
|
124
91
|
//return if connect for config
|
|
125
92
|
if (this.connectForConfig) {
|
|
126
|
-
return;
|
|
93
|
+
return contextKey;
|
|
127
94
|
};
|
|
128
95
|
|
|
129
96
|
//check devices list
|
|
130
|
-
await this.chackDevicesList();
|
|
97
|
+
await this.chackDevicesList(contextKey);
|
|
131
98
|
|
|
132
99
|
//emit connect success
|
|
133
100
|
this.emit('success', `Connect to MELCloud Success.`)
|
|
@@ -142,10 +109,29 @@ class MelCloud extends EventEmitter {
|
|
|
142
109
|
};
|
|
143
110
|
}
|
|
144
111
|
|
|
145
|
-
async chackDevicesList() {
|
|
112
|
+
async chackDevicesList(key) {
|
|
146
113
|
try {
|
|
114
|
+
const contextKey = this.contextKey ?? key;
|
|
115
|
+
|
|
116
|
+
//create axios instance get
|
|
117
|
+
const axiosInstanceGet = axios.create({
|
|
118
|
+
method: 'GET',
|
|
119
|
+
baseURL: CONSTANTS.ApiUrls.BaseURL,
|
|
120
|
+
timeout: 5000,
|
|
121
|
+
headers: {
|
|
122
|
+
'X-MitsContextKey': contextKey
|
|
123
|
+
},
|
|
124
|
+
maxContentLength: 100000000,
|
|
125
|
+
maxBodyLength: 1000000000,
|
|
126
|
+
withCredentials: true,
|
|
127
|
+
httpsAgent: new https.Agent({
|
|
128
|
+
keepAlive: false,
|
|
129
|
+
rejectUnauthorized: false
|
|
130
|
+
})
|
|
131
|
+
});
|
|
132
|
+
|
|
147
133
|
const debug = this.enableDebugMode ? this.emit('debug', `Scanning for devices.`) : false;
|
|
148
|
-
const listDevicesData = await
|
|
134
|
+
const listDevicesData = await axiosInstanceGet(CONSTANTS.ApiUrls.ListDevices);
|
|
149
135
|
const buildingsList = listDevicesData.data;
|
|
150
136
|
const debug1 = this.enableDebugMode ? this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`) : false;
|
|
151
137
|
|
|
@@ -199,7 +185,7 @@ class MelCloud extends EventEmitter {
|
|
|
199
185
|
//prepare device if not in devices array
|
|
200
186
|
if (!this.devicesId.includes(deviceId)) {
|
|
201
187
|
this.devicesId.push(deviceId);
|
|
202
|
-
this.emit('checkDevicesListComplete', this.accountInfo,
|
|
188
|
+
this.emit('checkDevicesListComplete', this.accountInfo, contextKey, deviceInfo);
|
|
203
189
|
}
|
|
204
190
|
};
|
|
205
191
|
|
|
@@ -222,11 +208,29 @@ class MelCloud extends EventEmitter {
|
|
|
222
208
|
|
|
223
209
|
async send(accountInfo) {
|
|
224
210
|
try {
|
|
211
|
+
//create axios instance post
|
|
212
|
+
const axiosInstancePost = axios.create({
|
|
213
|
+
method: 'POST',
|
|
214
|
+
baseURL: CONSTANTS.ApiUrls.BaseURL,
|
|
215
|
+
timeout: 5000,
|
|
216
|
+
headers: {
|
|
217
|
+
'X-MitsContextKey': this.contextKey,
|
|
218
|
+
'content-type': 'application/json'
|
|
219
|
+
},
|
|
220
|
+
maxContentLength: 100000000,
|
|
221
|
+
maxBodyLength: 1000000000,
|
|
222
|
+
withCredentials: true,
|
|
223
|
+
httpsAgent: new https.Agent({
|
|
224
|
+
keepAlive: false,
|
|
225
|
+
rejectUnauthorized: false
|
|
226
|
+
})
|
|
227
|
+
});
|
|
228
|
+
|
|
225
229
|
const options = {
|
|
226
230
|
data: accountInfo
|
|
227
231
|
};
|
|
228
232
|
|
|
229
|
-
await
|
|
233
|
+
await axiosInstancePost(CONSTANTS.ApiUrls.UpdateApplicationOptions, options);
|
|
230
234
|
await this.saveData(this.accountInfoFile, accountInfo);
|
|
231
235
|
return true;
|
|
232
236
|
} catch (error) {
|