homebridge-lib 6.3.7 → 6.3.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/README.md CHANGED
@@ -44,14 +44,9 @@ This way, `npm` installs Homebridge Lib automatically when installing the actual
44
44
 
45
45
  To install the command-line tools, use:
46
46
  ```
47
- $ sudo npm -g i homebridge-lib
47
+ $ sudo npm -g i hb-lib-tools
48
48
  ```
49
49
  This creates symlinks to these tools in `/usr/bin` or `/usr/local/bin` (depending on how you installed NodeJS).
50
- Note that, when Homebridge Lib is installed like this, Homebridge might issue a warning at startup:
51
- ```
52
- Plugin /usr/lib/node_modules/homebridge-lib package.json does not contain the keyword 'homebridge-plugin'
53
- ```
54
- This warning can be ignored safely.
55
50
 
56
51
  ### Credits
57
52
  The logic for handling [Eve](https://www.evehome.com/en/eve-app) history was copied from Simone Tisa's [`fakegato-history`](https://github.com/simont77/fakegato-history) repository, copyright © 2017 simont77.
package/cli/hap.js CHANGED
@@ -9,6 +9,6 @@
9
9
 
10
10
  'use strict'
11
11
 
12
- const { HapTool } = require('../index')
12
+ const { HapTool } = require('hb-lib-tools')
13
13
 
14
- new HapTool().main()
14
+ new HapTool(require('../package.json')).main()
package/cli/json.js CHANGED
@@ -9,6 +9,6 @@
9
9
 
10
10
  'use strict'
11
11
 
12
- const { JsonTool } = require('../index')
12
+ const { JsonTool } = require('hb-lib-tools')
13
13
 
14
- new JsonTool().main()
14
+ new JsonTool(require('../package.json')).main()
package/cli/sysinfo.js CHANGED
@@ -9,6 +9,6 @@
9
9
 
10
10
  'use strict'
11
11
 
12
- const { SysinfoTool } = require('../index')
12
+ const { SysinfoTool } = require('hb-lib-tools')
13
13
 
14
- new SysinfoTool().main()
14
+ new SysinfoTool(require('../package.json')).main()
package/cli/upnp.js CHANGED
@@ -9,6 +9,6 @@
9
9
 
10
10
  'use strict'
11
11
 
12
- const { UpnpTool } = require('../index')
12
+ const { UpnpTool } = require('hb-lib-tools')
13
13
 
14
- new UpnpTool().main()
14
+ new UpnpTool(require('../package.json')).main()
package/index.js CHANGED
@@ -5,32 +5,7 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- const chalk = require('chalk')
9
- const net = require('net')
10
-
11
- // Force colors when output is re-directed.
12
- chalk.enabled = true
13
- chalk.level = 1
14
-
15
- // Check of e is a JavaScript runtime error.
16
- function isJavaScriptError (e) {
17
- return [
18
- 'AssertionError',
19
- 'EvalError',
20
- 'RangeError',
21
- 'ReferenceError',
22
- 'SyntaxError',
23
- 'TypeError',
24
- 'URIError'
25
- ].includes(e.constructor.name)
26
- }
27
-
28
- // Check if e is a NodeJs runtime error.
29
- function isNodejsError (e) {
30
- return typeof e.code === 'string' && e.code.startsWith('ERR_')
31
- }
32
-
33
- const zeroes = '00000000000000000000000000000000'
8
+ const hbLibTools = require('hb-lib-tools')
34
9
 
35
10
  /** Library for Homebridge plugins.
36
11
  * see the {@tutorial homebridgeLib} tutorial.
@@ -41,23 +16,24 @@ const zeroes = '00000000000000000000000000000000'
41
16
  * {@link AccessoryDelegate},
42
17
  * {@link ServiceDelegate}, and
43
18
  * {@link CharacteristicDelegate}.
44
- * - A base class to building command-line tools:
19
+ * - An abstract base class to building command-line tools:
45
20
  * {@link CommandLineTool}.
46
21
  * - A series of helper classes for building homebridge plugins (of any type)
47
22
  * and/or command-line utilities:
48
23
  * {@link AdaptiveLighting},
49
24
  * {@link Colour},
50
25
  * {@link CommandLineParser},
26
+ * {@link CustomHomeKitTypes},
27
+ * {@link Delegate},
51
28
  * {@link EveHomeKitTypes},
52
29
  * {@link HttpClient},
53
30
  * {@link JsonFormatter},
54
31
  * {@link MyHomeKitTypes},
55
- * {@link OptionParser}, and
32
+ * {@link OptionParser},
33
+ * {@link PropertyDelegate},
34
+ * {@link SystemInfo},
35
+ * {@link UiServer}, and
56
36
  * {@link UpnpClient}.
57
- * - A series of command-line utilities for troubleshooting Homebridge setups:
58
- * `hap`, `json`, `upnp`.
59
- * For more information on these, start the tool from the command-line
60
- * with `-h` or `--help`.
61
37
  *
62
38
  * To access the classes provided by Homebridge Lib from your module,
63
39
  * simply load it by:
@@ -87,6 +63,13 @@ class homebridgeLib {
87
63
  */
88
64
  static get AdaptiveLighting () { return require('./lib/AdaptiveLighting') }
89
65
 
66
+ /** Return the `Bonjour` class from [`bonjour-hap`](https://github.com/homebridge/bonjour),
67
+ * so plugins don't have to list this as a separate dependency.
68
+ * @type {Class}
69
+ * @memberof module:homebridgeLib
70
+ */
71
+ static get Bonjour () { return hbLibTools.Bonjour }
72
+
90
73
  /** Delegate of a HomeKit characteristic.
91
74
  * <br>See {@link CharacteristicDelegate}.
92
75
  * @type {Class}
@@ -99,21 +82,21 @@ class homebridgeLib {
99
82
  * @type {Class}
100
83
  * @memberof module:homebridgeLib
101
84
  */
102
- static get Colour () { return require('./lib/Colour') }
85
+ static get Colour () { return hbLibTools.Colour }
103
86
 
104
87
  /** Parser and validator for command-line arguments.
105
88
  * <br>See {@link CommandLineParser}.
106
89
  * @type {Class}
107
90
  * @memberof module:homebridgeLib
108
91
  */
109
- static get CommandLineParser () { return require('./lib/CommandLineParser') }
92
+ static get CommandLineParser () { return hbLibTools.CommandLineParser }
110
93
 
111
94
  /** Command-line tool.
112
95
  * <br>See {@link CommandLineTool}.
113
96
  * @type {Class}
114
97
  * @memberof module:homebridgeLib
115
98
  */
116
- static get CommandLineTool () { return require('./lib/CommandLineTool') }
99
+ static get CommandLineTool () { return hbLibTools.CommandLineTool }
117
100
 
118
101
  /** Abstract superclass for {@link EveHomeKitTypes}
119
102
  * and {@link MyHomeKitTypes}.
@@ -145,14 +128,14 @@ class homebridgeLib {
145
128
  * @type {Class}
146
129
  * @memberof module:homebridgeLib
147
130
  */
148
- static get HttpClient () { return require('./lib/HttpClient') }
131
+ static get HttpClient () { return hbLibTools.HttpClient }
149
132
 
150
133
  /** JSON formatter.
151
134
  * <br>See {@link JsonFormatter}.
152
135
  * @type {Class}
153
136
  * @memberof module:homebridgeLib
154
137
  */
155
- static get JsonFormatter () { return require('./lib/JsonFormatter') }
138
+ static get JsonFormatter () { return hbLibTools.JsonFormatter }
156
139
 
157
140
  /** My own collection of custom HomeKit services and characteristics.
158
141
  * <br>See {@link MyHomeKitTypes}.
@@ -166,7 +149,7 @@ class homebridgeLib {
166
149
  * @type {Class}
167
150
  * @memberof module:homebridgeLib
168
151
  */
169
- static get OptionParser () { return require('./lib/OptionParser') }
152
+ static get OptionParser () { return hbLibTools.OptionParser }
170
153
 
171
154
  /** Homebridge dynamic platform plugin.
172
155
  * <br>See {@link Platform}.
@@ -194,27 +177,21 @@ class homebridgeLib {
194
177
  * @type {Class}
195
178
  * @memberof module:homebridgeLib
196
179
  */
197
- static get SystemInfo () { return require('./lib/SystemInfo') }
180
+ static get SystemInfo () { return hbLibTools.SystemInfo }
198
181
 
199
- /** Server for dynamic configuration settings through Homebridge UI.
200
- * <br>See {@link UiServer}.
182
+ /** Universal Plug and Play client.
183
+ * <br>See {@link UpnpClient}.
201
184
  * @type {Class}
202
185
  * @memberof module:homebridgeLib
203
186
  */
204
- static get UiServer () { return require('./lib/UiServer') }
187
+ static get UpnpClient () { return hbLibTools.UpnpClient }
205
188
 
206
- /** Universal Plug and Play client.
207
- * <br>See {@link UpnpClient}.
189
+ /** Server for dynamic configuration settings through Homebridge UI.
190
+ * <br>See {@link UiServer}.
208
191
  * @type {Class}
209
192
  * @memberof module:homebridgeLib
210
193
  */
211
- static get UpnpClient () { return require('./lib/UpnpClient') }
212
-
213
- // Command-line tools.
214
- static get HapTool () { return require('./lib/HapTool') }
215
- static get JsonTool () { return require('./lib/JsonTool') }
216
- static get SysinfoTool () { return require('./lib/SysinfoTool') }
217
- static get UpnpTool () { return require('./lib/UpnpTool') }
194
+ static get UiServer () { return require('./lib/UiServer') }
218
195
 
219
196
  /** Resolve after given period, delaying execution.
220
197
  *
@@ -228,12 +205,7 @@ class homebridgeLib {
228
205
  * @throws {RangeError} On invalid parameter value.
229
206
  * @memberof module:homebridgeLib
230
207
  */
231
- static async timeout (msec) {
232
- msec = homebridgeLib.OptionParser.toInt('msec', msec, 0)
233
- return new Promise((resolve, reject) => {
234
- setTimeout(() => { resolve() }, msec)
235
- })
236
- }
208
+ static get timeout () { return hbLibTools.timeout }
237
209
 
238
210
  /** Convert Error to string.
239
211
  *
@@ -245,48 +217,7 @@ class homebridgeLib {
245
217
  * @returns {string} - The error as string.
246
218
  * @memberof module:homebridgeLib
247
219
  */
248
- static formatError (e, useChalk = false) {
249
- if (isJavaScriptError(e) || isNodejsError(e)) {
250
- if (useChalk) {
251
- const lines = e.stack.split('\n')
252
- const firstLine = lines.shift()
253
- return firstLine + '\n' + chalk.reset.grey(lines.join('\n'))
254
- }
255
- return e.stack
256
- }
257
- if (e.errno != null) { // SystemError
258
- let label = ''
259
- if (e.path != null) {
260
- label = e.path
261
- } else if (e.dest != null) {
262
- label = e.dest
263
- } else if (e.address != null) {
264
- label = e.address
265
- if (net.isIPv6(label)) {
266
- label = '[' + label + ']'
267
- }
268
- if (e.port != null) {
269
- label += ':' + e.port
270
- }
271
- } else if (e.port != null) {
272
- label = '' + e.port
273
- } else if (e.hostname != null) {
274
- label = e.hostname
275
- }
276
- let message = ''
277
- const a = /[A-Z0-9_-]*:( .*),/.exec(e.message)
278
- if (a != null && a[1] != null) {
279
- message = a[1]
280
- }
281
- if (label != null && message != null) {
282
- return `${label}: cannot ${e.syscall}: ${e.code}${message}`
283
- }
284
- }
285
- if (e.cmd != null && e.message.slice(-1) === '\n') { // exec error
286
- return e.message.slice(0, e.message.length - 1)
287
- }
288
- return e.message
289
- }
220
+ static get formatError () { return hbLibTools.formatError }
290
221
 
291
222
  /** Convert integer to hex string.
292
223
  * @param {integer} i - The integer.
@@ -294,14 +225,19 @@ class homebridgeLib {
294
225
  * @returns {string} - The hex string.
295
226
  * @memberof module:homebridgeLib
296
227
  */
297
- static toHexString (i, length = 4) {
298
- return (zeroes + i.toString(16)).slice(-length).toUpperCase()
299
- }
228
+ static get toHexString () { return hbLibTools.toHexString }
229
+
230
+ /** Return the [`chalk`](https://github.com/chalk/chalk) module,
231
+ * so plugins don't have to list this as a separate dependency.
232
+ * @memberof module:homebridgeLib
233
+ */
234
+ static get chalk () { return hbLibTools.chalk }
300
235
 
301
- /** Return the `semver` library, so plugins don't have to list this as a
302
- * separate dependency.
236
+ /** Return the [`semver`](https://github.com/npm/node-semver) module,
237
+ * so plugins don't have to list this as a separate dependency.
238
+ * @memberof module:homebridgeLib
303
239
  */
304
- static get semver () { return require('semver') }
240
+ static get semver () { return hbLibTools.semver }
305
241
  }
306
242
 
307
243
  module.exports = homebridgeLib
@@ -284,7 +284,7 @@ class AccessoryDelegate extends homebridgeLib.Delegate {
284
284
  * from.
285
285
  */
286
286
  inheritLogLevel (delegate) {
287
- if (!(delegate instanceof homebridgeLib.AccessoryDelegate)) {
287
+ if (!(delegate instanceof AccessoryDelegate)) {
288
288
  throw new TypeError('delegate: not an AccessoryDelegate')
289
289
  }
290
290
  if (delegate === this) {
@@ -5,7 +5,7 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- const homebridgeLib = require('../index')
8
+ const { CharacteristicDelegate } = require('../index')
9
9
 
10
10
  /* global BigInt */
11
11
 
@@ -185,7 +185,7 @@ class AdaptiveLighting {
185
185
 
186
186
  get briIid () {
187
187
  if (this._briIid == null) {
188
- this._briIid = this._bri instanceof homebridgeLib.CharacteristicDelegate
188
+ this._briIid = this._bri instanceof CharacteristicDelegate
189
189
  ? this._bri._characteristic.iid
190
190
  : this._bri
191
191
  }
@@ -194,7 +194,7 @@ class AdaptiveLighting {
194
194
 
195
195
  get ctIid () {
196
196
  if (this._ctIid == null) {
197
- this._ctIid = this._ct instanceof homebridgeLib.CharacteristicDelegate
197
+ this._ctIid = this._ct instanceof CharacteristicDelegate
198
198
  ? this._ct._characteristic.iid
199
199
  : this._ct
200
200
  }
package/lib/Delegate.js CHANGED
@@ -6,6 +6,7 @@
6
6
  'use strict'
7
7
 
8
8
  const homebridgeLib = require('../index')
9
+ const { HttpClient } = homebridgeLib
9
10
 
10
11
  const events = require('events')
11
12
 
@@ -181,7 +182,7 @@ class Delegate extends events.EventEmitter {
181
182
  * @param {...string} args - Arguments to the printf-style message.
182
183
  */
183
184
  error (format, ...args) {
184
- if (format instanceof homebridgeLib.HttpClient.HttpError) {
185
+ if (format instanceof HttpClient.HttpError) {
185
186
  // Error already emitted by HttpClient.
186
187
  return
187
188
  }
@@ -3,7 +3,7 @@
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2017-2023 Erik Baauw. All rights reserved.
5
5
 
6
- const homebridgeLib = require('../index')
6
+ const { CustomHomeKitTypes } = require('../index')
7
7
 
8
8
  // Return long Eve UUID.
9
9
  function uuid (id) {
@@ -26,7 +26,7 @@ function uuid (id) {
26
26
  * [Gist](https://gist.github.com/simont77/3f4d4330fa55b83f8ca96388d9004e7d).
27
27
  * @extends CustomHomeKitTypes
28
28
  */
29
- class EveHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
29
+ class EveHomeKitTypes extends CustomHomeKitTypes {
30
30
  /** Start time for Eve history (2001-01-01T00:00:00Z).
31
31
  * @type {integer}
32
32
  * @readonly
@@ -5,7 +5,7 @@
5
5
  //
6
6
  // My own collection of custom HomeKit Services and Characteristics.
7
7
 
8
- const homebridgeLib = require('../index')
8
+ const { CustomHomeKitTypes } = require('../index')
9
9
 
10
10
  function uuid (id) {
11
11
  return MyHomeKitTypes.uuid(id, '-0000-1000-8000-656261617577')
@@ -15,7 +15,7 @@ function uuid (id) {
15
15
  * My own collection of custom HomeKit Services and Characteristics.
16
16
  * @extends CustomHomeKitTypes
17
17
  */
18
- class MyHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
18
+ class MyHomeKitTypes extends CustomHomeKitTypes {
19
19
  /**
20
20
  * Create my custom HomeKit Services and Characteristics.
21
21
  * @param {object} homebridge - API object from homebridge
package/lib/Platform.js CHANGED
@@ -6,11 +6,13 @@
6
6
  'use strict'
7
7
 
8
8
  const homebridgeLib = require('../index')
9
+ const {
10
+ HttpClient, SystemInfo, UpnpClient, formatError, semver
11
+ } = homebridgeLib
9
12
 
10
13
  const events = require('events')
11
14
  const fs = require('fs')
12
15
  const http = require('http')
13
- const { semver } = homebridgeLib
14
16
  const util = require('util')
15
17
  const zlib = require('zlib')
16
18
 
@@ -176,7 +178,7 @@ class Platform extends homebridgeLib.Delegate {
176
178
  * @type {SystemInfo}
177
179
  * @readonly
178
180
  */
179
- this.systemInfo = new homebridgeLib.SystemInfo()
181
+ this.systemInfo = new SystemInfo()
180
182
  this.systemInfo
181
183
  .on('error', (error) => { this.warn(error) })
182
184
  .on('exec', (command) => { this.debug('exec: %s', command) })
@@ -372,7 +374,7 @@ class Platform extends homebridgeLib.Delegate {
372
374
  async _checkLatest (name, version) {
373
375
  try {
374
376
  if (this.npmRegistry == null) {
375
- this.npmRegistry = new homebridgeLib.HttpClient({
377
+ this.npmRegistry = new HttpClient({
376
378
  https: true,
377
379
  host: 'registry.npmjs.org',
378
380
  json: true,
@@ -556,7 +558,7 @@ class Platform extends homebridgeLib.Delegate {
556
558
  if (this._upnpMonitor != null) {
557
559
  throw new SyntaxError('upnpConfig(): already called')
558
560
  }
559
- this._upnpMonitor = new homebridgeLib.UpnpClient(config)
561
+ this._upnpMonitor = new UpnpClient(config)
560
562
  this._upnpMonitor
561
563
  .on('error', (error) => {
562
564
  this.error('upnp: error')
@@ -693,7 +695,7 @@ class Platform extends homebridgeLib.Delegate {
693
695
  if (args.length > 0) {
694
696
  let lastArg = args.pop()
695
697
  if (lastArg instanceof Error) {
696
- lastArg = homebridgeLib.formatError(lastArg, true)
698
+ lastArg = formatError(lastArg, true)
697
699
  }
698
700
  args.push(lastArg)
699
701
  }
@@ -5,9 +5,7 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- const homebridgeLib = require('../../index')
9
-
10
- const { ServiceDelegate } = homebridgeLib
8
+ const { ServiceDelegate } = require('../../index')
11
9
 
12
10
  /** Class for an _AccessoryInformation_ service delegate.
13
11
  *
@@ -5,9 +5,7 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- const homebridgeLib = require('../../index')
9
-
10
- const { ServiceDelegate } = homebridgeLib
8
+ const { ServiceDelegate } = require('../../index')
11
9
 
12
10
  /** Class for a _Battery_ service delegate.
13
11
  *
@@ -5,9 +5,7 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- const homebridgeLib = require('../../index')
9
-
10
- const { ServiceDelegate } = homebridgeLib
8
+ const { ServiceDelegate } = require('../../index')
11
9
 
12
10
  /** Class for a delegate for a dummy _StatelessProgrammableSwitch_ service.
13
11
  *
@@ -9,22 +9,17 @@
9
9
 
10
10
  'use strict'
11
11
 
12
- const { CharacteristicDelegate } = require('../../index')
13
- const homebridgeLib = require('../../index')
12
+ const { CharacteristicDelegate, ServiceDelegate } = require('../../index')
14
13
 
15
- const { ServiceDelegate } = homebridgeLib
16
-
17
- /** Eve history keeps time as # seconds since epoch of 2001/01/01.
18
- * @type {integer}
19
- */
14
+ // Eve history keeps time as # seconds since epoch of 2001/01/01.
15
+ // @type {integer}
20
16
  const epoch = Math.round(new Date('2001-01-01T00:00:00Z').valueOf() / 1000)
21
17
 
22
18
  const defaultMemorySize = 6 * 24 * 7 * 4 // 4 weeks of 1 entry per 10 minutes
23
19
 
24
- /** Convert date (in # seconds since NodeJS epoch) to string.
25
- * @param {integer} d - Seconds since NodeJS epoch.
26
- * @returns {string} Human readable date string.
27
- */
20
+ // Convert date (in # seconds since NodeJS epoch) to string.
21
+ // @param {integer} d - Seconds since NodeJS epoch.
22
+ // @returns {string} Human readable date string.
28
23
  function dateToString (d) {
29
24
  return new Date(1000 * d).toString().slice(0, 24)
30
25
  }
@@ -5,9 +5,7 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- const homebridgeLib = require('../../index')
9
-
10
- const { ServiceDelegate } = homebridgeLib
8
+ const { ServiceDelegate } = require('../../index')
11
9
 
12
10
  /** Class for a _ServiceLabel_ service delegate.
13
11
  *
package/lib/UiServer.js CHANGED
@@ -8,8 +8,7 @@
8
8
  const {
9
9
  HomebridgePluginUiServer // , RequestError
10
10
  } = require('@homebridge/plugin-ui-utils')
11
- const { HttpClient, formatError } = require('../index')
12
- const chalk = require('chalk')
11
+ const { HttpClient, chalk, formatError } = require('../index')
13
12
  const fs = require('fs').promises
14
13
  const path = require('path')
15
14
  const util = require('util')
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Library for homebridge plugins",
4
4
  "author": "Erik Baauw",
5
5
  "license": "Apache-2.0",
6
- "version": "6.3.7",
6
+ "version": "6.3.8",
7
7
  "keywords": [
8
8
  "homekit",
9
9
  "homebridge"
@@ -26,13 +26,11 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@homebridge/plugin-ui-utils": "~0.0.19",
29
- "bonjour-hap": "^3.6.4",
30
- "chalk": "^4.1.2",
31
- "semver": "^7.3.8"
29
+ "hb-lib-tools": "^1.0.2"
32
30
  },
33
31
  "scripts": {
34
- "prepare": "standard && mocha && rm -rf out && jsdoc -c jsdoc.json",
35
- "test": "standard && mocha"
32
+ "prepare": "standard && rm -rf out && jsdoc -c jsdoc.json",
33
+ "test": "standard"
36
34
  },
37
35
  "repository": {
38
36
  "type": "git",