homebridge-midea-platform 0.4.3 → 0.4.5
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.
|
@@ -187,6 +187,7 @@
|
|
|
187
187
|
currentConfig.devices = currentConfig.devices || [];
|
|
188
188
|
if (devices) {
|
|
189
189
|
devices.forEach((device) => {
|
|
190
|
+
const validAuth = device.token && device.key;
|
|
190
191
|
const tr = table.insertRow();
|
|
191
192
|
const td = tr.insertCell();
|
|
192
193
|
td.appendChild(document.createTextNode(device.name));
|
|
@@ -195,14 +196,21 @@
|
|
|
195
196
|
tr.insertCell().appendChild(document.createTextNode(device.displayName));
|
|
196
197
|
tr.insertCell().appendChild(document.createTextNode(device.model));
|
|
197
198
|
tr.insertCell().appendChild(document.createTextNode(device.id));
|
|
198
|
-
tr.insertCell().appendChild(document.createTextNode(
|
|
199
|
-
|
|
199
|
+
tr.insertCell().appendChild(document.createTextNode(
|
|
200
|
+
device.token ?
|
|
201
|
+
device.token.slice(0, 6) + '...' + device.token.slice(-4) :
|
|
202
|
+
'token missing' + '\n' +
|
|
203
|
+
device.key ?
|
|
204
|
+
device.key.slice(0, 6) + '...' + device.key.slice(-4) :
|
|
205
|
+
'key missing'
|
|
200
206
|
));
|
|
201
207
|
tr.insertCell().appendChild(document.createTextNode(device.ip));
|
|
202
208
|
|
|
203
209
|
const addCell = tr.insertCell();
|
|
204
210
|
if (device.displayName === 'Unknown') {
|
|
205
211
|
addCell.appendChild(document.createTextNode('Not supported'));
|
|
212
|
+
} else if (!validAuth) {
|
|
213
|
+
addCell.appendChild(document.createTextNode('Invalid credentials'));
|
|
206
214
|
} else if (currentDevice = currentConfig.devices.find((d) => d.id === device.id)) {
|
|
207
215
|
// addCell.appendChild(document.createTextNode('Already added'));
|
|
208
216
|
debugLog(`Existing device:\n${JSON.stringify(currentDevice, null, 2)}`);
|
package/homebridge-ui/server.js
CHANGED
|
@@ -87,7 +87,8 @@ class UiServer extends HomebridgePluginUiServer {
|
|
|
87
87
|
await this.cloud.login();
|
|
88
88
|
} catch (e) {
|
|
89
89
|
const msg = e instanceof Error ? e.stack : e;
|
|
90
|
-
|
|
90
|
+
this.logger.warn(`Login failed:\n${msg}`);
|
|
91
|
+
throw new RequestError('Login failed, check credentials.');
|
|
91
92
|
}
|
|
92
93
|
});
|
|
93
94
|
|
|
@@ -98,7 +99,7 @@ class UiServer extends HomebridgePluginUiServer {
|
|
|
98
99
|
});
|
|
99
100
|
this.config = config;
|
|
100
101
|
this.logger.setDebugEnabled(config.uiDebug ? config.uiDebug : false);
|
|
101
|
-
this.logger.debug(`Merged config
|
|
102
|
+
this.logger.debug(`Merged config:\n${JSON.stringify(config, null, 2)}`);
|
|
102
103
|
return config;
|
|
103
104
|
});
|
|
104
105
|
|
|
@@ -112,6 +113,9 @@ class UiServer extends HomebridgePluginUiServer {
|
|
|
112
113
|
this.onRequest('/discover', async () => {
|
|
113
114
|
try {
|
|
114
115
|
const devices = await this.blockingDiscover();
|
|
116
|
+
for (const device of devices) {
|
|
117
|
+
await this.getNewCredentials(device);
|
|
118
|
+
}
|
|
115
119
|
this.logger.debug(`All devices:\n${JSON.stringify(devices, null, 2)}`);
|
|
116
120
|
return devices
|
|
117
121
|
.filter((a) => Object.keys(a).length > 0)
|
|
@@ -155,10 +159,7 @@ class UiServer extends HomebridgePluginUiServer {
|
|
|
155
159
|
}
|
|
156
160
|
i++;
|
|
157
161
|
}
|
|
158
|
-
|
|
159
|
-
throw new Error(`[${device.name}] Authentication failed, token/key undefined.`);
|
|
160
|
-
}
|
|
161
|
-
this.logger.debug(`Token: ${device.token}, Key: ${device.key}`);
|
|
162
|
+
this.logger.debug(`[${device.name}] Token: ${device.token}, Key: ${device.key}`);
|
|
162
163
|
return;
|
|
163
164
|
}
|
|
164
165
|
|
|
@@ -179,12 +180,13 @@ class UiServer extends HomebridgePluginUiServer {
|
|
|
179
180
|
const response = await this.promiseSocket.read();
|
|
180
181
|
if (response) {
|
|
181
182
|
if (response.length < 20) {
|
|
182
|
-
|
|
183
|
+
this.logger.debug(`[${device.name}] Authenticate error when receiving data from ${device.ip}:${device.port}. (Data length: ${response.length})\n${JSON.stringify(response)}`);
|
|
184
|
+
throw Error(`[${device.name}] Authenticate error when receiving data from ${device.ip}:${device.port}. (Data length mismatch)`);
|
|
183
185
|
}
|
|
184
186
|
const resp = response.subarray(8, 72);
|
|
185
187
|
this.security.tcp_key_from_resp(resp, Buffer.from(device.key, 'hex'));
|
|
186
188
|
} else {
|
|
187
|
-
throw Error(`[${device.name}] Authenticate error when receiving data from ${
|
|
189
|
+
throw Error(`[${device.name}] Authenticate error when receiving data from ${device.ip}:${device.port}.`);
|
|
188
190
|
}
|
|
189
191
|
} finally {
|
|
190
192
|
this.promiseSocket.destroy();
|
|
@@ -203,7 +205,6 @@ class UiServer extends HomebridgePluginUiServer {
|
|
|
203
205
|
this.logger.info('Start device discovery...');
|
|
204
206
|
discover.startDiscover();
|
|
205
207
|
discover.on('device', async (device) => {
|
|
206
|
-
await this.getNewCredentials(device);
|
|
207
208
|
switch (device.type) {
|
|
208
209
|
case DeviceType.AIR_CONDITIONER:
|
|
209
210
|
device['displayName'] = 'Air Conditioner';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"displayName": "Homebridge Midea",
|
|
2
|
+
"displayName": "Homebridge Midea Platform",
|
|
3
3
|
"name": "homebridge-midea-platform",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.5",
|
|
5
5
|
"description": "Homebridge plugin for Midea devices",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"url": "https://github.com/kovapatrik/homebridge-midea/issues"
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
|
15
|
-
"node": "^18.17.0",
|
|
15
|
+
"node": "^18.17.0 || ^20.9.0",
|
|
16
16
|
"homebridge": "^1.6.0"
|
|
17
17
|
},
|
|
18
18
|
"main": "dist/index.js",
|