homebridge-lib 6.7.4 → 7.0.0-0

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