homebridge-melcloud-control 2.5.0-beta.17 → 2.5.0-beta.19
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 -50
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 = await melCloud.connect();
|
|
32
|
+
const devices = await 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.19",
|
|
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
|
@@ -39,7 +39,9 @@ class MelCloud extends EventEmitter {
|
|
|
39
39
|
};
|
|
40
40
|
}).on('state', (state) => { });
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
if (!connectForConfig) {
|
|
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
|
|
|
@@ -122,29 +89,49 @@ class MelCloud extends EventEmitter {
|
|
|
122
89
|
await this.saveData(this.accountInfoFile, accountInfo);
|
|
123
90
|
|
|
124
91
|
//return if connect for config
|
|
125
|
-
if (
|
|
92
|
+
if (this.connectForConfig) {
|
|
93
|
+
return contextKey;
|
|
94
|
+
};
|
|
126
95
|
|
|
127
|
-
|
|
128
|
-
|
|
96
|
+
//check devices list
|
|
97
|
+
await this.chackDevicesList(contextKey);
|
|
129
98
|
|
|
130
|
-
|
|
131
|
-
|
|
99
|
+
//emit connect success
|
|
100
|
+
this.emit('success', `Connect to MELCloud Success.`)
|
|
132
101
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
102
|
+
//start impulse generator
|
|
103
|
+
const timers = [{ name: 'checkDevicesList', sampling: this.refreshInterval }];
|
|
104
|
+
this.impulseGenerator.start(timers);
|
|
136
105
|
|
|
137
|
-
|
|
138
|
-
};
|
|
106
|
+
return true;
|
|
139
107
|
} catch (error) {
|
|
140
108
|
this.emit('error', `Connect to MELCloud error: ${error.message ?? error}.`);
|
|
141
109
|
};
|
|
142
110
|
}
|
|
143
111
|
|
|
144
|
-
async chackDevicesList() {
|
|
112
|
+
async chackDevicesList(key) {
|
|
145
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
|
+
|
|
146
133
|
const debug = this.enableDebugMode ? this.emit('debug', `Scanning for devices.`) : false;
|
|
147
|
-
const listDevicesData = await
|
|
134
|
+
const listDevicesData = await axiosInstanceGet(CONSTANTS.ApiUrls.ListDevices);
|
|
148
135
|
const buildingsList = listDevicesData.data;
|
|
149
136
|
const debug1 = this.enableDebugMode ? this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`) : false;
|
|
150
137
|
|
|
@@ -198,7 +185,7 @@ class MelCloud extends EventEmitter {
|
|
|
198
185
|
//prepare device if not in devices array
|
|
199
186
|
if (!this.devicesId.includes(deviceId)) {
|
|
200
187
|
this.devicesId.push(deviceId);
|
|
201
|
-
this.emit('checkDevicesListComplete', this.accountInfo,
|
|
188
|
+
this.emit('checkDevicesListComplete', this.accountInfo, contextKey, deviceInfo);
|
|
202
189
|
}
|
|
203
190
|
};
|
|
204
191
|
|
|
@@ -221,11 +208,29 @@ class MelCloud extends EventEmitter {
|
|
|
221
208
|
|
|
222
209
|
async send(accountInfo) {
|
|
223
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
|
+
|
|
224
229
|
const options = {
|
|
225
230
|
data: accountInfo
|
|
226
231
|
};
|
|
227
232
|
|
|
228
|
-
await
|
|
233
|
+
await axiosInstancePost(CONSTANTS.ApiUrls.UpdateApplicationOptions, options);
|
|
229
234
|
await this.saveData(this.accountInfoFile, accountInfo);
|
|
230
235
|
return true;
|
|
231
236
|
} catch (error) {
|