homebridge-lib 6.7.5 → 7.0.0-1

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/cli/hap.js CHANGED
@@ -7,8 +7,11 @@
7
7
  //
8
8
  // Logger for HomeKit accessory announcements.
9
9
 
10
- 'use strict'
10
+ import { createRequire } from 'node:module'
11
11
 
12
- const { HapTool } = require('hb-lib-tools')
12
+ import { HapTool } from 'hb-lib-tools/HapTool'
13
13
 
14
- new HapTool(require('../package.json')).main()
14
+ const require = createRequire(import.meta.url)
15
+ const packageJson = require('../package.json')
16
+
17
+ new HapTool(packageJson).main()
package/cli/json.js CHANGED
@@ -7,8 +7,11 @@
7
7
  //
8
8
  // JSON formatter.
9
9
 
10
- 'use strict'
10
+ import { createRequire } from 'node:module'
11
11
 
12
- const { JsonTool } = require('hb-lib-tools')
12
+ import { JsonTool } from 'hb-lib-tools/JsonTool'
13
13
 
14
- new JsonTool(require('../package.json')).main()
14
+ const require = createRequire(import.meta.url)
15
+ const packageJson = require('../package.json')
16
+
17
+ new JsonTool(packageJson).main()
package/cli/sysinfo.js CHANGED
@@ -7,8 +7,11 @@
7
7
  //
8
8
  // Show system info.
9
9
 
10
- 'use strict'
10
+ import { createRequire } from 'node:module'
11
11
 
12
- const { SysinfoTool } = require('hb-lib-tools')
12
+ import { SysinfoTool } from 'hb-lib-tools/SysinfoTool'
13
13
 
14
- new SysinfoTool(require('../package.json')).main()
14
+ const require = createRequire(import.meta.url)
15
+ const packageJson = require('../package.json')
16
+
17
+ new SysinfoTool(packageJson).main()
package/cli/upnp.js CHANGED
@@ -7,8 +7,11 @@
7
7
  //
8
8
  // Logger for UPnP device announcements.
9
9
 
10
- 'use strict'
10
+ import { createRequire } from 'node:module'
11
11
 
12
- const { UpnpTool } = require('hb-lib-tools')
12
+ import { UpnpTool } from 'hb-lib-tools/UpnpTool'
13
13
 
14
- new UpnpTool(require('../package.json')).main()
14
+ const require = createRequire(import.meta.url)
15
+ const packageJson = require('../package.json')
16
+
17
+ new UpnpTool(packageJson).main()
package/index.js CHANGED
@@ -3,12 +3,8 @@
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2017-2024 Erik Baauw. All rights reserved.
5
5
 
6
- 'use strict'
7
-
8
- const hbLibTools = require('hb-lib-tools')
9
-
10
6
  /** Library for Homebridge plugins.
11
- * see the {@tutorial homebridgeLib} tutorial.
7
+ * see the {@tutorial homebridge-lib} tutorial.
12
8
  *
13
9
  * Homebridge Lib provides:
14
10
  * - A series of base classes for building Homebridge dynamic platform plugins:
@@ -38,7 +34,7 @@ const hbLibTools = require('hb-lib-tools')
38
34
  * To access the classes provided by Homebridge Lib from your module,
39
35
  * simply load it by:
40
36
  * ```javascript
41
- * const homebridgeLib = require('homebridge-lib')
37
+ * import { Class } from 'homebridge-lib/Class'
42
38
  * ```
43
39
  *
44
40
  * Note that each class provided by Homebridge Lib is implemented as a
@@ -46,207 +42,54 @@ const hbLibTools = require('hb-lib-tools')
46
42
  * Due to the way NodeJS deals with circular module dependencies, these modules
47
43
  * might not yet be initialised while your module is loading.
48
44
  *
49
- * @module homebridgeLib
45
+ * @module homebridge-lib
50
46
  */
51
- class homebridgeLib {
52
- /** Delegate of a HomeKit accessory.
53
- * <br>See {@link AccessoryDelegate}.
54
- * @type {Class}
55
- * @memberof module:homebridgeLib
56
- */
57
- static get AccessoryDelegate () { return require('./lib/AccessoryDelegate') }
58
-
59
- /** Adaptive Lighting.
60
- * <br>See {@link AdaptiveLighting}.
61
- * @type {Class}
62
- * @memberof module:homebridgeLib
63
- */
64
- static get AdaptiveLighting () { return require('./lib/AdaptiveLighting') }
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
-
73
- /** Delegate of a HomeKit characteristic.
74
- * <br>See {@link CharacteristicDelegate}.
75
- * @type {Class}
76
- * @memberof module:homebridgeLib
77
- */
78
- static get CharacteristicDelegate () { return require('./lib/CharacteristicDelegate') }
79
-
80
- /** Colour conversions.
81
- * <br>See {@link Colour}.
82
- * @type {Class}
83
- * @memberof module:homebridgeLib
84
- */
85
- static get Colour () { return hbLibTools.Colour }
86
-
87
- /** Parser and validator for command-line arguments.
88
- * <br>See {@link CommandLineParser}.
89
- * @type {Class}
90
- * @memberof module:homebridgeLib
91
- */
92
- static get CommandLineParser () { return hbLibTools.CommandLineParser }
93
-
94
- /** Command-line tool.
95
- * <br>See {@link CommandLineTool}.
96
- * @type {Class}
97
- * @memberof module:homebridgeLib
98
- */
99
- static get CommandLineTool () { return hbLibTools.CommandLineTool }
100
-
101
- /** Abstract superclass for {@link EveHomeKitTypes}
102
- * and {@link MyHomeKitTypes}.
103
- * <br>See {@link CustomHomeKitTypes}.
104
- * @type {Class}
105
- * @memberof module:homebridgeLib
106
- */
107
- static get CustomHomeKitTypes () { return require('./lib/CustomHomeKitTypes') }
108
-
109
- /** Abstract superclass for {@link Platform}, {@link AccessoryDelegate},
110
- * {@link ServiceDelegate}, and {@link CharacteristicDelegate}.
111
- * <br>See {@link Delegate}.
112
- * @type {Class}
113
- * @memberof module:homebridgeLib
114
- */
115
- static get Delegate () { return require('./lib/Delegate') }
116
-
117
- /** Custom HomeKit services and characteristics used by
118
- * [Eve](https://www.evehome.com/en) accessories and by the
119
- * [Eve app](https://www.evehome.com/en/eve-app).
120
- * <br>See {@link EveHomeKitTypes}.
121
- * @type {Class}
122
- * @memberof module:homebridgeLib
123
- */
124
- static get EveHomeKitTypes () { return require('./lib/EveHomeKitTypes') }
125
-
126
- /** HTTP client.
127
- * <br>See {@link HttpClient}.
128
- * @type {Class}
129
- * @memberof module:homebridgeLib
130
- */
131
- static get HttpClient () { return hbLibTools.HttpClient }
132
-
133
- /** JSON formatter.
134
- * <br>See {@link JsonFormatter}.
135
- * @type {Class}
136
- * @memberof module:homebridgeLib
137
- */
138
- static get JsonFormatter () { return hbLibTools.JsonFormatter }
139
-
140
- /** My own collection of custom HomeKit services and characteristics.
141
- * <br>See {@link MyHomeKitTypes}.
142
- * @type {Class}
143
- * @memberof module:homebridgeLib
144
- */
145
- static get MyHomeKitTypes () { return require('./lib/MyHomeKitTypes') }
146
-
147
- /** Parser and validator for options and other parameters.
148
- * <br>See {@link OptionParser}.
149
- * @type {Class}
150
- * @memberof module:homebridgeLib
151
- */
152
- static get OptionParser () { return hbLibTools.OptionParser }
153
-
154
- /** Homebridge dynamic platform plugin.
155
- * <br>See {@link Platform}.
156
- * @type {Class}
157
- * @memberof module:homebridgeLib
158
- */
159
- static get Platform () { return require('./lib/Platform') }
160
-
161
- /** Delegate of a property of a HomeKit accessory or service.
162
- * <br>See {@link PropertyDelegate}.
163
- * @type {Class}
164
- * @memberof module:homebridgeLib
165
- */
166
- static get PropertyDelegate () { return require('./lib/PropertyDelegate') }
167
-
168
- /** Delegate of a HomeKit service.
169
- * <br>See {@link ServiceDelegate}.
170
- * @type {Class}
171
- * @memberof module:homebridgeLib
172
- */
173
- static get ServiceDelegate () { return require('./lib/ServiceDelegate') }
174
47
 
175
- /** System information.
176
- * <br>See {@link SystemInfo}.
177
- * @type {Class}
178
- * @memberof module:homebridgeLib
179
- */
180
- static get SystemInfo () { return hbLibTools.SystemInfo }
181
-
182
- /** Universal Plug and Play client.
183
- * <br>See {@link UpnpClient}.
184
- * @type {Class}
185
- * @memberof module:homebridgeLib
186
- */
187
- static get UpnpClient () { return hbLibTools.UpnpClient }
188
-
189
- /** Server for dynamic configuration settings through Homebridge UI.
190
- * <br>See {@link UiServer}.
191
- * @type {Class}
192
- * @memberof module:homebridgeLib
193
- */
194
- static get UiServer () { return require('./lib/UiServer') }
195
-
196
- /** Resolve after given period, delaying execution.
197
- *
198
- * E.g. to delay execution for 1.5 seconds, issue:
199
- * ```javascript
200
- * await homebridgeLib.timeout(1500)
201
- * ```
202
- *
203
- * @param {integer} msec - Period (in msec) to wait.
204
- * @throws {TypeError} On invalid parameter type.
205
- * @throws {RangeError} On invalid parameter value.
206
- * @memberof module:homebridgeLib
207
- */
208
- static get timeout () { return hbLibTools.timeout }
209
-
210
- /** Convert Error to string.
211
- *
212
- * Include the stack trace only for programming errors (JavaScript and NodeJS
213
- * runtime errors).
214
- * Translate system errors into more readable messages.
215
- * @param {Error} e - The error.
216
- * @param {boolean} [useChalk=false] - Use chalk to grey out the stack trace.
217
- * @returns {string} - The error as string.
218
- * @memberof module:homebridgeLib
219
- */
220
- static get formatError () { return hbLibTools.formatError }
221
-
222
- /** Convert integer to hex string.
223
- * @param {integer} i - The integer.
224
- * @param {integer} [length=4] - The number of digits in the hex string.
225
- * @returns {string} - The hex string.
226
- * @memberof module:homebridgeLib
227
- */
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 }
235
-
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
239
- */
240
- static get semver () { return hbLibTools.semver }
241
-
242
- /** Return the recommended version of NodeJS from package.json.
243
- * This is the version used to develop and test the software,
244
- * typically the latest LTS version.
245
- * @param {string} packageJson - The contents of package.json
246
- * #return {string} - The recommended version.
247
- * @memberof module:hbLibTools
248
- */
249
- static get recommendedNodeVersion () { return hbLibTools.recommendedNodeVersion }
250
- }
48
+ /** Convert Error to string.
49
+ *
50
+ * Include the stack trace only for programming errors (JavaScript and NodeJS
51
+ * runtime errors).
52
+ * Translate system errors into more readable messages.
53
+ * @function formatError
54
+ * @param {Error} e - The error.
55
+ * @param {boolean} [useChalk=false] - Use chalk to grey out the stack trace.
56
+ * @returns {string} - The error as string.
57
+ * @memberof module:homebridge-lib
58
+ */
59
+ export { formatError } from 'hb-lib-tools'
60
+
61
+ /** Return the recommended version of NodeJS from package.json.
62
+ * This is the version used to develop and test the software,
63
+ * typically the latest LTS version.
64
+ * @function recommendedNodeVersion
65
+ * @param {string} packageJson - The contents of package.json
66
+ * #return {string} - The recommended version.
67
+ * @memberof module:hbLibTools
68
+ */
69
+ export { recommendedNodeVersion } from 'hb-lib-tools'
251
70
 
252
- module.exports = homebridgeLib
71
+ /** Resolve after given period, delaying execution.
72
+ *
73
+ * E.g. to delay execution for 1.5 seconds, issue:
74
+ * ```javascript
75
+ * import { timeout } from 'homebridge-lib'
76
+ *
77
+ * await timeout(1500)
78
+ * ```
79
+ *
80
+ * @function timeout
81
+ * @param {integer} msec - Period (in msec) to wait.
82
+ * @throws {TypeError} On invalid parameter type.
83
+ * @throws {RangeError} On invalid parameter value.
84
+ * @memberof module:homebridge-lib
85
+ */
86
+ export { timeout } from 'hb-lib-tools'
87
+
88
+ /** Convert integer to hex string.
89
+ * @function toHexString
90
+ * @param {integer} i - The integer.
91
+ * @param {integer} [length=4] - The number of digits in the hex string.
92
+ * @returns {string} - The hex string.
93
+ * @memberof module:homebridge-lib
94
+ */
95
+ export { toHexString } from 'hb-lib-tools'
@@ -3,18 +3,27 @@
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2017-2024 Erik Baauw. All rights reserved.
5
5
 
6
- 'use strict'
7
-
8
- const homebridgeLib = require('../index')
6
+ import { CharacteristicDelegate } from 'homebridge-lib/CharacteristicDelegate'
7
+ import { Delegate } from 'homebridge-lib/Delegate'
8
+ import { PropertyDelegate } from 'homebridge-lib/PropertyDelegate'
9
+ import { ServiceDelegate } from 'homebridge-lib/ServiceDelegate'
10
+ import 'homebridge-lib/ServiceDelegate/AccessoryInformation'
9
11
 
10
12
  const startsWithUuid = /^[0-9A-F]{8}-[0-9A-F]{4}-[1-5][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}/
11
13
 
14
+ /** Delegate of a HomeKit accessory.
15
+ * <br>See {@link AccessoryDelegate}.
16
+ * @name AccessoryDelegate
17
+ * @type {Class}
18
+ * @memberof module:homebridge-lib
19
+ */
20
+
12
21
  /** Delegate of a HomeKit accessory.
13
22
  *
14
23
  * @abstract
15
24
  * @extends Delegate
16
25
  */
17
- class AccessoryDelegate extends homebridgeLib.Delegate {
26
+ class AccessoryDelegate extends Delegate {
18
27
  /** Create a new instance of a HomeKit accessory delegate.
19
28
  *
20
29
  * When the corresponding HomeKit accessory was restored from persistent
@@ -75,8 +84,7 @@ class AccessoryDelegate extends homebridgeLib.Delegate {
75
84
 
76
85
  // Create delegate for AccessoryInformation service.
77
86
  this._serviceDelegates = {}
78
- this._accessoryInformationDelegate =
79
- new homebridgeLib.ServiceDelegate.AccessoryInformation(this, params)
87
+ this._accessoryInformationDelegate = new ServiceDelegate.AccessoryInformation(this, params)
80
88
 
81
89
  // Configure PlatformAccessory.
82
90
  this._accessory.on('identify', this._identify.bind(this))
@@ -189,7 +197,7 @@ class AccessoryDelegate extends homebridgeLib.Delegate {
189
197
  throw new SyntaxError(`${key}: duplicate key`)
190
198
  }
191
199
 
192
- const delegate = new homebridgeLib.PropertyDelegate(this, params)
200
+ const delegate = new PropertyDelegate(this, params)
193
201
  this._propertyDelegates[key] = delegate
194
202
 
195
203
  // Create shortcut for characteristic value.
@@ -303,8 +311,8 @@ class AccessoryDelegate extends homebridgeLib.Delegate {
303
311
  */
304
312
  manageLogLevel (delegate, forPlatform = false) {
305
313
  if (
306
- !(delegate instanceof homebridgeLib.CharacteristicDelegate) &&
307
- !(delegate instanceof homebridgeLib.PropertyDelegate)
314
+ !(delegate instanceof CharacteristicDelegate) &&
315
+ !(delegate instanceof PropertyDelegate)
308
316
  ) {
309
317
  throw new TypeError('delegate: not a CharacteristicDelegate or PropertyDelegate')
310
318
  }
@@ -329,4 +337,4 @@ class AccessoryDelegate extends homebridgeLib.Delegate {
329
337
  }
330
338
  }
331
339
 
332
- module.exports = AccessoryDelegate
340
+ export { AccessoryDelegate }
@@ -3,9 +3,7 @@
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2020-2024 Erik Baauw. All rights reserved.
5
5
 
6
- 'use strict'
7
-
8
- const { CharacteristicDelegate } = require('../index')
6
+ import { CharacteristicDelegate } from 'homebridge-lib/CharacteristicDelegate'
9
7
 
10
8
  /* global BigInt */
11
9
 
@@ -164,6 +162,13 @@ function tlvFromHexString (type, value) {
164
162
  return tlvFromBuffer(type, Buffer.from(value, 'hex'))
165
163
  }
166
164
 
165
+ /** Adaptive Lighting.
166
+ * <br>See {@link AdaptiveLighting}.
167
+ * @name AdaptiveLighting
168
+ * @type {Class}
169
+ * @memberof module:homebridge-lib
170
+ */
171
+
167
172
  /** Adaptive Lighting.
168
173
  */
169
174
  class AdaptiveLighting {
@@ -342,4 +347,4 @@ class AdaptiveLighting {
342
347
  }
343
348
  }
344
349
 
345
- module.exports = AdaptiveLighting
350
+ export { AdaptiveLighting }
package/lib/Bonjour.js ADDED
@@ -0,0 +1,12 @@
1
+ // homebridge-lib/lib/Bonjour.js
2
+ //
3
+ // Library for Homebridge plugins.
4
+ // Copyright © 2020-2024 Erik Baauw. All rights reserved.
5
+
6
+ /** Return the `Bonjour` class from [`bonjour-hap`](https://github.com/homebridge/bonjour),
7
+ * so plugins don't have to list this as a separate dependency.
8
+ * @name Bonjour
9
+ * @type {Class}
10
+ * @memberof module:homebridge-lib
11
+ */
12
+ export { Bonjour } from 'hb-lib-tools/Bonjour'
@@ -3,9 +3,16 @@
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2017-2024 Erik Baauw. All rights reserved.
5
5
 
6
- 'use strict'
6
+ import { Delegate } from 'homebridge-lib/Delegate'
7
+ import { OptionParser } from 'homebridge-lib/OptionParser'
8
+ import { ServiceDelegate } from 'homebridge-lib/ServiceDelegate'
7
9
 
8
- const homebridgeLib = require('../index')
10
+ /** Delegate of a HomeKit characteristic.
11
+ * <br>See {@link CharacteristicDelegate}.
12
+ * @name CharacteristicDelegate
13
+ * @type {Class}
14
+ * @memberof module:homebridge-lib
15
+ */
9
16
 
10
17
  /** Delegate of a HomeKit characteristic.
11
18
  *
@@ -50,7 +57,7 @@ const homebridgeLib = require('../index')
50
57
  *
51
58
  * @extends Delegate
52
59
  */
53
- class CharacteristicDelegate extends homebridgeLib.Delegate {
60
+ class CharacteristicDelegate extends Delegate {
54
61
  /** Create a new instance of a HomeKit characteristic delegate.
55
62
  *
56
63
  * Note that instances of `CharacteristicDelegate` are normally created by
@@ -95,7 +102,7 @@ class CharacteristicDelegate extends homebridgeLib.Delegate {
95
102
  * optional parameter is not applicable.
96
103
  */
97
104
  constructor (serviceDelegate, params = {}) {
98
- if (!(serviceDelegate instanceof homebridgeLib.ServiceDelegate)) {
105
+ if (!(serviceDelegate instanceof ServiceDelegate)) {
99
106
  throw new TypeError('serviceDelegate: not a ServiceDelegate')
100
107
  }
101
108
  super(serviceDelegate.platform, serviceDelegate.name)
@@ -145,7 +152,7 @@ class CharacteristicDelegate extends homebridgeLib.Delegate {
145
152
  }
146
153
  this._characteristic.on('set', this._onSet.bind(this))
147
154
  }
148
- this._timeout = homebridgeLib.OptionParser.toInt(
155
+ this._timeout = OptionParser.toInt(
149
156
  'params.timeout', params.timeout == null ? 1000 : params.timeout, 500, 5000
150
157
  )
151
158
  // Check that we are the only listener
@@ -451,4 +458,4 @@ class CharacteristicDelegate extends homebridgeLib.Delegate {
451
458
  }
452
459
  }
453
460
 
454
- module.exports = CharacteristicDelegate
461
+ export { CharacteristicDelegate }
package/lib/Colour.js ADDED
@@ -0,0 +1,12 @@
1
+ // homebridge-lib/lib/Colour.js
2
+ //
3
+ // Library for Homebridge plugins.
4
+ // Copyright © 2020-2024 Erik Baauw. All rights reserved.
5
+
6
+ /** Colour conversions.
7
+ * <br>See {@link Colour}.
8
+ * @name Colour
9
+ * @type {Class}
10
+ * @memberof module:homebridge-lib
11
+ */
12
+ export { Colour } from 'hb-lib-tools/Colour'
@@ -0,0 +1,12 @@
1
+ // homebridge-lib/lib/CommandLineParser.js
2
+ //
3
+ // Library for Homebridge plugins.
4
+ // Copyright © 2020-2024 Erik Baauw. All rights reserved.
5
+
6
+ /** Parser and validator for command-line arguments.
7
+ * <br>See {@link CommandLineParser}.
8
+ * @name CommandLineParser
9
+ * @type {Class}
10
+ * @memberof module:homebridge-lib
11
+ */
12
+ export { CommandLineParser } from 'hb-lib-tools/CommandLineParser'
@@ -0,0 +1,12 @@
1
+ // homebridge-lib/lib/CommandLineTool.js
2
+ //
3
+ // Library for Homebridge plugins.
4
+ // Copyright © 2020-2024 Erik Baauw. All rights reserved.
5
+
6
+ /** Command-line tool.
7
+ * <br>See {@link CommandLineTool}.
8
+ * @name CommandLineTool
9
+ * @type {Class}
10
+ * @memberof module:homebridge-lib
11
+ */
12
+ export { CommandLineTool } from 'hb-lib-tools/CommandLineTool'
@@ -13,6 +13,14 @@ let hap
13
13
  let hapCharacteristics
14
14
  let hapServices
15
15
 
16
+ /** Abstract superclass for {@link EveHomeKitTypes}
17
+ * and {@link MyHomeKitTypes}.
18
+ * <br>See {@link CustomHomeKitTypes}.
19
+ * @name CustomHomeKitTypes
20
+ * @type {Class}
21
+ * @memberof module:homebridge-lib
22
+ */
23
+
16
24
  /** Abstract superclass for {@link EveHomeKitTypes} and {@link MyHomeKitTypes}.
17
25
  *
18
26
  * `CustomHomeKitTypes` creates and manages a collection of:
@@ -233,4 +241,4 @@ class CustomHomeKitTypes {
233
241
  }
234
242
  }
235
243
 
236
- module.exports = CustomHomeKitTypes
244
+ export { CustomHomeKitTypes }
package/lib/Delegate.js CHANGED
@@ -3,12 +3,19 @@
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2017-2024 Erik Baauw. All rights reserved.
5
5
 
6
- 'use strict'
6
+ import { EventEmitter } from 'node:events'
7
7
 
8
- const homebridgeLib = require('../index')
9
- const { HttpClient } = homebridgeLib
8
+ import { HttpClient } from 'hb-lib-tools/HttpClient'
10
9
 
11
- const events = require('events')
10
+ import { Platform } from 'homebridge-lib/Platform'
11
+
12
+ /** Abstract superclass for {@link Platform}, {@link AccessoryDelegate},
13
+ * {@link ServiceDelegate}, and {@link CharacteristicDelegate}.
14
+ * <br>See {@link Delegate}.
15
+ * @name Delegate
16
+ * @type {Class}
17
+ * @memberof module:homebridge-lib
18
+ */
12
19
 
13
20
  /** Abstract superclass for {@link Platform}, {@link AccessoryDelegate},
14
21
  * {@link ServiceDelegate}, and {@link CharacteristicDelegate}.
@@ -19,7 +26,7 @@ const events = require('events')
19
26
  * @abstract
20
27
  * @extends EventEmitter
21
28
  */
22
- class Delegate extends events.EventEmitter {
29
+ class Delegate extends EventEmitter {
23
30
  /** Create a new `Delegate` instance.
24
31
  * @abstract
25
32
  * @param {?Platform} platform - Reference to the corresponding platform
@@ -32,7 +39,7 @@ class Delegate extends events.EventEmitter {
32
39
  if (platform == null) {
33
40
  platform = this
34
41
  }
35
- if (!(platform instanceof homebridgeLib.Platform)) {
42
+ if (!(platform instanceof Platform)) {
36
43
  throw new TypeError('platform: not a Platform')
37
44
  }
38
45
  this._platform = platform
@@ -256,4 +263,4 @@ class Delegate extends events.EventEmitter {
256
263
  }
257
264
  }
258
265
 
259
- module.exports = Delegate
266
+ export { Delegate }
@@ -3,7 +3,7 @@
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2017-2024 Erik Baauw. All rights reserved.
5
5
 
6
- const { CustomHomeKitTypes } = require('../index')
6
+ import { CustomHomeKitTypes } from 'homebridge-lib/CustomHomeKitTypes'
7
7
 
8
8
  // Return long Eve UUID.
9
9
  function uuid (id) {
@@ -14,6 +14,15 @@ function uuid (id) {
14
14
  return `E863F${id}-079E-48FF-8F27-9C2605A29F52`
15
15
  }
16
16
 
17
+ /** Custom HomeKit services and characteristics used by
18
+ * [Eve](https://www.evehome.com/en) accessories and by the
19
+ * [Eve app](https://www.evehome.com/en/eve-app).
20
+ * <br>See {@link EveHomeKitTypes}.
21
+ * @name EveHomeKitTypes
22
+ * @type {Class}
23
+ * @memberof module:homebridge-lib
24
+ */
25
+
17
26
  /** Custom HomeKit Services and Characteristic used by
18
27
  * [Eve](https://www.evehome.com/en) accessories and by the
19
28
  * [Eve app](https://www.evehome.com/en/eve-app).
@@ -691,4 +700,4 @@ class EveHomeKitTypes extends CustomHomeKitTypes {
691
700
  }
692
701
  }
693
702
 
694
- module.exports = EveHomeKitTypes
703
+ export { EveHomeKitTypes }
@@ -0,0 +1,7 @@
1
+ /** HTTP client.
2
+ * <br>See {@link HttpClient}.
3
+ * @name HttpClient
4
+ * @type {Class}
5
+ * @memberof module:homebridge-lib
6
+ */
7
+ export { HttpClient } from 'hb-lib-tools/HttpClient'
@@ -0,0 +1,7 @@
1
+ /** JSON formatter.
2
+ * <br>See {@link JsonFormatter}.
3
+ * @name JsonFormatter
4
+ * @type {Class}
5
+ * @memberof module:homebridge-lib
6
+ */
7
+ export { JsonFormatter } from 'hb-lib-tools/JsonFormatter'
@@ -5,16 +5,21 @@
5
5
  //
6
6
  // My own collection of custom HomeKit Services and Characteristics.
7
7
 
8
- const { CustomHomeKitTypes } = require('../index')
8
+ import { CustomHomeKitTypes } from 'homebridge-lib/CustomHomeKitTypes'
9
9
 
10
10
  function uuid (id) {
11
11
  return MyHomeKitTypes.uuid(id, '-0000-1000-8000-656261617577')
12
12
  }
13
-
14
- /**
15
- * My own collection of custom HomeKit Services and Characteristics.
16
- * @extends CustomHomeKitTypes
17
- */
13
+ /** My own collection of custom HomeKit services and characteristics.
14
+ * <br>See {@link MyHomeKitTypes}.
15
+ * @name MyHomeKitTypes
16
+ * @type {Class}
17
+ * @memberof module:homebridge-lib
18
+ */
19
+
20
+ /** My own collection of custom HomeKit Services and Characteristics.
21
+ * @extends CustomHomeKitTypes
22
+ */
18
23
  class MyHomeKitTypes extends CustomHomeKitTypes {
19
24
  /**
20
25
  * Create my custom HomeKit Services and Characteristics.
@@ -1034,4 +1039,4 @@ class MyHomeKitTypes extends CustomHomeKitTypes {
1034
1039
  }
1035
1040
  }
1036
1041
 
1037
- module.exports = MyHomeKitTypes
1042
+ export { MyHomeKitTypes }
@@ -0,0 +1,12 @@
1
+ // homebridge-lib/lib/OptionParser.js
2
+ //
3
+ // Library for Homebridge plugins.
4
+ // Copyright © 2017-2024 Erik Baauw. All rights reserved.
5
+
6
+ /** Parser and validator for options and other parameters.
7
+ * <br>See {@link OptionParser}.
8
+ * @name OptionParser
9
+ * @type {Class}
10
+ * @memberof module:homebridge-lib
11
+ */
12
+ export { OptionParser } from 'hb-lib-tools/OptionParser'
package/lib/Platform.js CHANGED
@@ -3,37 +3,50 @@
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2017-2024 Erik Baauw. All rights reserved.
5
5
 
6
- 'use strict'
6
+ import { once } from 'node:events'
7
+ import { writeFile, unlink } from 'node:fs/promises'
8
+ import { Server, STATUS_CODES } from 'node:http'
9
+ import { createRequire } from 'node:module'
10
+ import { format, promisify } from 'node:util'
11
+ import zlib from 'node:zlib'
7
12
 
8
- const homebridgeLib = require('../index')
9
- const {
10
- HttpClient, SystemInfo, UpnpClient, formatError, recommendedNodeVersion, semver
11
- } = homebridgeLib
13
+ import { HttpClient } from 'hb-lib-tools/HttpClient'
14
+ import { SystemInfo } from 'hb-lib-tools/SystemInfo'
15
+ import { UpnpClient } from 'hb-lib-tools/UpnpClient'
12
16
 
13
- const events = require('events')
14
- const fs = require('fs')
15
- const http = require('http')
16
- const util = require('util')
17
- const zlib = require('zlib')
17
+ import { Delegate } from 'homebridge-lib/Delegate'
18
+ import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes'
19
+ import { MyHomeKitTypes } from 'homebridge-lib/MyHomeKitTypes'
20
+ import { semver } from 'homebridge-lib/semver'
18
21
 
22
+ import { formatError, recommendedNodeVersion } from 'homebridge-lib'
23
+
24
+ const require = createRequire(import.meta.url)
19
25
  const libPackageJson = require('../package.json')
20
26
 
21
27
  const uuid = /^[0-9A-F]{8}-[0-9A-F]{4}-[1-5][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/
22
- const gzip = util.promisify(zlib.gzip)
28
+ const gzip = promisify(zlib.gzip)
23
29
 
24
30
  const context = {
25
31
  libName: libPackageJson.name,
26
32
  libVersion: libPackageJson.version,
27
33
  nodeVersion: process.version.slice(1),
28
34
  recommendedNodeVersion: recommendedNodeVersion(libPackageJson),
29
- recommendedHomebridgeVersion:
30
- semver.minVersion(libPackageJson.engines.homebridge).toString(),
35
+ // recommendedHomebridgeVersion:
36
+ // semver.minVersion(libPackageJson.engines.homebridge).toString(),
31
37
  saveInterval: 3600,
32
38
  checkInterval: 7 * 24 * 3600,
33
39
  driftDebugThreshold: 250,
34
40
  driftWarningThreshold: 2500
35
41
  }
36
42
 
43
+ /** Homebridge dynamic platform plugin.
44
+ * <br>See {@link Platform}.
45
+ * @name Platform
46
+ * @type {Class}
47
+ * @memberof module:homebridge-lib
48
+ */
49
+
37
50
  /** Homebridge dynamic platform plugin.
38
51
  *
39
52
  * `Platform` provides the following features to a platform plugin:
@@ -49,7 +62,7 @@ const context = {
49
62
  * @abstract
50
63
  * @extends Delegate
51
64
  */
52
- class Platform extends homebridgeLib.Delegate {
65
+ class Platform extends Delegate {
53
66
  /** Load the platform plugin.
54
67
  *
55
68
  * Called by Homebridge, through the plugin's `index.js`, when loading the
@@ -67,6 +80,9 @@ class Platform extends homebridgeLib.Delegate {
67
80
  context.homebridge = homebridge
68
81
  context.homebridgeVersion = homebridge.serverVersion
69
82
  context.PlatformAccessory = homebridge.platformAccessory
83
+ context.recommendedHomebridgeVersion =
84
+ semver.minVersion(libPackageJson.engines.homebridge).toString()
85
+
70
86
  const hap = {
71
87
  Services: {},
72
88
  Characteristics: {}
@@ -81,8 +97,8 @@ class Platform extends homebridgeLib.Delegate {
81
97
  }).forEach((key) => {
82
98
  hap.Characteristics[key] = homebridge.hap.Characteristic[key]
83
99
  })
84
- const eve = new homebridgeLib.EveHomeKitTypes(homebridge)
85
- const my = new homebridgeLib.MyHomeKitTypes(homebridge)
100
+ const eve = new EveHomeKitTypes(homebridge)
101
+ const my = new MyHomeKitTypes(homebridge)
86
102
 
87
103
  context.Accessory = Object.freeze({
88
104
  Categories: Object.freeze(Object.assign({}, homebridge.hap.Categories))
@@ -105,6 +121,11 @@ class Platform extends homebridgeLib.Delegate {
105
121
  })
106
122
  }
107
123
  context[Platform.name] = { packageJson, platformName }
124
+ // console.log(
125
+ // '%s v%s, node v%s, homebridge v%s, %s v%s',
126
+ // packageJson.name, packageJson.version, context.nodeVersion,
127
+ // context.homebridgeVersion, context.libName, context.libVersion
128
+ // )
108
129
  homebridge.registerPlatform(
109
130
  packageJson.name, platformName, Platform, true
110
131
  )
@@ -170,9 +191,6 @@ class Platform extends homebridgeLib.Delegate {
170
191
  // Main platform function.
171
192
  // Called by homebridge after restoring accessories from cache.
172
193
  async _main () {
173
- // process.on('unhandledRejection', (error) => {
174
- // this.error('unhandled rejection: %s', error.stack)
175
- // })
176
194
  /** System information.
177
195
  * @type {SystemInfo}
178
196
  * @readonly
@@ -204,7 +222,7 @@ class Platform extends homebridgeLib.Delegate {
204
222
  await this._createUiServer()
205
223
  } catch (error) { this.error(error) }
206
224
  }
207
- await events.once(this, 'initialised')
225
+ await once(this, 'initialised')
208
226
  this._flushCachedAccessories()
209
227
  for (const id in this._accessories) {
210
228
  if (this._accessoryDelegates[id] == null) {
@@ -248,7 +266,7 @@ class Platform extends homebridgeLib.Delegate {
248
266
  this._pluginName + '.json.gz'
249
267
  try {
250
268
  const data = await gzip(JSON.stringify(Object.assign(result, dumpInfo)))
251
- await fs.promises.writeFile(filename, data)
269
+ await writeFile(filename, data)
252
270
  this.log('created debug dump file %s', filename)
253
271
  } catch (error) {
254
272
  this.error('%s: %s', filename, error)
@@ -526,7 +544,7 @@ class Platform extends homebridgeLib.Delegate {
526
544
  const historyFile = accessory.context.historyFile
527
545
  if (historyFile) {
528
546
  this.debug('remove history file %s', historyFile)
529
- fs.unlink(historyFile, (error) => {
547
+ unlink(historyFile, (error) => {
530
548
  if (error) {
531
549
  this.warn(error)
532
550
  }
@@ -611,7 +629,7 @@ class Platform extends homebridgeLib.Delegate {
611
629
  // Create HTTP server for Homebridge Plugin UI Settings.
612
630
  async _createUiServer () {
613
631
  this._ui = {}
614
- this._ui.server = new http.Server()
632
+ this._ui.server = new Server()
615
633
  this._ui.server
616
634
  .on('listening', () => {
617
635
  this._ui.port = this._ui.server.address().port
@@ -660,7 +678,7 @@ class Platform extends homebridgeLib.Delegate {
660
678
  )
661
679
  this.debug(
662
680
  'ui request %d: %d %s', this._ui.requestId,
663
- status, http.STATUS_CODES[status]
681
+ status, STATUS_CODES[status]
664
682
  )
665
683
  if (status === 200) {
666
684
  this.vdebug('ui request %d: response: %j', this._ui.requestId, body)
@@ -684,7 +702,7 @@ class Platform extends homebridgeLib.Delegate {
684
702
  host: '127.0.0.1',
685
703
  signal: this._ui.abortController.signal
686
704
  })
687
- await events.once(this._ui.server, 'listening')
705
+ await once(this._ui.server, 'listening')
688
706
  }
689
707
 
690
708
  // ===== Logging =============================================================
@@ -707,7 +725,7 @@ class Platform extends homebridgeLib.Delegate {
707
725
  if (args[0] == null) {
708
726
  message = ''
709
727
  } else if (typeof (args[0]) === 'string') {
710
- message = util.format(...args)
728
+ message = format(...args)
711
729
  } else {
712
730
  throw new TypeError('format: not a string or instance of Error')
713
731
  }
@@ -740,4 +758,4 @@ class Platform extends homebridgeLib.Delegate {
740
758
  }
741
759
  }
742
760
 
743
- module.exports = Platform
761
+ export { Platform }
@@ -3,9 +3,15 @@
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2017-2024 Erik Baauw. All rights reserved.
5
5
 
6
- 'use strict'
6
+ import { AccessoryDelegate } from 'homebridge-lib/AccessoryDelegate'
7
+ import { Delegate } from 'homebridge-lib/Delegate'
7
8
 
8
- const homebridgeLib = require('../index')
9
+ /** Delegate of a property of a HomeKit accessory or service.
10
+ * <br>See {@link PropertyDelegate}.
11
+ * @name PropertyDelegate
12
+ * @type {Class}
13
+ * @memberof module:homebridge-lib
14
+ */
9
15
 
10
16
  /** Delegate of a property of a delegate of a HomeKit accessory or HomeKit
11
17
  * service.
@@ -18,7 +24,7 @@ const homebridgeLib = require('../index')
18
24
  *
19
25
  * @extends Delegate
20
26
  */
21
- class PropertyDelegate extends homebridgeLib.Delegate {
27
+ class PropertyDelegate extends Delegate {
22
28
  /** Instantiate a property delegate.
23
29
  *
24
30
  * Note that instances are normally created by invoking
@@ -40,7 +46,7 @@ class PropertyDelegate extends homebridgeLib.Delegate {
40
46
  * optional parameter is not applicable.
41
47
  */
42
48
  constructor (parent, params = {}) {
43
- if (!(parent instanceof homebridgeLib.AccessoryDelegate)) {
49
+ if (!(parent instanceof AccessoryDelegate)) {
44
50
  throw new TypeError('parent: not an AccessoryDelegate')
45
51
  }
46
52
  super(parent.platform, parent.name + ': ' + params.key)
@@ -134,4 +140,4 @@ class PropertyDelegate extends homebridgeLib.Delegate {
134
140
  }
135
141
  }
136
142
 
137
- module.exports = PropertyDelegate
143
+ export { PropertyDelegate }
@@ -3,9 +3,7 @@
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2017-2024 Erik Baauw. All rights reserved.
5
5
 
6
- 'use strict'
7
-
8
- const { ServiceDelegate } = require('../../index')
6
+ import { ServiceDelegate } from 'homebridge-lib/ServiceDelegate'
9
7
 
10
8
  /** Class for an _AccessoryInformation_ service delegate.
11
9
  *
@@ -111,4 +109,4 @@ class AccessoryInformation extends ServiceDelegate {
111
109
  }
112
110
  }
113
111
 
114
- module.exports = AccessoryInformation
112
+ ServiceDelegate.AccessoryInformation = AccessoryInformation
@@ -3,9 +3,7 @@
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2017-2024 Erik Baauw. All rights reserved.
5
5
 
6
- 'use strict'
7
-
8
- const { ServiceDelegate } = require('../../index')
6
+ import { ServiceDelegate } from 'homebridge-lib/ServiceDelegate'
9
7
 
10
8
  /** Class for a _Battery_ service delegate.
11
9
  *
@@ -105,4 +103,4 @@ class Battery extends ServiceDelegate {
105
103
  }
106
104
  }
107
105
 
108
- module.exports = Battery
106
+ ServiceDelegate.Battery = Battery
@@ -3,9 +3,7 @@
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2017-2024 Erik Baauw. All rights reserved.
5
5
 
6
- 'use strict'
7
-
8
- const { ServiceDelegate } = require('../../index')
6
+ import { ServiceDelegate } from 'homebridge-lib/ServiceDelegate'
9
7
 
10
8
  /** Class for a delegate for a dummy _StatelessProgrammableSwitch_ service.
11
9
  *
@@ -44,4 +42,4 @@ class Dummy extends ServiceDelegate {
44
42
  }
45
43
  }
46
44
 
47
- module.exports = Dummy
45
+ ServiceDelegate.Dummy = Dummy
@@ -7,9 +7,8 @@
7
7
  // fakagato-history repository, copyright © 2017 simont77.
8
8
  // See https://github.com/simont77/fakegato-history.
9
9
 
10
- 'use strict'
11
-
12
- const { CharacteristicDelegate, ServiceDelegate } = require('../../index')
10
+ import { CharacteristicDelegate } from 'homebridge-lib/CharacteristicDelegate'
11
+ import { ServiceDelegate } from 'homebridge-lib/ServiceDelegate'
13
12
 
14
13
  // Eve history keeps time as # seconds since epoch of 2001/01/01.
15
14
  // @type {integer}
@@ -749,4 +748,4 @@ class History extends ServiceDelegate {
749
748
  }
750
749
  }
751
750
 
752
- module.exports = History
751
+ ServiceDelegate.History = History
@@ -3,9 +3,7 @@
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2017-2024 Erik Baauw. All rights reserved.
5
5
 
6
- 'use strict'
7
-
8
- const { ServiceDelegate } = require('../../index')
6
+ import { ServiceDelegate } from 'homebridge-lib/ServiceDelegate'
9
7
 
10
8
  /** Class for a _ServiceLabel_ service delegate.
11
9
  *
@@ -47,4 +45,4 @@ class ServiceLabel extends ServiceDelegate {
47
45
  }
48
46
  }
49
47
 
50
- module.exports = ServiceLabel
48
+ ServiceDelegate.ServiceLabel = ServiceLabel
@@ -1,11 +1,18 @@
1
- // homebridge-lib/lib/ServiceDelegate/index.js
1
+ // homebridge-lib/lib/ServiceDelegate.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2017-2024 Erik Baauw. All rights reserved.
5
5
 
6
- 'use strict'
6
+ import { AccessoryDelegate } from 'homebridge-lib/AccessoryDelegate'
7
+ import { CharacteristicDelegate } from 'homebridge-lib/CharacteristicDelegate'
8
+ import { Delegate } from 'homebridge-lib/Delegate'
7
9
 
8
- const homebridgeLib = require('../../index')
10
+ /** Delegate of a HomeKit service.
11
+ * <br>See {@link ServiceDelegate}.
12
+ * @name ServiceDelegate
13
+ * @type {Class}
14
+ * @memberof module:homebridge-lib
15
+ */
9
16
 
10
17
  /** Delegate of a HomeKit service.
11
18
  *
@@ -19,13 +26,7 @@ const homebridgeLib = require('../../index')
19
26
  * @abstract
20
27
  * @extends Delegate
21
28
  */
22
- class ServiceDelegate extends homebridgeLib.Delegate {
23
- static get AccessoryInformation () { return require('./AccessoryInformation') }
24
- static get Battery () { return require('./Battery') }
25
- static get Dummy () { return require('./Dummy') }
26
- static get History () { return require('./History') }
27
- static get ServiceLabel () { return require('./ServiceLabel') }
28
-
29
+ class ServiceDelegate extends Delegate {
29
30
  /** Create a new instance of a HomeKit service delegate.
30
31
  *
31
32
  * When the associated HomeKit service was restored from persistent
@@ -49,7 +50,7 @@ class ServiceDelegate extends homebridgeLib.Delegate {
49
50
  * @params {?boolean} params.hidden - Hidden service.
50
51
  */
51
52
  constructor (accessoryDelegate, params = {}) {
52
- if (!(accessoryDelegate instanceof homebridgeLib.AccessoryDelegate)) {
53
+ if (!(accessoryDelegate instanceof AccessoryDelegate)) {
53
54
  throw new TypeError('parent: not a AccessoryDelegate')
54
55
  }
55
56
  if (params.name == null) {
@@ -229,7 +230,7 @@ class ServiceDelegate extends homebridgeLib.Delegate {
229
230
  throw new SyntaxError(`${key}: duplicate key`)
230
231
  }
231
232
 
232
- const characteristicDelegate = new homebridgeLib.CharacteristicDelegate(
233
+ const characteristicDelegate = new CharacteristicDelegate(
233
234
  this, params
234
235
  )
235
236
  this._characteristicDelegates[key] = characteristicDelegate
@@ -318,4 +319,4 @@ class ServiceDelegate extends homebridgeLib.Delegate {
318
319
  }
319
320
  }
320
321
 
321
- module.exports = ServiceDelegate
322
+ export { ServiceDelegate }
@@ -0,0 +1,12 @@
1
+ // homebridge-lib/lib/SystemInfo.js
2
+ //
3
+ // Library for Homebridge plugins.
4
+ // Copyright © 2020-2024 Erik Baauw. All rights reserved.
5
+
6
+ /** System information.
7
+ * <br>See {@link SystemInfo}.
8
+ * @name SystemInfo
9
+ * @type {Class}
10
+ * @memberof module:homebridge-lib
11
+ */
12
+ export { SystemInfo } from 'hb-lib-tools/SystemInfo'
package/lib/UiServer.js CHANGED
@@ -3,15 +3,23 @@
3
3
  // Library for Homebridge plugins.
4
4
  // Copyright © 2022-2024 Erik Baauw. All rights reserved.
5
5
 
6
- 'use strict'
7
-
8
- const {
9
- HomebridgePluginUiServer // , RequestError
10
- } = require('@homebridge/plugin-ui-utils')
11
- const { HttpClient, chalk, formatError } = require('../index')
12
- const fs = require('fs').promises
13
- const path = require('path')
14
- const util = require('util')
6
+ import { readFile } from 'node:fs/promises'
7
+ import { join } from 'node:path'
8
+ import { format } from 'node:util'
9
+
10
+ // Somehow this causes Homebridge to crash with SIGTERM after ~9 seconds.
11
+ import { HomebridgePluginUiServer } from '@homebridge/plugin-ui-utils'
12
+
13
+ import { formatError } from 'hb-lib-tools'
14
+ import { chalk } from 'hb-lib-tools/chalk'
15
+ import { HttpClient } from 'hb-lib-tools/HttpClient'
16
+
17
+ /** Server for dynamic configuration settings through Homebridge UI.
18
+ * <br>See {@link UiServer}.
19
+ * @name UiServer
20
+ * @type {Class}
21
+ * @memberof module:homebridge-lib
22
+ */
15
23
 
16
24
  /** Server for handling Homebridge Plugin UI requests.
17
25
  *
@@ -93,12 +101,12 @@ class UiServer extends HomebridgePluginUiServer {
93
101
  if (username != null) {
94
102
  fileName += '.' + username.replace(/:/g, '').toUpperCase()
95
103
  }
96
- const fullFileName = path.join(
104
+ const fullFileName = join(
97
105
  this.homebridgeStoragePath,
98
106
  'accessories',
99
107
  fileName
100
108
  )
101
- const json = await fs.readFile(fullFileName)
109
+ const json = await readFile(fullFileName)
102
110
  const cachedAccessories = JSON.parse(json)
103
111
  return cachedAccessories
104
112
  } catch (error) {
@@ -219,9 +227,9 @@ class UiServer extends HomebridgePluginUiServer {
219
227
  if (args[0] == null) {
220
228
  message = ''
221
229
  } else if (typeof args[0] === 'string') {
222
- message = util.format(...args)
230
+ message = format(...args)
223
231
  } else {
224
- message = util.format('%o', ...args)
232
+ message = format('%o', ...args)
225
233
  }
226
234
 
227
235
  // Handle colours.
@@ -233,4 +241,4 @@ class UiServer extends HomebridgePluginUiServer {
233
241
  }
234
242
  }
235
243
 
236
- module.exports = UiServer
244
+ export { UiServer }
@@ -0,0 +1,12 @@
1
+ // homebridge-lib/lib/UpnpClient.js
2
+ //
3
+ // Library for Homebridge plugins.
4
+ // Copyright © 2020-2024 Erik Baauw. All rights reserved.
5
+
6
+ /** Universal Plug and Play client.
7
+ * <br>See {@link UpnpClient}.
8
+ * @name UpnpClient
9
+ * @type {Class}
10
+ * @memberof module:homebridge-lib
11
+ */
12
+ export { UpnpClient } from 'hb-lib-tools/UpnpClient'
package/lib/chalk.js ADDED
@@ -0,0 +1,11 @@
1
+ // homebridge-lib/lib/chalk.js
2
+ //
3
+ // Library for Homebridge plugins.
4
+ // Copyright © 2020-2024 Erik Baauw. All rights reserved.
5
+
6
+ /** Return the [`chalk`](https://github.com/chalk/chalk) module,
7
+ * so plugins don't have to list this as a separate dependency.
8
+ * @name chalk
9
+ * @memberof module:homebridge-lib
10
+ */
11
+ export { chalk } from 'hb-lib-tools/chalk'
package/lib/semver.js ADDED
@@ -0,0 +1,11 @@
1
+ // homebridge-lib/lib/semver.js
2
+ //
3
+ // Library for Homebridge plugins.
4
+ // Copyright © 2020-2024 Erik Baauw. All rights reserved.
5
+
6
+ /** Return the [`semver`](https://github.com/npm/node-semver) module,
7
+ * so plugins don't have to list this as a separate dependency.
8
+ * @name semver
9
+ * @memberof module:homebridge-lib
10
+ */
11
+ export { semver } from 'hb-lib-tools/semver'
package/package.json CHANGED
@@ -3,12 +3,17 @@
3
3
  "description": "Library for homebridge plugins",
4
4
  "author": "Erik Baauw",
5
5
  "license": "Apache-2.0",
6
- "version": "6.7.5",
6
+ "version": "7.0.0-1",
7
7
  "keywords": [
8
8
  "homekit",
9
9
  "homebridge"
10
10
  ],
11
+ "type": "module",
11
12
  "main": "index.js",
13
+ "exports": {
14
+ ".": "./index.js",
15
+ "./*": "./lib/*.js"
16
+ },
12
17
  "files": [
13
18
  "index.js",
14
19
  "lib",
@@ -21,12 +26,12 @@
21
26
  "upnp": "cli/upnp.js"
22
27
  },
23
28
  "engines": {
24
- "homebridge": "^1.7.0",
25
- "node": "20.12.0||^20||^18"
29
+ "homebridge": "^1.8.1",
30
+ "node": "20.12.2||^20||^18"
26
31
  },
27
32
  "dependencies": {
28
- "@homebridge/plugin-ui-utils": "~1.0.1",
29
- "hb-lib-tools": "~1.2.4"
33
+ "@homebridge/plugin-ui-utils": "~1.0.3",
34
+ "hb-lib-tools": "~2.0.0-2"
30
35
  },
31
36
  "scripts": {
32
37
  "prepare": "standard && rm -rf out && jsdoc -c jsdoc.json",