homebridge-midea-platform 0.4.2 → 0.4.4

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(device.token.slice(0, 6) + '...' + device.token.slice(-4) +
199
- '\n' + device.key.slice(0, 6) + '...' + device.key.slice(-4)
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)}`);
@@ -75,11 +75,11 @@ class UiServer extends HomebridgePluginUiServer {
75
75
  super();
76
76
  // Obtain the plugin configuration from homebridge config JSON file.
77
77
  const config = require(this.homebridgeConfigPath).platforms.find((obj) => obj.platform === 'midea-platform');
78
- this.logger = new Logger(config.uiDebug ? config.uiDebug : false);
78
+ this.logger = new Logger(config?.uiDebug ? config.uiDebug : false);
79
79
  this.logger.info(`Custom UI created.`);
80
80
  this.logger.debug(`ENV:\n${JSON.stringify(process.env, null, 2)}`);
81
81
  this.security = new LocalSecurity();
82
- this.promiseSocket = new PromiseSocket(this.logger, config.logRecoverableErrors ? config.logRecoverableErrors : false);
82
+ this.promiseSocket = new PromiseSocket(this.logger, config?.logRecoverableErrors ? config.logRecoverableErrors : false);
83
83
 
84
84
  this.onRequest('/login', async ({ username, password, registeredApp }) => {
85
85
  try {
@@ -112,6 +112,9 @@ class UiServer extends HomebridgePluginUiServer {
112
112
  this.onRequest('/discover', async () => {
113
113
  try {
114
114
  const devices = await this.blockingDiscover();
115
+ for (const device of devices) {
116
+ await this.getNewCredentials(device);
117
+ }
115
118
  this.logger.debug(`All devices:\n${JSON.stringify(devices, null, 2)}`);
116
119
  return devices
117
120
  .filter((a) => Object.keys(a).length > 0)
@@ -155,10 +158,7 @@ class UiServer extends HomebridgePluginUiServer {
155
158
  }
156
159
  i++;
157
160
  }
158
- if (!device.token || !device.key) {
159
- throw new Error(`[${device.name}] Authentication failed, token/key undefined.`);
160
- }
161
- this.logger.debug(`Token: ${device.token}, Key: ${device.key}`);
161
+ this.logger.debug(`[${device.name}] Token: ${device.token}, Key: ${device.key}`);
162
162
  return;
163
163
  }
164
164
 
@@ -203,7 +203,6 @@ class UiServer extends HomebridgePluginUiServer {
203
203
  this.logger.info('Start device discovery...');
204
204
  discover.startDiscover();
205
205
  discover.on('device', async (device) => {
206
- await this.getNewCredentials(device);
207
206
  switch (device.type) {
208
207
  case DeviceType.AIR_CONDITIONER:
209
208
  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.2",
4
+ "version": "0.4.4",
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",