homebridge-zwave-usb 1.2.7 → 1.2.9
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/dist/zwave/ZWaveController.js +72 -22
- package/package.json +1 -1
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.ZWaveController = void 0;
|
|
4
7
|
const zwave_js_1 = require("zwave-js");
|
|
5
8
|
const events_1 = require("events");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
6
10
|
class ZWaveController extends events_1.EventEmitter {
|
|
7
11
|
log;
|
|
8
12
|
serialPort;
|
|
@@ -19,39 +23,55 @@ class ZWaveController extends events_1.EventEmitter {
|
|
|
19
23
|
this.options = options;
|
|
20
24
|
const securityKeys = {};
|
|
21
25
|
if (this.options.securityKeys) {
|
|
22
|
-
if (this.options.securityKeys.S0_Legacy) {
|
|
23
|
-
|
|
24
|
-
securityKeys.S0_Legacy = Buffer.from(this.options.securityKeys.S0_Legacy, 'hex');
|
|
25
|
-
}
|
|
26
|
+
if (this.options.securityKeys.S0_Legacy && this.options.securityKeys.S0_Legacy.length === 32) {
|
|
27
|
+
securityKeys.S0_Legacy = Buffer.from(this.options.securityKeys.S0_Legacy, 'hex');
|
|
26
28
|
}
|
|
27
|
-
if (this.options.securityKeys.S2_Unauthenticated) {
|
|
28
|
-
|
|
29
|
-
securityKeys.S2_Unauthenticated = Buffer.from(this.options.securityKeys.S2_Unauthenticated, 'hex');
|
|
30
|
-
}
|
|
29
|
+
if (this.options.securityKeys.S2_Unauthenticated && this.options.securityKeys.S2_Unauthenticated.length === 32) {
|
|
30
|
+
securityKeys.S2_Unauthenticated = Buffer.from(this.options.securityKeys.S2_Unauthenticated, 'hex');
|
|
31
31
|
}
|
|
32
|
-
if (this.options.securityKeys.S2_Authenticated) {
|
|
33
|
-
|
|
34
|
-
securityKeys.S2_Authenticated = Buffer.from(this.options.securityKeys.S2_Authenticated, 'hex');
|
|
35
|
-
}
|
|
32
|
+
if (this.options.securityKeys.S2_Authenticated && this.options.securityKeys.S2_Authenticated.length === 32) {
|
|
33
|
+
securityKeys.S2_Authenticated = Buffer.from(this.options.securityKeys.S2_Authenticated, 'hex');
|
|
36
34
|
}
|
|
37
|
-
if (this.options.securityKeys.S2_AccessControl) {
|
|
38
|
-
|
|
39
|
-
securityKeys.S2_AccessControl = Buffer.from(this.options.securityKeys.S2_AccessControl, 'hex');
|
|
40
|
-
}
|
|
35
|
+
if (this.options.securityKeys.S2_AccessControl && this.options.securityKeys.S2_AccessControl.length === 32) {
|
|
36
|
+
securityKeys.S2_AccessControl = Buffer.from(this.options.securityKeys.S2_AccessControl, 'hex');
|
|
41
37
|
}
|
|
42
38
|
}
|
|
43
|
-
// Z-Wave JS
|
|
39
|
+
// Redirect Z-Wave JS logs to Homebridge with a more complete Winston mock
|
|
40
|
+
const customLogTransport = {
|
|
41
|
+
on: () => customLogTransport,
|
|
42
|
+
once: () => customLogTransport,
|
|
43
|
+
emit: () => true,
|
|
44
|
+
removeListener: () => customLogTransport,
|
|
45
|
+
removeEventListener: () => customLogTransport,
|
|
46
|
+
addListener: () => customLogTransport,
|
|
47
|
+
log: (info, next) => {
|
|
48
|
+
const message = info.message || info;
|
|
49
|
+
const label = info.label ? `[${info.label}] ` : '';
|
|
50
|
+
const level = info.level || 'info';
|
|
51
|
+
const output = `[Z-Wave JS] ${label}${message}`;
|
|
52
|
+
if (this.options.debug || level === 'error' || level === 'warn') {
|
|
53
|
+
this.log.info(output);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this.log.debug(output);
|
|
57
|
+
}
|
|
58
|
+
if (next) {
|
|
59
|
+
next();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
44
63
|
const logConfig = {
|
|
45
64
|
enabled: true,
|
|
46
65
|
level: this.options.debug ? 'debug' : 'info',
|
|
66
|
+
transports: [customLogTransport] // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
47
67
|
};
|
|
48
68
|
const storagePath = this.options.storagePath || process.cwd();
|
|
49
69
|
this.driver = new zwave_js_1.Driver(this.serialPort, {
|
|
50
70
|
securityKeys: Object.keys(securityKeys).length > 0 ? securityKeys : undefined,
|
|
51
|
-
logConfig
|
|
71
|
+
logConfig,
|
|
52
72
|
storage: {
|
|
53
|
-
cacheDir: storagePath
|
|
54
|
-
deviceConfigPriorityDir: storagePath
|
|
73
|
+
cacheDir: path_1.default.join(storagePath, 'zwave-js-cache'),
|
|
74
|
+
deviceConfigPriorityDir: path_1.default.join(storagePath, 'zwave-js-config'),
|
|
55
75
|
},
|
|
56
76
|
features: {
|
|
57
77
|
softReset: false,
|
|
@@ -133,7 +153,9 @@ class ZWaveController extends events_1.EventEmitter {
|
|
|
133
153
|
return;
|
|
134
154
|
}
|
|
135
155
|
this.nodes.set(node.nodeId, node);
|
|
136
|
-
|
|
156
|
+
const statusMap = ['Unknown', 'Alive', 'Awake', 'Asleep', 'Dead'];
|
|
157
|
+
const status = statusMap[node.status] || node.status.toString();
|
|
158
|
+
this.log.info(`Node ${node.nodeId} added to controller (Status: ${status}, Interview Stage: ${node.interviewStage})`);
|
|
137
159
|
const onReady = () => {
|
|
138
160
|
this.log.info(`Node ${node.nodeId} is ready (Interview Stage: ${node.interviewStage})`);
|
|
139
161
|
this.emit('node ready', node);
|
|
@@ -148,16 +170,28 @@ class ZWaveController extends events_1.EventEmitter {
|
|
|
148
170
|
const onInterviewFailed = (args) => {
|
|
149
171
|
this.log.error(`Node ${node.nodeId} interview failed: ${args.errorMessage}`);
|
|
150
172
|
};
|
|
173
|
+
const onWakeUp = () => {
|
|
174
|
+
this.log.info(`Node ${node.nodeId} has woken up. Interview will resume.`);
|
|
175
|
+
};
|
|
176
|
+
const onSleep = () => {
|
|
177
|
+
this.log.info(`Node ${node.nodeId} has gone to sleep. Interview is paused.`);
|
|
178
|
+
};
|
|
151
179
|
this.nodeListeners.set(node.nodeId, {
|
|
152
180
|
ready: onReady,
|
|
153
181
|
value: onValueUpdated,
|
|
154
182
|
interviewStageCompleted: onInterviewStageCompleted,
|
|
155
|
-
interviewFailed: onInterviewFailed
|
|
183
|
+
interviewFailed: onInterviewFailed,
|
|
184
|
+
onWakeUp,
|
|
185
|
+
onSleep
|
|
156
186
|
});
|
|
157
187
|
node.on('ready', onReady);
|
|
158
188
|
node.on('value updated', onValueUpdated);
|
|
189
|
+
node.on('value added', onValueUpdated);
|
|
190
|
+
node.on('metadata updated', onValueUpdated);
|
|
159
191
|
node.on('interview stage completed', onInterviewStageCompleted);
|
|
160
192
|
node.on('interview failed', onInterviewFailed);
|
|
193
|
+
node.on('wake up', onWakeUp);
|
|
194
|
+
node.on('sleep', onSleep);
|
|
161
195
|
this.log.info(`Node ${node.nodeId} registered with event listeners (ready: ${node.ready})`);
|
|
162
196
|
if (node.ready) {
|
|
163
197
|
this.log.info(`Node ${node.nodeId} is already ready, emitting node ready immediately`);
|
|
@@ -169,12 +203,20 @@ class ZWaveController extends events_1.EventEmitter {
|
|
|
169
203
|
if (listeners) {
|
|
170
204
|
node.off('ready', listeners.ready);
|
|
171
205
|
node.off('value updated', listeners.value);
|
|
206
|
+
node.off('value added', listeners.value);
|
|
207
|
+
node.off('metadata updated', listeners.value);
|
|
172
208
|
if (listeners.interviewStageCompleted) {
|
|
173
209
|
node.off('interview stage completed', listeners.interviewStageCompleted);
|
|
174
210
|
}
|
|
175
211
|
if (listeners.interviewFailed) {
|
|
176
212
|
node.off('interview failed', listeners.interviewFailed);
|
|
177
213
|
}
|
|
214
|
+
if (listeners.onWakeUp) {
|
|
215
|
+
node.off('wake up', listeners.onWakeUp);
|
|
216
|
+
}
|
|
217
|
+
if (listeners.onSleep) {
|
|
218
|
+
node.off('sleep', listeners.onSleep);
|
|
219
|
+
}
|
|
178
220
|
this.nodeListeners.delete(node.nodeId);
|
|
179
221
|
}
|
|
180
222
|
this.nodes.delete(node.nodeId);
|
|
@@ -202,12 +244,20 @@ class ZWaveController extends events_1.EventEmitter {
|
|
|
202
244
|
if (listeners) {
|
|
203
245
|
node.off('ready', listeners.ready);
|
|
204
246
|
node.off('value updated', listeners.value);
|
|
247
|
+
node.off('value added', listeners.value);
|
|
248
|
+
node.off('metadata updated', listeners.value);
|
|
205
249
|
if (listeners.interviewStageCompleted) {
|
|
206
250
|
node.off('interview stage completed', listeners.interviewStageCompleted);
|
|
207
251
|
}
|
|
208
252
|
if (listeners.interviewFailed) {
|
|
209
253
|
node.off('interview failed', listeners.interviewFailed);
|
|
210
254
|
}
|
|
255
|
+
if (listeners.onWakeUp) {
|
|
256
|
+
node.off('wake up', listeners.onWakeUp);
|
|
257
|
+
}
|
|
258
|
+
if (listeners.onSleep) {
|
|
259
|
+
node.off('sleep', listeners.onSleep);
|
|
260
|
+
}
|
|
211
261
|
}
|
|
212
262
|
}
|
|
213
263
|
this.nodeListeners.clear();
|
package/package.json
CHANGED