homebridge-nb 1.4.0 → 1.4.2

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.
@@ -13,6 +13,16 @@
13
13
  "required": true,
14
14
  "default": "Nuki"
15
15
  },
16
+ "devices": {
17
+ "title": "Device",
18
+ "description": "Whitelisted Nuki devices (default: all).<br>Make sure to include the Nuki bridge to which the device is connected.",
19
+ "type": "array",
20
+ "items": {
21
+ "title": "Device",
22
+ "description": "Nuki ID of the device.",
23
+ "type": "integer"
24
+ }
25
+ },
16
26
  "latch": {
17
27
  "description": "Expose a second <i>Lock Mechanism</i> service to unlatch a Smart Lock.",
18
28
  "type": "boolean"
@@ -45,6 +55,30 @@
45
55
  "title": "Advanced Settings",
46
56
  "description": "Don't change these, unless you understand what you're doing.",
47
57
  "items": [
58
+ {
59
+ "type": "help",
60
+ "helpvalue": "Devices"
61
+ },
62
+ {
63
+ "nodescription": true,
64
+ "notitle": true,
65
+ "key": "devices",
66
+ "type": "array",
67
+ "items": [
68
+ {
69
+ "type": "div",
70
+ "displayFlex": true,
71
+ "flex-direction": "row",
72
+ "items": [
73
+ {
74
+ "key": "devices[]",
75
+ "required": true,
76
+ "flex": "1 1 50px"
77
+ }
78
+ ]
79
+ }
80
+ ]
81
+ },
48
82
  "openerResetTimeout",
49
83
  "timeout",
50
84
  "port"
@@ -250,6 +250,9 @@ class Bridge extends homebridgeLib.AccessoryDelegate {
250
250
  continue
251
251
  }
252
252
  const id = device.nukiId.toString(16).toUpperCase()
253
+ if (!this.platform.isWhitelisted(id)) {
254
+ continue
255
+ }
253
256
  switch (device.deviceType) {
254
257
  case NbClient.DeviceTypes.SMARTLOCK:
255
258
  case NbClient.DeviceTypes.SMARTDOOR:
package/lib/NbPlatform.js CHANGED
@@ -9,11 +9,13 @@ const events = require('events')
9
9
  const homebridgeLib = require('homebridge-lib')
10
10
  const NbAccessory = require('./NbAccessory')
11
11
  const { NbClient, NbDiscovery, NbListener } = require('hb-nb-tools')
12
+ const { timeout } = homebridgeLib
12
13
 
13
14
  class NbPlatform extends homebridgeLib.Platform {
14
15
  constructor (log, configJson, homebridge) {
15
16
  super(log, configJson, homebridge)
16
17
  this.config = {
18
+ devices: [],
17
19
  openerResetTimeout: 500,
18
20
  timeout: 15
19
21
  }
@@ -21,6 +23,7 @@ class NbPlatform extends homebridgeLib.Platform {
21
23
  optionParser
22
24
  .stringKey('platform')
23
25
  .stringKey('name')
26
+ .arrayKey('devices')
24
27
  .boolKey('latch')
25
28
  .intKey('port', 0, 65535)
26
29
  .intKey('openerResetTimeout', 0, 2000) // milliseconds
@@ -30,6 +33,22 @@ class NbPlatform extends homebridgeLib.Platform {
30
33
  })
31
34
  try {
32
35
  optionParser.parse(configJson)
36
+ const validDevices = []
37
+ for (const i in this.config.devices) {
38
+ try {
39
+ const device = homebridgeLib.OptionParser.toInt(
40
+ `devices[${i}]`, this.config.devices[i], 0x10000000, 0xFFFFFFFF, true
41
+ )
42
+ validDevices.push(device.toString(16).toUpperCase())
43
+ } catch (error) {
44
+ if (error instanceof homebridgeLib.OptionParser.UserInputError) {
45
+ this.warn(error)
46
+ } else {
47
+ this.error(error)
48
+ }
49
+ }
50
+ }
51
+ this.config.devices = validDevices
33
52
  this.bridges = {}
34
53
  this.discovery = new NbDiscovery({
35
54
  timeout: this.config.timeout
@@ -128,11 +147,18 @@ class NbPlatform extends homebridgeLib.Platform {
128
147
  }
129
148
  }
130
149
 
150
+ isWhitelisted (id) {
151
+ return this.config.devices.length === 0 || this.config.devices.includes(id)
152
+ }
153
+
131
154
  async foundBridge (bridge) {
132
155
  if (bridge.ip == null || bridge.port == null) {
133
156
  return
134
157
  }
135
158
  const id = bridge.bridgeId.toString(16).toUpperCase()
159
+ if (!this.isWhitelisted(id)) {
160
+ return
161
+ }
136
162
  const host = bridge.ip + ':' + bridge.port
137
163
  if (this.bridges[id] == null) {
138
164
  const name = 'Bridge_' + id
@@ -175,8 +201,12 @@ class NbPlatform extends homebridgeLib.Platform {
175
201
  try {
176
202
  this.log('%s: press Nuki bridge button to obtain token', name)
177
203
  await client.auth()
204
+ if (client.token == null) {
205
+ this.warn('Nuki bridge button not pressed')
206
+ }
178
207
  } catch (error) {
179
208
  this.warn(error)
209
+ await timeout(30000)
180
210
  }
181
211
  }
182
212
  await client.init()
@@ -194,6 +224,9 @@ class NbPlatform extends homebridgeLib.Platform {
194
224
  }
195
225
 
196
226
  accessoryRestored (className, version, id, name, context) {
227
+ if (!this.isWhitelisted(id.split('-')[0])) {
228
+ return
229
+ }
197
230
  switch (className) {
198
231
  case 'Bridge':
199
232
  context.id = id
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName": "Homebridge NB",
5
5
  "author": "Erik Baauw",
6
6
  "license": "Apache-2.0",
7
- "version": "1.4.0",
7
+ "version": "1.4.2",
8
8
  "keywords": [
9
9
  "homebridge-plugin",
10
10
  "homekit",
@@ -18,13 +18,13 @@
18
18
  "nb": "cli/nb.js"
19
19
  },
20
20
  "engines": {
21
- "homebridge": "^1.6.0",
22
- "node": "^18.15.0",
21
+ "homebridge": "^1.6.1",
22
+ "node": "^18.16.0",
23
23
  "nuki": "2.15.0"
24
24
  },
25
25
  "dependencies": {
26
- "homebridge-lib": "~6.3.13",
27
- "hb-nb-tools": "~1.0.0"
26
+ "homebridge-lib": "~6.3.15",
27
+ "hb-nb-tools": "~1.1.0"
28
28
  },
29
29
  "scripts": {
30
30
  "prepare": "standard",