homebridge-zwave-usb 1.2.7 → 1.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/dist/zwave/ZWaveController.js +50 -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,33 @@ 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 logging
|
|
39
|
+
// Z-Wave JS logging configuration
|
|
40
|
+
// We use forceConsole: true to ensure logs appear in Homebridge terminal
|
|
44
41
|
const logConfig = {
|
|
45
42
|
enabled: true,
|
|
46
43
|
level: this.options.debug ? 'debug' : 'info',
|
|
44
|
+
forceConsole: true,
|
|
47
45
|
};
|
|
48
46
|
const storagePath = this.options.storagePath || process.cwd();
|
|
49
47
|
this.driver = new zwave_js_1.Driver(this.serialPort, {
|
|
50
48
|
securityKeys: Object.keys(securityKeys).length > 0 ? securityKeys : undefined,
|
|
51
|
-
logConfig
|
|
49
|
+
logConfig,
|
|
52
50
|
storage: {
|
|
53
|
-
cacheDir: storagePath
|
|
54
|
-
deviceConfigPriorityDir: storagePath
|
|
51
|
+
cacheDir: path_1.default.join(storagePath, 'zwave-js-cache'),
|
|
52
|
+
deviceConfigPriorityDir: path_1.default.join(storagePath, 'zwave-js-config'),
|
|
55
53
|
},
|
|
56
54
|
features: {
|
|
57
55
|
softReset: false,
|
|
@@ -133,7 +131,9 @@ class ZWaveController extends events_1.EventEmitter {
|
|
|
133
131
|
return;
|
|
134
132
|
}
|
|
135
133
|
this.nodes.set(node.nodeId, node);
|
|
136
|
-
|
|
134
|
+
const statusMap = ['Unknown', 'Alive', 'Awake', 'Asleep', 'Dead'];
|
|
135
|
+
const status = statusMap[node.status] || node.status.toString();
|
|
136
|
+
this.log.info(`Node ${node.nodeId} added to controller (Status: ${status}, Interview Stage: ${node.interviewStage})`);
|
|
137
137
|
const onReady = () => {
|
|
138
138
|
this.log.info(`Node ${node.nodeId} is ready (Interview Stage: ${node.interviewStage})`);
|
|
139
139
|
this.emit('node ready', node);
|
|
@@ -148,16 +148,28 @@ class ZWaveController extends events_1.EventEmitter {
|
|
|
148
148
|
const onInterviewFailed = (args) => {
|
|
149
149
|
this.log.error(`Node ${node.nodeId} interview failed: ${args.errorMessage}`);
|
|
150
150
|
};
|
|
151
|
+
const onWakeUp = () => {
|
|
152
|
+
this.log.info(`Node ${node.nodeId} has woken up. Interview will resume.`);
|
|
153
|
+
};
|
|
154
|
+
const onSleep = () => {
|
|
155
|
+
this.log.info(`Node ${node.nodeId} has gone to sleep. Interview is paused.`);
|
|
156
|
+
};
|
|
151
157
|
this.nodeListeners.set(node.nodeId, {
|
|
152
158
|
ready: onReady,
|
|
153
159
|
value: onValueUpdated,
|
|
154
160
|
interviewStageCompleted: onInterviewStageCompleted,
|
|
155
|
-
interviewFailed: onInterviewFailed
|
|
161
|
+
interviewFailed: onInterviewFailed,
|
|
162
|
+
onWakeUp,
|
|
163
|
+
onSleep
|
|
156
164
|
});
|
|
157
165
|
node.on('ready', onReady);
|
|
158
166
|
node.on('value updated', onValueUpdated);
|
|
167
|
+
node.on('value added', onValueUpdated);
|
|
168
|
+
node.on('metadata updated', onValueUpdated);
|
|
159
169
|
node.on('interview stage completed', onInterviewStageCompleted);
|
|
160
170
|
node.on('interview failed', onInterviewFailed);
|
|
171
|
+
node.on('wake up', onWakeUp);
|
|
172
|
+
node.on('sleep', onSleep);
|
|
161
173
|
this.log.info(`Node ${node.nodeId} registered with event listeners (ready: ${node.ready})`);
|
|
162
174
|
if (node.ready) {
|
|
163
175
|
this.log.info(`Node ${node.nodeId} is already ready, emitting node ready immediately`);
|
|
@@ -169,12 +181,20 @@ class ZWaveController extends events_1.EventEmitter {
|
|
|
169
181
|
if (listeners) {
|
|
170
182
|
node.off('ready', listeners.ready);
|
|
171
183
|
node.off('value updated', listeners.value);
|
|
184
|
+
node.off('value added', listeners.value);
|
|
185
|
+
node.off('metadata updated', listeners.value);
|
|
172
186
|
if (listeners.interviewStageCompleted) {
|
|
173
187
|
node.off('interview stage completed', listeners.interviewStageCompleted);
|
|
174
188
|
}
|
|
175
189
|
if (listeners.interviewFailed) {
|
|
176
190
|
node.off('interview failed', listeners.interviewFailed);
|
|
177
191
|
}
|
|
192
|
+
if (listeners.onWakeUp) {
|
|
193
|
+
node.off('wake up', listeners.onWakeUp);
|
|
194
|
+
}
|
|
195
|
+
if (listeners.onSleep) {
|
|
196
|
+
node.off('sleep', listeners.onSleep);
|
|
197
|
+
}
|
|
178
198
|
this.nodeListeners.delete(node.nodeId);
|
|
179
199
|
}
|
|
180
200
|
this.nodes.delete(node.nodeId);
|
|
@@ -202,12 +222,20 @@ class ZWaveController extends events_1.EventEmitter {
|
|
|
202
222
|
if (listeners) {
|
|
203
223
|
node.off('ready', listeners.ready);
|
|
204
224
|
node.off('value updated', listeners.value);
|
|
225
|
+
node.off('value added', listeners.value);
|
|
226
|
+
node.off('metadata updated', listeners.value);
|
|
205
227
|
if (listeners.interviewStageCompleted) {
|
|
206
228
|
node.off('interview stage completed', listeners.interviewStageCompleted);
|
|
207
229
|
}
|
|
208
230
|
if (listeners.interviewFailed) {
|
|
209
231
|
node.off('interview failed', listeners.interviewFailed);
|
|
210
232
|
}
|
|
233
|
+
if (listeners.onWakeUp) {
|
|
234
|
+
node.off('wake up', listeners.onWakeUp);
|
|
235
|
+
}
|
|
236
|
+
if (listeners.onSleep) {
|
|
237
|
+
node.off('sleep', listeners.onSleep);
|
|
238
|
+
}
|
|
211
239
|
}
|
|
212
240
|
}
|
|
213
241
|
this.nodeListeners.clear();
|
package/package.json
CHANGED