homebridge-melcloud-control 2.5.0-beta.78 → 2.5.0-beta.8
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/config.schema.json +1034 -1043
- package/homebridge-ui/public/index.html +31 -125
- package/homebridge-ui/server.js +47 -11
- package/index.js +113 -123
- package/package.json +1 -1
- package/src/deviceata.js +10 -10
- package/src/deviceatw.js +14 -14
- package/src/deviceerv.js +8 -8
- package/src/melcloud.js +63 -68
package/src/deviceerv.js
CHANGED
|
@@ -7,7 +7,7 @@ const CONSTANTS = require('./constants.json');
|
|
|
7
7
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
8
8
|
|
|
9
9
|
class DeviceErv extends EventEmitter {
|
|
10
|
-
constructor(api, account,
|
|
10
|
+
constructor(api, account, melCloud, accountInfo, accountName, contextKey, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile, deviceRefreshInterval) {
|
|
11
11
|
super();
|
|
12
12
|
|
|
13
13
|
Accessory = api.platformAccessory;
|
|
@@ -17,12 +17,12 @@ class DeviceErv extends EventEmitter {
|
|
|
17
17
|
AccessoryUUID = api.hap.uuid;
|
|
18
18
|
|
|
19
19
|
//account config
|
|
20
|
-
this.displayMode =
|
|
21
|
-
this.temperatureSensor =
|
|
22
|
-
this.temperatureSensorOutdoor =
|
|
23
|
-
this.temperatureSensorSupply =
|
|
24
|
-
this.presetsEnabled =
|
|
25
|
-
this.buttons =
|
|
20
|
+
this.displayMode = account.ervDisplayMode || 0;
|
|
21
|
+
this.temperatureSensor = account.ervTemperatureSensor || false;
|
|
22
|
+
this.temperatureSensorOutdoor = account.ervTemperatureSensorOutdoor || false;
|
|
23
|
+
this.temperatureSensorSupply = account.ervTemperatureSensorSupply || false;
|
|
24
|
+
this.presetsEnabled = account.ervPresets || false;
|
|
25
|
+
this.buttons = account.ervButtons || [];
|
|
26
26
|
this.disableLogInfo = account.disableLogInfo || false;
|
|
27
27
|
this.disableLogDeviceInfo = account.disableLogDeviceInfo || false;
|
|
28
28
|
this.enableDebugMode = account.enableDebugMode || false;
|
|
@@ -67,7 +67,7 @@ class DeviceErv extends EventEmitter {
|
|
|
67
67
|
accountInfoFile: accountInfoFile,
|
|
68
68
|
deviceInfoFile: deviceInfoFile,
|
|
69
69
|
debugLog: account.enableDebugMode,
|
|
70
|
-
refreshInterval:
|
|
70
|
+
refreshInterval: deviceRefreshInterval
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
this.melCloudErv.on('externalIntegrations', (deviceData, deviceState) => {
|
package/src/melcloud.js
CHANGED
|
@@ -10,14 +10,12 @@ const CONSTANTS = require('./constants.json');
|
|
|
10
10
|
class MelCloud extends EventEmitter {
|
|
11
11
|
constructor(user, passwd, language, accountInfoFile, deviceInfoFile, buildingsFile, enableDebugMode, refreshInterval, connectForConfig) {
|
|
12
12
|
super();
|
|
13
|
+
this.enableDebugMode = enableDebugMode;
|
|
13
14
|
this.accountInfoFile = accountInfoFile;
|
|
14
15
|
this.buildingsFile = buildingsFile;
|
|
15
16
|
this.deviceInfoFile = deviceInfoFile;
|
|
16
|
-
this.enableDebugMode = enableDebugMode;
|
|
17
17
|
this.refreshInterval = refreshInterval;
|
|
18
18
|
this.connectForConfig = connectForConfig;
|
|
19
|
-
this.emitReady = true;
|
|
20
|
-
this.contextKey = '';
|
|
21
19
|
this.devicesId = [];
|
|
22
20
|
|
|
23
21
|
this.options = {
|
|
@@ -32,18 +30,16 @@ class MelCloud extends EventEmitter {
|
|
|
32
30
|
}
|
|
33
31
|
};
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.connect();
|
|
46
|
-
};
|
|
33
|
+
this.impulseGenerator = new ImpulseGenerator();
|
|
34
|
+
this.impulseGenerator.on('checkDevicesList', async () => {
|
|
35
|
+
try {
|
|
36
|
+
await this.chackDevicesList();
|
|
37
|
+
} catch (error) {
|
|
38
|
+
this.emit('error', `Check devices list: ${error}.`);
|
|
39
|
+
};
|
|
40
|
+
}).on('state', (state) => { });
|
|
41
|
+
|
|
42
|
+
this.connect();
|
|
47
43
|
};
|
|
48
44
|
|
|
49
45
|
async connect() {
|
|
@@ -83,26 +79,57 @@ class MelCloud extends EventEmitter {
|
|
|
83
79
|
this.emit('warn', `Context key: ${contextKey}, missing.`)
|
|
84
80
|
return;
|
|
85
81
|
};
|
|
82
|
+
|
|
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
|
+
|
|
86
118
|
this.accountInfo = accountInfo;
|
|
87
119
|
this.contextKey = contextKey;
|
|
88
120
|
|
|
89
|
-
//return if connect for config
|
|
90
|
-
if (this.connectForConfig) {
|
|
91
|
-
return contextKey;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
121
|
//save melcloud info to the file
|
|
95
122
|
await this.saveData(this.accountInfoFile, accountInfo);
|
|
96
123
|
|
|
97
124
|
//check devices list
|
|
98
|
-
await this.chackDevicesList(
|
|
125
|
+
await this.chackDevicesList();
|
|
99
126
|
|
|
100
127
|
//emit connect success
|
|
101
128
|
this.emit('success', `Connect to MELCloud Success.`)
|
|
102
129
|
|
|
103
130
|
//start impulse generator
|
|
104
131
|
const timers = [{ name: 'checkDevicesList', sampling: this.refreshInterval }];
|
|
105
|
-
this.impulseGenerator.start(timers);
|
|
132
|
+
const startImpulseGenerator = this.connectForConfig ? false : this.impulseGenerator.start(timers);
|
|
106
133
|
|
|
107
134
|
return true;
|
|
108
135
|
} catch (error) {
|
|
@@ -110,27 +137,10 @@ class MelCloud extends EventEmitter {
|
|
|
110
137
|
};
|
|
111
138
|
}
|
|
112
139
|
|
|
113
|
-
async chackDevicesList(
|
|
140
|
+
async chackDevicesList() {
|
|
114
141
|
try {
|
|
115
|
-
//create axios instance get
|
|
116
|
-
const axiosInstanceGet = axios.create({
|
|
117
|
-
method: 'GET',
|
|
118
|
-
baseURL: CONSTANTS.ApiUrls.BaseURL,
|
|
119
|
-
timeout: 5000,
|
|
120
|
-
headers: {
|
|
121
|
-
'X-MitsContextKey': contextKey
|
|
122
|
-
},
|
|
123
|
-
maxContentLength: 100000000,
|
|
124
|
-
maxBodyLength: 1000000000,
|
|
125
|
-
withCredentials: true,
|
|
126
|
-
httpsAgent: new https.Agent({
|
|
127
|
-
keepAlive: false,
|
|
128
|
-
rejectUnauthorized: false
|
|
129
|
-
})
|
|
130
|
-
});
|
|
131
|
-
|
|
132
142
|
const debug = this.enableDebugMode ? this.emit('debug', `Scanning for devices.`) : false;
|
|
133
|
-
const listDevicesData = await axiosInstanceGet(CONSTANTS.ApiUrls.ListDevices);
|
|
143
|
+
const listDevicesData = await this.axiosInstanceGet(CONSTANTS.ApiUrls.ListDevices);
|
|
134
144
|
const buildingsList = listDevicesData.data;
|
|
135
145
|
const debug1 = this.enableDebugMode ? this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`) : false;
|
|
136
146
|
|
|
@@ -166,10 +176,11 @@ class MelCloud extends EventEmitter {
|
|
|
166
176
|
}
|
|
167
177
|
const debug3 = this.enableDebugMode ? this.emit('debug', `Found: ${devicesCount} devices.`) : false;
|
|
168
178
|
|
|
169
|
-
//
|
|
179
|
+
//emit devices list for config
|
|
180
|
+
this.emit('devicesList', devices);
|
|
170
181
|
if (this.connectForConfig) {
|
|
171
|
-
return
|
|
172
|
-
}
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
173
184
|
|
|
174
185
|
//get device info fom devices
|
|
175
186
|
for (const deviceInfo of devices) {
|
|
@@ -180,15 +191,17 @@ class MelCloud extends EventEmitter {
|
|
|
180
191
|
const deviceInfoFile = `${this.deviceInfoFile}${deviceId}`;
|
|
181
192
|
await this.saveData(deviceInfoFile, deviceInfo);
|
|
182
193
|
const debug = this.enableDebugMode ? this.emit('debug', `Device: ${deviceName} info saved.`) : false;
|
|
183
|
-
};
|
|
184
194
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
195
|
+
//prepare device if not in devices array
|
|
196
|
+
if (!this.devicesId.includes(deviceId)) {
|
|
197
|
+
this.devicesId.push(deviceId);
|
|
198
|
+
this.emit('checkDevicesListComplete', this.accountInfo, this.contextKey, deviceInfo);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
188
201
|
|
|
189
202
|
return true;
|
|
190
203
|
} catch (error) {
|
|
191
|
-
|
|
204
|
+
this.impulseGenerator.stop();
|
|
192
205
|
throw new Error(`Scanning for devices error: ${error.message ?? error}.`);
|
|
193
206
|
};
|
|
194
207
|
}
|
|
@@ -205,29 +218,11 @@ class MelCloud extends EventEmitter {
|
|
|
205
218
|
|
|
206
219
|
async send(accountInfo) {
|
|
207
220
|
try {
|
|
208
|
-
//create axios instance post
|
|
209
|
-
const axiosInstancePost = axios.create({
|
|
210
|
-
method: 'POST',
|
|
211
|
-
baseURL: CONSTANTS.ApiUrls.BaseURL,
|
|
212
|
-
timeout: 5000,
|
|
213
|
-
headers: {
|
|
214
|
-
'X-MitsContextKey': this.contextKey,
|
|
215
|
-
'content-type': 'application/json'
|
|
216
|
-
},
|
|
217
|
-
maxContentLength: 100000000,
|
|
218
|
-
maxBodyLength: 1000000000,
|
|
219
|
-
withCredentials: true,
|
|
220
|
-
httpsAgent: new https.Agent({
|
|
221
|
-
keepAlive: false,
|
|
222
|
-
rejectUnauthorized: false
|
|
223
|
-
})
|
|
224
|
-
});
|
|
225
|
-
|
|
226
221
|
const options = {
|
|
227
222
|
data: accountInfo
|
|
228
223
|
};
|
|
229
224
|
|
|
230
|
-
await axiosInstancePost(CONSTANTS.ApiUrls.UpdateApplicationOptions, options);
|
|
225
|
+
await this.axiosInstancePost(CONSTANTS.ApiUrls.UpdateApplicationOptions, options);
|
|
231
226
|
await this.saveData(this.accountInfoFile, accountInfo);
|
|
232
227
|
return true;
|
|
233
228
|
} catch (error) {
|