homebridge-nest-accfactory 0.2.11 → 0.3.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/CHANGELOG.md +24 -0
- package/README.md +14 -7
- package/config.schema.json +118 -0
- package/dist/HomeKitDevice.js +194 -77
- package/dist/HomeKitHistory.js +1 -1
- package/dist/config.js +207 -0
- package/dist/devices.js +113 -0
- package/dist/index.js +2 -1
- package/dist/nexustalk.js +19 -21
- package/dist/{camera.js → plugins/camera.js} +212 -239
- package/dist/{doorbell.js → plugins/doorbell.js} +32 -30
- package/dist/plugins/floodlight.js +91 -0
- package/dist/plugins/heatlink.js +17 -0
- package/dist/{protect.js → plugins/protect.js} +24 -41
- package/dist/{tempsensor.js → plugins/tempsensor.js} +13 -17
- package/dist/{thermostat.js → plugins/thermostat.js} +424 -381
- package/dist/{weather.js → plugins/weather.js} +26 -60
- package/dist/protobuf/nest/services/apigateway.proto +31 -1
- package/dist/protobuf/nest/trait/firmware.proto +207 -89
- package/dist/protobuf/nest/trait/hvac.proto +1052 -312
- package/dist/protobuf/nest/trait/located.proto +51 -8
- package/dist/protobuf/nest/trait/network.proto +366 -36
- package/dist/protobuf/nest/trait/occupancy.proto +145 -17
- package/dist/protobuf/nest/trait/product/protect.proto +57 -43
- package/dist/protobuf/nest/trait/resourcedirectory.proto +8 -0
- package/dist/protobuf/nest/trait/sensor.proto +7 -1
- package/dist/protobuf/nest/trait/service.proto +3 -1
- package/dist/protobuf/nest/trait/structure.proto +60 -14
- package/dist/protobuf/nest/trait/ui.proto +41 -1
- package/dist/protobuf/nest/trait/user.proto +6 -1
- package/dist/protobuf/nest/trait/voiceassistant.proto +2 -1
- package/dist/protobuf/nestlabs/eventingapi/v1.proto +20 -1
- package/dist/protobuf/root.proto +1 -0
- package/dist/protobuf/wdl.proto +18 -2
- package/dist/protobuf/weave/common.proto +2 -1
- package/dist/protobuf/weave/trait/heartbeat.proto +41 -1
- package/dist/protobuf/weave/trait/power.proto +1 -0
- package/dist/protobuf/weave/trait/security.proto +10 -1
- package/dist/streamer.js +68 -72
- package/dist/system.js +1208 -1245
- package/dist/webrtc.js +28 -23
- package/package.json +12 -12
- package/dist/floodlight.js +0 -97
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `homebridge-nest-accfactory` will be documented in this file. This project tries to adhere to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
|
|
5
|
+
## v0.3.0 (2025/06/14)
|
|
6
|
+
|
|
7
|
+
- General code cleanup and stability improvements
|
|
8
|
+
- Introduced plugin-style architecture for Nest/Google devices
|
|
9
|
+
- Updated README.md to reflect changes to the devices section in configuration
|
|
10
|
+
- Prevent excluded devices from being restored from Homebridge cache
|
|
11
|
+
- Added internal support for selecting active temperature sensor (not yet exposed to HomeKit)
|
|
12
|
+
- Fixed loss of custom devices section when using the plugin config UI
|
|
13
|
+
- Fixed motion services being recreated when restored from Homebridge cache
|
|
14
|
+
- Fixed missing devices for Nest FieldTest accounts
|
|
15
|
+
- Added hot water heating boost (on/off) support for compatible EU/UK Thermostats
|
|
16
|
+
- Added support for Nest Heat Link devices as room temperature sensors
|
|
17
|
+
|
|
18
|
+
### Deprecation Notice
|
|
19
|
+
- Support for the standalone Docker version of this plugin is planned to be deprecated in an upcoming release. While it currently remains functional, future updates may no longer include Docker-specific build support. Users are encouraged to transition to standard Homebridge installations where possible.
|
|
20
|
+
|
|
21
|
+
### Known Issues
|
|
22
|
+
|
|
23
|
+
- Audio from newer Nest/Google cameras and doorbells is currently silent (blank audio output)
|
|
24
|
+
- The ip npm package has a known security advisory [GHSA-2p57-rm9w-gvfp](https://github.com/advisories/GHSA-2p57-rm9w-gvfp); this is used indirectly via the werift library
|
|
25
|
+
|
|
26
|
+
### Thanks
|
|
27
|
+
Special thanks to [@Daniel](https://github.com/no1knows) and [@Brad](https://github.com/bcullman) for testing and feedback on this release!
|
|
28
|
+
|
|
5
29
|
## v0.2.11 (2025/04/17)
|
|
6
30
|
|
|
7
31
|
- General code cleanup and bug fixes
|
package/README.md
CHANGED
|
@@ -23,8 +23,12 @@ The following Nest devices are known to be supported
|
|
|
23
23
|
* Nest Temp Sensors (1st gen)
|
|
24
24
|
* Nest Cameras (Cam Indoor, IQ Indoor, Outdoor, IQ Outdoor, Cam with Floodlight)
|
|
25
25
|
* Nest Doorbells (wired 1st gen)
|
|
26
|
+
* Nest HeatLink
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
**Note:** Google has announced it will discontinue support for 1st and 2nd generation Nest Thermostats as of **October 25, 2025**.
|
|
29
|
+
Based on their stated intentions, these models are expected to stop functioning with this Homebridge plugin after that date.
|
|
30
|
+
|
|
31
|
+
The accessory supports connection to Nest using a Nest account AND/OR a Google (migrated Nest account) account.
|
|
28
32
|
|
|
29
33
|
## Configuration
|
|
30
34
|
|
|
@@ -79,14 +83,15 @@ Sample config.json entries below
|
|
|
79
83
|
"elevation": 600,
|
|
80
84
|
"hksv": false
|
|
81
85
|
},
|
|
82
|
-
"devices":
|
|
83
|
-
|
|
86
|
+
"devices": [
|
|
87
|
+
{
|
|
88
|
+
"serialNumber": "XXXXXXXX",
|
|
84
89
|
"exclude": false
|
|
85
90
|
},
|
|
86
|
-
|
|
91
|
+
"serialNumber": "YYYYYYYY",
|
|
87
92
|
"hksv" : true
|
|
88
93
|
}
|
|
89
|
-
|
|
94
|
+
],
|
|
90
95
|
"platform": "NestAccfactory"
|
|
91
96
|
}
|
|
92
97
|
```
|
|
@@ -99,15 +104,15 @@ The following options are available in the config.json options object. These app
|
|
|
99
104
|
|-------------------|-----------------------------------------------------------------------------------------------|----------------|
|
|
100
105
|
| elevation | Height above sea level for the weather station | 0 |
|
|
101
106
|
| eveHistory | Provide history in EveHome application where applicable | true |
|
|
107
|
+
| exclude | Exclude ALL devices | false |
|
|
102
108
|
| ffmegDebug | Turns on specific debugging output for when ffmpeg is envoked | false |
|
|
103
109
|
| ffmegPath | Path to an ffmpeg binary for us to use | /usr/local/bin |
|
|
104
110
|
| hksv | Enable HomeKit Secure Video for supported camera(s) and doorbell(s) | false |
|
|
105
|
-
| maxStreams | Maximum number of concurrent video streams in HomeKit for supported camera(s) and doorbell(s) | 2 |
|
|
106
111
|
| weather | Virtual weather station for each Nest/Google home we discover | false |
|
|
107
112
|
|
|
108
113
|
#### devices
|
|
109
114
|
|
|
110
|
-
The following options are available on a per-device level in the config.json devices
|
|
115
|
+
The following options are available on a per-device level in the `config.json` `devices` array. Each device is specified as a JSON object, and the device is identified using the `"serialNumber"` key with the value of its serial number (in uppercase).
|
|
111
116
|
|
|
112
117
|
| Name | Description | Default |
|
|
113
118
|
|-------------------|-----------------------------------------------------------------------------------------------|----------------|
|
|
@@ -118,10 +123,12 @@ The following options are available on a per-device level in the config.json dev
|
|
|
118
123
|
| exclude | Exclude the device | false |
|
|
119
124
|
| ffmegDebug | Turns on specific debugging output for when ffmpeg is envoked | false |
|
|
120
125
|
| hksv | Enable HomeKit Secure Video for supported camera(s) and doorbell(s) | false |
|
|
126
|
+
| hotWaterBoostTime | Time in seconds for hotwater boost heating | 1800 |
|
|
121
127
|
| humiditySensor | Create a seperate humidity sensor for supported thermostat(s) | false |
|
|
122
128
|
| localAccess | Use direct access to supported camera(s) and doorbell(s) for video streaming and recording | false |
|
|
123
129
|
| motionCooldown | Time in seconds between detected motion events | 60 |
|
|
124
130
|
| personCooldown | Time in seconds between detected person events | 120 |
|
|
131
|
+
| serialNumber | Device serial number to which these settings belong too | |
|
|
125
132
|
|
|
126
133
|
## ffmpeg
|
|
127
134
|
|
package/config.schema.json
CHANGED
|
@@ -105,6 +105,84 @@
|
|
|
105
105
|
"type": "string",
|
|
106
106
|
"placeholder": "Path to an ffmpeg binary",
|
|
107
107
|
"default": "/usr/local/bin/ffmpeg"
|
|
108
|
+
},
|
|
109
|
+
"ffmegDebug": {
|
|
110
|
+
"type": "boolean"
|
|
111
|
+
},
|
|
112
|
+
"maxStreams": {
|
|
113
|
+
"type": "integer"
|
|
114
|
+
},
|
|
115
|
+
"exclude": {
|
|
116
|
+
"type": "boolean"
|
|
117
|
+
},
|
|
118
|
+
"useNestAPI": {
|
|
119
|
+
"type": "boolean"
|
|
120
|
+
},
|
|
121
|
+
"useGoogleAPI": {
|
|
122
|
+
"type": "boolean"
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"devices": {
|
|
127
|
+
"title": "Per device configuration options",
|
|
128
|
+
"type": "array",
|
|
129
|
+
"items": {
|
|
130
|
+
"title": "Device",
|
|
131
|
+
"type": "object",
|
|
132
|
+
"properties": {
|
|
133
|
+
"serialNumber": {
|
|
134
|
+
"title": "Device Serial Number",
|
|
135
|
+
"type": "string",
|
|
136
|
+
"required": true
|
|
137
|
+
},
|
|
138
|
+
"chimeSwitch": {
|
|
139
|
+
"type": "boolean"
|
|
140
|
+
},
|
|
141
|
+
"doorbellCooldown": {
|
|
142
|
+
"type": "number"
|
|
143
|
+
},
|
|
144
|
+
"elevation": {
|
|
145
|
+
"type": "number"
|
|
146
|
+
},
|
|
147
|
+
"eveHistory": {
|
|
148
|
+
"type": "boolean"
|
|
149
|
+
},
|
|
150
|
+
"exclude": {
|
|
151
|
+
"type": "boolean"
|
|
152
|
+
},
|
|
153
|
+
"externalCool": {
|
|
154
|
+
"type": "string"
|
|
155
|
+
},
|
|
156
|
+
"externalDehumidifier": {
|
|
157
|
+
"type": "string"
|
|
158
|
+
},
|
|
159
|
+
"externalFan": {
|
|
160
|
+
"type": "string"
|
|
161
|
+
},
|
|
162
|
+
"externalHeat": {
|
|
163
|
+
"type": "string"
|
|
164
|
+
},
|
|
165
|
+
"ffmegDebug": {
|
|
166
|
+
"type": "boolean"
|
|
167
|
+
},
|
|
168
|
+
"hkPairingCode": {
|
|
169
|
+
"type": "string"
|
|
170
|
+
},
|
|
171
|
+
"hksv": {
|
|
172
|
+
"type": "boolean"
|
|
173
|
+
},
|
|
174
|
+
"humiditySensor": {
|
|
175
|
+
"type": "boolean"
|
|
176
|
+
},
|
|
177
|
+
"localAccess": {
|
|
178
|
+
"type": "boolean"
|
|
179
|
+
},
|
|
180
|
+
"motionCooldown": {
|
|
181
|
+
"type": "number"
|
|
182
|
+
},
|
|
183
|
+
"personCooldown": {
|
|
184
|
+
"type": "number"
|
|
185
|
+
}
|
|
108
186
|
}
|
|
109
187
|
}
|
|
110
188
|
}
|
|
@@ -117,5 +195,45 @@
|
|
|
117
195
|
{
|
|
118
196
|
"required": ["google"]
|
|
119
197
|
}
|
|
198
|
+
],
|
|
199
|
+
"layout": [
|
|
200
|
+
{
|
|
201
|
+
"type": "fieldset",
|
|
202
|
+
"title": "Nest Account",
|
|
203
|
+
"expandable": true,
|
|
204
|
+
"expanded": {
|
|
205
|
+
"functionBody": "return model.nest && model.nest.access_token"
|
|
206
|
+
},
|
|
207
|
+
"items": [
|
|
208
|
+
"nest.access_token",
|
|
209
|
+
"nest.fieldTest"
|
|
210
|
+
]
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"type": "fieldset",
|
|
214
|
+
"title": "Google Account",
|
|
215
|
+
"expandable": true,
|
|
216
|
+
"expanded": {
|
|
217
|
+
"functionBody": "return model.google && model.google.issuetoken && model.google.cookie"
|
|
218
|
+
},
|
|
219
|
+
"items": [
|
|
220
|
+
"google.issuetoken",
|
|
221
|
+
"google.cookie",
|
|
222
|
+
"google.fieldTest"
|
|
223
|
+
]
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
"type": "fieldset",
|
|
227
|
+
"title": "Options",
|
|
228
|
+
"expandable": true,
|
|
229
|
+
"expanded": true,
|
|
230
|
+
"items": [
|
|
231
|
+
"options.eveHistory",
|
|
232
|
+
"options.weather",
|
|
233
|
+
"options.elevation",
|
|
234
|
+
"options.hksv",
|
|
235
|
+
"options.ffmpegPath"
|
|
236
|
+
]
|
|
237
|
+
}
|
|
120
238
|
]
|
|
121
239
|
}
|
package/dist/HomeKitDevice.js
CHANGED
|
@@ -27,15 +27,16 @@
|
|
|
27
27
|
// HomeKitDevice.HOMEKITHISTORY
|
|
28
28
|
// HomeKitDevice.PLUGIN_NAME
|
|
29
29
|
// HomeKitDevice.PLATFORM_NAME
|
|
30
|
+
// HomeKitDevice.TYPE
|
|
31
|
+
// HomeKitDevice.VERSION
|
|
30
32
|
//
|
|
31
33
|
// The following functions should be overriden in your class which extends this
|
|
32
34
|
//
|
|
33
|
-
// HomeKitDevice.
|
|
34
|
-
// HomeKitDevice.
|
|
35
|
-
// HomeKitDevice.
|
|
36
|
-
// HomeKitDevice.
|
|
35
|
+
// HomeKitDevice.setupDevice()
|
|
36
|
+
// HomeKitDevice.removeDevice()
|
|
37
|
+
// HomeKitDevice.updateDevice(deviceData)
|
|
38
|
+
// HomeKitDevice.messageDevice(type, message)
|
|
37
39
|
//
|
|
38
|
-
// Code version 8/10/2024
|
|
39
40
|
// Mark Hulskamp
|
|
40
41
|
'use strict';
|
|
41
42
|
|
|
@@ -43,75 +44,76 @@
|
|
|
43
44
|
import crypto from 'crypto';
|
|
44
45
|
import EventEmitter from 'node:events';
|
|
45
46
|
|
|
47
|
+
// Define constants
|
|
48
|
+
const HK_PIN_3_2_3 = /^\d{3}-\d{2}-\d{3}$/;
|
|
49
|
+
const HK_PIN_4_4 = /^\d{4}-\d{4}$/;
|
|
50
|
+
const MAC_ADDR = /^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$/;
|
|
51
|
+
const LOGLEVELS = {
|
|
52
|
+
info: 'info',
|
|
53
|
+
success: 'success',
|
|
54
|
+
warn: 'warn',
|
|
55
|
+
error: 'error',
|
|
56
|
+
debug: 'debug',
|
|
57
|
+
};
|
|
58
|
+
|
|
46
59
|
// Define our HomeKit device class
|
|
47
|
-
|
|
48
|
-
static ADD = 'HomeKitDevice.add'; // Device add message
|
|
60
|
+
class HomeKitDevice {
|
|
49
61
|
static UPDATE = 'HomeKitDevice.update'; // Device update message
|
|
50
62
|
static REMOVE = 'HomeKitDevice.remove'; // Device remove message
|
|
51
63
|
static SET = 'HomeKitDevice.set'; // Device set property message
|
|
52
64
|
static GET = 'HomeKitDevice.get'; // Device get property message
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
static
|
|
65
|
+
|
|
66
|
+
// Override this in the class which extends
|
|
67
|
+
static PLUGIN_NAME = undefined; // Homebridge plugin name
|
|
68
|
+
static PLATFORM_NAME = undefined; // Homebridge platform name
|
|
69
|
+
static HISTORY = undefined; // HomeKit History object
|
|
70
|
+
static TYPE = 'base'; // String naming type of device
|
|
71
|
+
static VERSION = '2025.06.12'; // Code version
|
|
56
72
|
|
|
57
73
|
deviceData = {}; // The devices data we store
|
|
58
74
|
historyService = undefined; // HomeKit history service
|
|
59
|
-
accessory = undefined; //
|
|
60
|
-
hap = undefined; // HomeKit Accessory Protocol API stub
|
|
75
|
+
accessory = undefined; // HomeKit accessory service for this device
|
|
76
|
+
hap = undefined; // HomeKit Accessory Protocol (HAP) API stub
|
|
61
77
|
log = undefined; // Logging function object
|
|
62
78
|
uuid = undefined; // UUID for this instance
|
|
63
79
|
|
|
64
80
|
// Internal data only for this class
|
|
65
81
|
#platform = undefined; // Homebridge platform api
|
|
66
82
|
#eventEmitter = undefined; // Event emitter to use for comms
|
|
83
|
+
#postSetupDetails = []; // Use for extra output details once a device has been setup
|
|
67
84
|
|
|
68
85
|
constructor(accessory, api, log, eventEmitter, deviceData) {
|
|
69
86
|
// Validate the passed in logging object. We are expecting certain functions to be present
|
|
70
|
-
if (
|
|
71
|
-
typeof log?.info === 'function' &&
|
|
72
|
-
typeof log?.success === 'function' &&
|
|
73
|
-
typeof log?.warn === 'function' &&
|
|
74
|
-
typeof log?.error === 'function' &&
|
|
75
|
-
typeof log?.debug === 'function'
|
|
76
|
-
) {
|
|
87
|
+
if (Object.keys(LOGLEVELS).every((fn) => typeof log?.[fn] === 'function')) {
|
|
77
88
|
this.log = log;
|
|
78
89
|
}
|
|
79
90
|
|
|
80
|
-
// Workout if we're running under
|
|
91
|
+
// Workout if we're running under Homebridge or HAP-NodeJS library
|
|
81
92
|
if (isNaN(api?.version) === false && typeof api?.hap === 'object' && api?.HAPLibraryVersion === undefined) {
|
|
82
|
-
// We have the
|
|
93
|
+
// We have the Homebridge version number and hap API object
|
|
83
94
|
this.hap = api.hap;
|
|
84
95
|
this.#platform = api;
|
|
85
96
|
|
|
86
|
-
this
|
|
97
|
+
this.postSetupDetail('Homebridge backend', LOGLEVELS.debug);
|
|
87
98
|
}
|
|
88
99
|
|
|
89
100
|
if (typeof api?.HAPLibraryVersion === 'function' && api?.version === undefined && api?.hap === undefined) {
|
|
90
|
-
// As we're missing the
|
|
101
|
+
// As we're missing the Homebridge entry points but have the HAP library version
|
|
91
102
|
this.hap = api;
|
|
92
103
|
|
|
93
|
-
this
|
|
104
|
+
this.postSetupDetail('HAP-NodeJS library', LOGLEVELS.debug);
|
|
94
105
|
}
|
|
95
106
|
|
|
96
107
|
// Generate UUID for this device instance
|
|
97
108
|
// Will either be a random generated one or HAP generated one
|
|
98
109
|
// HAP is based upon defined plugin name and devices serial number
|
|
99
|
-
this.uuid =
|
|
100
|
-
if (
|
|
101
|
-
typeof HomeKitDevice.PLUGIN_NAME === 'string' &&
|
|
102
|
-
HomeKitDevice.PLUGIN_NAME !== '' &&
|
|
103
|
-
typeof deviceData.serialNumber === 'string' &&
|
|
104
|
-
deviceData.serialNumber !== '' &&
|
|
105
|
-
typeof this?.hap?.uuid?.generate === 'function'
|
|
106
|
-
) {
|
|
107
|
-
this.uuid = this.hap.uuid.generate(HomeKitDevice.PLUGIN_NAME + '_' + deviceData.serialNumber.toUpperCase());
|
|
108
|
-
}
|
|
110
|
+
this.uuid = HomeKitDevice.generateUUID(HomeKitDevice.PLUGIN_NAME, api, deviceData.serialNumber);
|
|
109
111
|
|
|
110
112
|
// See if we were passed in an existing accessory object or array of accessory objects
|
|
111
|
-
// Mainly used to restore a
|
|
113
|
+
// Mainly used to restore a Homebridge cached accessory
|
|
112
114
|
if (typeof accessory === 'object' && this.#platform !== undefined) {
|
|
113
115
|
if (Array.isArray(accessory) === true) {
|
|
114
|
-
this.accessory = accessory.find((accessory) => accessory?.UUID === this.uuid);
|
|
116
|
+
this.accessory = accessory.find((accessory) => this?.uuid !== undefined && accessory?.UUID === this.uuid);
|
|
115
117
|
}
|
|
116
118
|
if (Array.isArray(accessory) === false && accessory?.UUID === this.uuid) {
|
|
117
119
|
this.accessory = accessory;
|
|
@@ -155,17 +157,17 @@ export default class HomeKitDevice {
|
|
|
155
157
|
this.deviceData.manufacturer === '' ||
|
|
156
158
|
(this.#platform === undefined &&
|
|
157
159
|
(typeof this.deviceData?.hkPairingCode !== 'string' ||
|
|
158
|
-
(new RegExp(
|
|
159
|
-
new RegExp(
|
|
160
|
+
(new RegExp(HK_PIN_3_2_3).test(this.deviceData.hkPairingCode) === false &&
|
|
161
|
+
new RegExp(HK_PIN_4_4).test(this.deviceData.hkPairingCode) === false) ||
|
|
160
162
|
typeof this.deviceData?.hkUsername !== 'string' ||
|
|
161
|
-
new RegExp(
|
|
163
|
+
new RegExp(MAC_ADDR).test(this.deviceData.hkUsername) === false))
|
|
162
164
|
) {
|
|
163
165
|
return;
|
|
164
166
|
}
|
|
165
167
|
|
|
166
168
|
// If we do not have an existing accessory object, create a new one
|
|
167
169
|
if (this.accessory === undefined && this.#platform !== undefined) {
|
|
168
|
-
// Create
|
|
170
|
+
// Create Homebridge platform accessory
|
|
169
171
|
this.accessory = new this.#platform.platformAccessory(this.deviceData.description, this.uuid);
|
|
170
172
|
this.#platform.registerPlatformAccessories(HomeKitDevice.PLUGIN_NAME, HomeKitDevice.PLATFORM_NAME, [this.accessory]);
|
|
171
173
|
}
|
|
@@ -194,21 +196,29 @@ export default class HomeKitDevice {
|
|
|
194
196
|
this.historyService = new HomeKitDevice.HISTORY(this.accessory, this.log, this.hap, {});
|
|
195
197
|
}
|
|
196
198
|
|
|
197
|
-
if (typeof this
|
|
199
|
+
if (typeof this?.setupDevice === 'function') {
|
|
198
200
|
try {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
this.postSetupDetail('Serial number "%s"', this.deviceData.serialNumber, LOGLEVELS.debug);
|
|
202
|
+
|
|
203
|
+
await this.setupDevice();
|
|
204
|
+
|
|
202
205
|
if (this.historyService?.EveHome !== undefined) {
|
|
203
|
-
this
|
|
204
|
-
}
|
|
205
|
-
if (typeof postSetupDetails === 'object') {
|
|
206
|
-
postSetupDetails.forEach((output) => {
|
|
207
|
-
this?.log?.info && this.log.info(' += %s', output);
|
|
208
|
-
});
|
|
206
|
+
this.postSetupDetail('EveHome support as "%s"', this.historyService.EveHome.evetype);
|
|
209
207
|
}
|
|
208
|
+
|
|
209
|
+
this?.log?.info?.('Setup %s %s as "%s"', this.deviceData.manufacturer, this.deviceData.model, this.deviceData.description);
|
|
210
|
+
|
|
211
|
+
this.#postSetupDetails.forEach((entry) => {
|
|
212
|
+
if (typeof entry === 'string') {
|
|
213
|
+
this?.log?.[LOGLEVELS.info]?.(' += %s', entry);
|
|
214
|
+
} else if (typeof entry?.message === 'string') {
|
|
215
|
+
let level =
|
|
216
|
+
Object.hasOwn(LOGLEVELS, entry?.level) && typeof this?.log?.[entry?.level] === 'function' ? entry.level : LOGLEVELS.info;
|
|
217
|
+
this?.log?.[level]?.(' += ' + entry.message, ...(Array.isArray(entry?.args) ? entry.args : []));
|
|
218
|
+
}
|
|
219
|
+
});
|
|
210
220
|
} catch (error) {
|
|
211
|
-
this?.log?.error
|
|
221
|
+
this?.log?.error('setupDevice call for device "%s" failed. Error was', this.deviceData.description, error);
|
|
212
222
|
}
|
|
213
223
|
}
|
|
214
224
|
|
|
@@ -223,26 +233,26 @@ export default class HomeKitDevice {
|
|
|
223
233
|
category: this.accessory.category,
|
|
224
234
|
});
|
|
225
235
|
|
|
226
|
-
this?.log?.info
|
|
227
|
-
this?.log?.info
|
|
236
|
+
this?.log?.info(' += Advertising as "%s"', this.accessory.displayName);
|
|
237
|
+
this?.log?.info(' += Pairing code is "%s"', this.accessory.pincode);
|
|
228
238
|
}
|
|
229
|
-
|
|
239
|
+
this.#postSetupDetails = []; // Dont' need these anymore
|
|
230
240
|
return this.accessory; // Return our HomeKit accessory
|
|
231
241
|
}
|
|
232
242
|
|
|
233
243
|
remove() {
|
|
234
|
-
this?.log?.warn
|
|
244
|
+
this?.log?.warn?.('Device "%s" has been removed', this.deviceData.description);
|
|
235
245
|
|
|
236
246
|
if (this.#eventEmitter !== undefined) {
|
|
237
247
|
// Remove listener for 'messages'
|
|
238
248
|
this.#eventEmitter.removeAllListeners(this.uuid);
|
|
239
249
|
}
|
|
240
250
|
|
|
241
|
-
if (typeof this
|
|
251
|
+
if (typeof this?.removeDevice === 'function') {
|
|
242
252
|
try {
|
|
243
|
-
this.
|
|
253
|
+
this.removeDevice();
|
|
244
254
|
} catch (error) {
|
|
245
|
-
this?.log?.error
|
|
255
|
+
this?.log?.error('removeDevice call for device "%s" failed. Error was', this.deviceData.description, error);
|
|
246
256
|
}
|
|
247
257
|
}
|
|
248
258
|
|
|
@@ -332,8 +342,8 @@ export default class HomeKitDevice {
|
|
|
332
342
|
deviceData.serialNumber !== '' &&
|
|
333
343
|
deviceData.serialNumber.toUpperCase() !== this.deviceData.serialNumber.toUpperCase()
|
|
334
344
|
) {
|
|
335
|
-
this?.log?.warn
|
|
336
|
-
this?.log?.warn
|
|
345
|
+
this?.log?.warn?.('Serial number on "%s" has changed', deviceData.description);
|
|
346
|
+
this?.log?.warn?.('This may cause the device to become unresponsive in HomeKit');
|
|
337
347
|
|
|
338
348
|
// Update software version on the HomeKit accessory
|
|
339
349
|
informationService.updateCharacteristic(this.hap.Characteristic.SerialNumber, deviceData.serialNumber);
|
|
@@ -343,19 +353,19 @@ export default class HomeKitDevice {
|
|
|
343
353
|
if (typeof deviceData?.online === 'boolean' && deviceData.online !== this.deviceData.online) {
|
|
344
354
|
// Output device online/offline status
|
|
345
355
|
if (deviceData.online === false) {
|
|
346
|
-
this?.log?.warn
|
|
356
|
+
this?.log?.warn?.('Device "%s" is offline', deviceData.description);
|
|
347
357
|
}
|
|
348
358
|
|
|
349
359
|
if (deviceData.online === true) {
|
|
350
|
-
this?.log?.success
|
|
360
|
+
this?.log?.success?.('Device "%s" is online', deviceData.description);
|
|
351
361
|
}
|
|
352
362
|
}
|
|
353
363
|
|
|
354
|
-
if (typeof this
|
|
364
|
+
if (typeof this?.updateDevice === 'function') {
|
|
355
365
|
try {
|
|
356
|
-
this.
|
|
366
|
+
this.updateDevice(deviceData); // Pass updated data on for accessory to process as it needs
|
|
357
367
|
} catch (error) {
|
|
358
|
-
this?.log?.error
|
|
368
|
+
this?.log?.error('updateDevice call for device "%s" failed. Error was', deviceData.description, error);
|
|
359
369
|
}
|
|
360
370
|
}
|
|
361
371
|
|
|
@@ -397,14 +407,6 @@ export default class HomeKitDevice {
|
|
|
397
407
|
|
|
398
408
|
#message(type, message) {
|
|
399
409
|
switch (type) {
|
|
400
|
-
case HomeKitDevice.ADD: {
|
|
401
|
-
// Got message for device add
|
|
402
|
-
if (typeof message?.name === 'string' && isNaN(message?.category) === false && typeof message?.history === 'boolean') {
|
|
403
|
-
this.add(message.name, Number(message.category), message.history);
|
|
404
|
-
}
|
|
405
|
-
break;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
410
|
case HomeKitDevice.UPDATE: {
|
|
409
411
|
// Got some device data, so process any updates
|
|
410
412
|
this.update(message, false);
|
|
@@ -419,16 +421,131 @@ export default class HomeKitDevice {
|
|
|
419
421
|
|
|
420
422
|
default: {
|
|
421
423
|
// This is not a message we know about, so pass onto accessory for it to perform any processing
|
|
422
|
-
if (typeof this
|
|
424
|
+
if (typeof this?.messageDevice === 'function') {
|
|
423
425
|
try {
|
|
424
|
-
this.
|
|
426
|
+
this.messageDevice(type, message);
|
|
425
427
|
} catch (error) {
|
|
426
|
-
this?.log?.error
|
|
427
|
-
this.log.error('messageServices call for device "%s" failed. Error was', this.deviceData.description, error);
|
|
428
|
+
this?.log?.error('messageDevice call for device "%s" failed. Error was', this.deviceData.description, error);
|
|
428
429
|
}
|
|
429
430
|
}
|
|
430
431
|
break;
|
|
431
432
|
}
|
|
432
433
|
}
|
|
433
434
|
}
|
|
435
|
+
|
|
436
|
+
addHKService(hkServiceType, name = '', subType = undefined) {
|
|
437
|
+
let service = undefined;
|
|
438
|
+
|
|
439
|
+
if (
|
|
440
|
+
hkServiceType !== undefined &&
|
|
441
|
+
typeof this?.accessory?.getService === 'function' &&
|
|
442
|
+
typeof this?.accessory?.getServiceById === 'function' &&
|
|
443
|
+
typeof this?.accessory?.addService === 'function'
|
|
444
|
+
) {
|
|
445
|
+
if (subType !== undefined) {
|
|
446
|
+
service = this.accessory.getServiceById(hkServiceType, subType);
|
|
447
|
+
} else {
|
|
448
|
+
service = this.accessory.getService(hkServiceType);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if (service === undefined) {
|
|
452
|
+
service = this.accessory.addService(hkServiceType, name, subType);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
return service;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
addHKCharacteristic(hkService, hkCharacteristicType, { props, onSet, onGet } = {}) {
|
|
460
|
+
let characteristic = undefined;
|
|
461
|
+
|
|
462
|
+
if (
|
|
463
|
+
hkCharacteristicType !== undefined &&
|
|
464
|
+
typeof hkService?.getCharacteristic === 'function' &&
|
|
465
|
+
typeof hkService?.testCharacteristic === 'function' &&
|
|
466
|
+
typeof hkService?.addCharacteristic === 'function' &&
|
|
467
|
+
typeof hkService?.addOptionalCharacteristic === 'function'
|
|
468
|
+
) {
|
|
469
|
+
if (hkService.testCharacteristic(hkCharacteristicType) === false) {
|
|
470
|
+
if (
|
|
471
|
+
Array.isArray(hkService?.optionalCharacteristics) &&
|
|
472
|
+
hkService.optionalCharacteristics.includes(hkCharacteristicType) &&
|
|
473
|
+
typeof hkService?.addOptionalCharacteristic === 'function'
|
|
474
|
+
) {
|
|
475
|
+
hkService.addOptionalCharacteristic(hkCharacteristicType);
|
|
476
|
+
} else {
|
|
477
|
+
hkService.addCharacteristic(hkCharacteristicType);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
characteristic = hkService.getCharacteristic(hkCharacteristicType);
|
|
482
|
+
|
|
483
|
+
// Apply optional config
|
|
484
|
+
if (typeof onSet === 'function') {
|
|
485
|
+
characteristic.onSet(onSet);
|
|
486
|
+
}
|
|
487
|
+
if (typeof onGet === 'function') {
|
|
488
|
+
characteristic.onGet(onGet);
|
|
489
|
+
}
|
|
490
|
+
if (typeof props === 'object' && typeof characteristic.setProps === 'function') {
|
|
491
|
+
characteristic.setProps(props);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return characteristic;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
postSetupDetail(message, ...args) {
|
|
498
|
+
if (typeof message !== 'string' || message === '') {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
let level = 'info';
|
|
503
|
+
let availableLevel = Object.keys(LOGLEVELS).find((lvl) => typeof this.log?.[lvl] === 'function') || 'info';
|
|
504
|
+
let lastArg = args.at(-1);
|
|
505
|
+
|
|
506
|
+
if (typeof lastArg === 'string' && Object.hasOwn(LOGLEVELS, lastArg)) {
|
|
507
|
+
level = lastArg;
|
|
508
|
+
args = args.slice(0, -1);
|
|
509
|
+
} else {
|
|
510
|
+
level = availableLevel;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
this.#postSetupDetails.push({
|
|
514
|
+
level,
|
|
515
|
+
message,
|
|
516
|
+
args: args.length > 0 ? args : undefined,
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
static generateUUID(PLUGIN_NAME, api, serialNumber) {
|
|
521
|
+
let hap = undefined;
|
|
522
|
+
let uuid = crypto.randomUUID();
|
|
523
|
+
|
|
524
|
+
// Workout if we're running under Homebridge or HAP-NodeJS library
|
|
525
|
+
if (isNaN(api?.version) === false && typeof api?.hap === 'object' && api?.HAPLibraryVersion === undefined) {
|
|
526
|
+
// We have the Homebridge version number and hap API object
|
|
527
|
+
hap = api.hap;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
if (typeof api?.HAPLibraryVersion === 'function' && api?.version === undefined && api?.hap === undefined) {
|
|
531
|
+
// As we're missing the Homebridge entry points but have the HAP library version
|
|
532
|
+
hap = api;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (
|
|
536
|
+
typeof PLUGIN_NAME === 'string' &&
|
|
537
|
+
PLUGIN_NAME !== '' &&
|
|
538
|
+
typeof serialNumber === 'string' &&
|
|
539
|
+
serialNumber !== '' &&
|
|
540
|
+
typeof hap?.uuid?.generate === 'function'
|
|
541
|
+
) {
|
|
542
|
+
uuid = hap.uuid.generate(PLUGIN_NAME + '_' + serialNumber.toUpperCase());
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return uuid;
|
|
546
|
+
}
|
|
434
547
|
}
|
|
548
|
+
|
|
549
|
+
// Define exports
|
|
550
|
+
export { HK_PIN_3_2_3, HK_PIN_4_4, MAC_ADDR, HomeKitDevice };
|
|
551
|
+
export default HomeKitDevice;
|
package/dist/HomeKitHistory.js
CHANGED