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 +2 -4
- package/cli/json.js +2 -4
- package/cli/sysinfo.js +2 -4
- package/cli/upnp.js +2 -4
- package/index.js +226 -207
- package/lib/AccessoryDelegate.js +7 -9
- package/lib/AdaptiveLighting.js +2 -4
- package/lib/CharacteristicDelegate.js +5 -7
- package/lib/CustomHomeKitTypes.js +1 -1
- package/lib/Delegate.js +5 -8
- package/lib/EveHomeKitTypes.js +2 -2
- package/lib/MyHomeKitTypes.js +2 -2
- package/lib/Platform.js +43 -33
- package/lib/PropertyDelegate.js +4 -6
- package/lib/ServiceDelegate/AccessoryInformation.js +2 -4
- package/lib/ServiceDelegate/Battery.js +2 -4
- package/lib/ServiceDelegate/Dummy.js +2 -4
- package/lib/ServiceDelegate/History.js +2 -4
- package/lib/ServiceDelegate/ServiceLabel.js +2 -4
- package/lib/ServiceDelegate/index.js +13 -12
- package/lib/UiServer.js +12 -13
- package/package.json +5 -4
package/cli/hap.js
CHANGED
package/cli/json.js
CHANGED
package/cli/sysinfo.js
CHANGED
package/cli/upnp.js
CHANGED
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
|
-
*
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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'
|
package/lib/AccessoryDelegate.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
// Library for Homebridge plugins.
|
|
4
4
|
// Copyright © 2017-2024 Erik Baauw. All rights reserved.
|
|
5
5
|
|
|
6
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
307
|
-
!(delegate instanceof
|
|
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
|
-
|
|
330
|
+
export { AccessoryDelegate }
|
package/lib/AdaptiveLighting.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
// Library for Homebridge plugins.
|
|
4
4
|
// Copyright © 2020-2024 Erik Baauw. All rights reserved.
|
|
5
5
|
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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 =
|
|
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
|
-
|
|
452
|
+
export { CharacteristicDelegate }
|
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
|
-
|
|
6
|
+
import { EventEmitter } from 'node:events'
|
|
7
7
|
|
|
8
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
256
|
+
export { Delegate }
|
package/lib/EveHomeKitTypes.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Library for Homebridge plugins.
|
|
4
4
|
// Copyright © 2017-2024 Erik Baauw. All rights reserved.
|
|
5
5
|
|
|
6
|
-
|
|
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
|
-
|
|
694
|
+
export { EveHomeKitTypes }
|
package/lib/MyHomeKitTypes.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
//
|
|
6
6
|
// My own collection of custom HomeKit Services and Characteristics.
|
|
7
7
|
|
|
8
|
-
|
|
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
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const libPackageJson =
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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 {!
|
|
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,
|
|
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
|
|
85
|
-
const my = new
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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,
|
|
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
|
|
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 =
|
|
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
|
-
|
|
753
|
+
export { Platform }
|
package/lib/PropertyDelegate.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
// Library for Homebridge plugins.
|
|
4
4
|
// Copyright © 2017-2024 Erik Baauw. All rights reserved.
|
|
5
5
|
|
|
6
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
23
|
-
static get AccessoryInformation () { return
|
|
24
|
-
static get Battery () { return
|
|
25
|
-
static get Dummy () { return
|
|
26
|
-
static get History () { return
|
|
27
|
-
static get ServiceLabel () { return
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
6
|
+
import { readFile } from 'node:fs/promises'
|
|
7
|
+
import { join } from 'node:path'
|
|
8
|
+
import { format } from 'node:util'
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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 =
|
|
95
|
+
const fullFileName = join(
|
|
97
96
|
this.homebridgeStoragePath,
|
|
98
97
|
'accessories',
|
|
99
98
|
fileName
|
|
100
99
|
)
|
|
101
|
-
const json = await
|
|
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 =
|
|
221
|
+
message = format(...args)
|
|
223
222
|
} else {
|
|
224
|
-
message =
|
|
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
|
-
|
|
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
|
+
"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.
|
|
26
|
+
"node": "20.12.2||^20||^18"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@homebridge/plugin-ui-utils": "~1.0.
|
|
29
|
-
"hb-lib-tools": "~
|
|
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",
|