homebridge-alexa 0.8.0-beta.13 → 0.8.0-beta.14
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/package.json +6 -6
- package/src/lib/alexaActions.js +78 -17
- package/src/lib/alexaLocal.js +2 -1
- package/src/lib/alexaMessages.js +2 -0
- package/src/lib/parse/messages.js +2 -2
- package/src/plugin.js +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-alexa",
|
|
3
|
-
"version": "0.8.0-beta.
|
|
3
|
+
"version": "0.8.0-beta.14",
|
|
4
4
|
"description": "Control your Homebridge devices with Amazon Alexa.",
|
|
5
5
|
"main": "src/plugin.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"homebridge-plugin"
|
|
35
35
|
],
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@types/node": "^22.10.
|
|
37
|
+
"@homebridge/hap-client": "^2.0.0",
|
|
38
|
+
"@types/node": "^22.10.2",
|
|
39
39
|
"@types/jest": "^29.5.14",
|
|
40
40
|
"@eslint/js": "^9.14.0",
|
|
41
41
|
"eslint": "^8.57.1",
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
"globals": "^15.12.0",
|
|
46
46
|
"jest": "^29.7.0",
|
|
47
47
|
"mqtt-connection": "^4.1.0",
|
|
48
|
-
"nodemon": "^3.1.
|
|
48
|
+
"nodemon": "^3.1.9",
|
|
49
49
|
"rimraf": "^6.0.1",
|
|
50
50
|
"semver": "^7.6.3"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"axios": "^1.7.
|
|
53
|
+
"axios": "^1.7.9",
|
|
54
54
|
"bottleneck": "2.19.5",
|
|
55
|
-
"debug": "4.
|
|
55
|
+
"debug": "4.4.0",
|
|
56
56
|
"hap-node-client": "^0.2.9",
|
|
57
57
|
"is-my-json-valid": "2.20.6",
|
|
58
58
|
"mqtt": "5.10.3"
|
package/src/lib/alexaActions.js
CHANGED
|
@@ -140,10 +140,11 @@ function alexaDiscovery(message, callback) {
|
|
|
140
140
|
this.log("ERROR: Maximum devices/accessories of 300 exceeded.");
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
// debug("Discovery Response", JSON.stringify(response, null, 2));
|
|
144
143
|
if (this.debug) {
|
|
145
144
|
const fs = require('fs');
|
|
146
|
-
|
|
145
|
+
const storagePath = this.api.user.storagePath() + '/homebridge-alexa-discovery.json';
|
|
146
|
+
this.log.warn("Writing Alexa Discovery Response to", storagePath);
|
|
147
|
+
fs.writeFileSync(storagePath, JSON.stringify(response, null, 2));
|
|
147
148
|
}
|
|
148
149
|
callback(null, response);
|
|
149
150
|
}.bind(this));
|
|
@@ -265,7 +266,13 @@ function alexaColorTemperatureController(message, callback) {
|
|
|
265
266
|
}]
|
|
266
267
|
};
|
|
267
268
|
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
268
|
-
|
|
269
|
+
if (err) {
|
|
270
|
+
this.log.error(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""), (err ? "ERROR: " + err : ""));
|
|
271
|
+
} else if (status) {
|
|
272
|
+
this.log.warn(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
273
|
+
} else {
|
|
274
|
+
this.log(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
275
|
+
}
|
|
269
276
|
var response = alexaMessages.alexaResponse(message, status, err, message.directive.payload.colorTemperatureInKelvin);
|
|
270
277
|
callback(err, response);
|
|
271
278
|
}.bind(this));
|
|
@@ -292,7 +299,13 @@ function alexaPlaybackController(message, callback) {
|
|
|
292
299
|
}]
|
|
293
300
|
};
|
|
294
301
|
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
295
|
-
|
|
302
|
+
if (err) {
|
|
303
|
+
this.log.error(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""), (err ? "ERROR: " + err : ""));
|
|
304
|
+
} else if (status) {
|
|
305
|
+
this.log.warn(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
306
|
+
} else {
|
|
307
|
+
this.log(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
308
|
+
}
|
|
296
309
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
297
310
|
callback(err, response);
|
|
298
311
|
}.bind(this));
|
|
@@ -317,7 +330,13 @@ function alexaInputController(message, callback) {
|
|
|
317
330
|
}]
|
|
318
331
|
};
|
|
319
332
|
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
320
|
-
|
|
333
|
+
if (err) {
|
|
334
|
+
this.log.error(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""), (err ? "ERROR: " + err : ""));
|
|
335
|
+
} else if (status) {
|
|
336
|
+
this.log.warn(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
337
|
+
} else {
|
|
338
|
+
this.log(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
339
|
+
}
|
|
321
340
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
322
341
|
callback(err, response);
|
|
323
342
|
}.bind(this));
|
|
@@ -342,7 +361,13 @@ function alexaPowerController(message, callback) {
|
|
|
342
361
|
}]
|
|
343
362
|
};
|
|
344
363
|
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
345
|
-
|
|
364
|
+
if (err) {
|
|
365
|
+
this.log.error(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""), (err ? "ERROR: " + err : ""));
|
|
366
|
+
} else if (status) {
|
|
367
|
+
this.log.warn(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
368
|
+
} else {
|
|
369
|
+
this.log(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
370
|
+
}
|
|
346
371
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
347
372
|
callback(err, response);
|
|
348
373
|
}.bind(this));
|
|
@@ -383,7 +408,13 @@ function alexaModeController(message, callback) {
|
|
|
383
408
|
}]
|
|
384
409
|
};
|
|
385
410
|
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
386
|
-
|
|
411
|
+
if (err) {
|
|
412
|
+
this.log.error(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""), (err ? "ERROR: " + err : ""));
|
|
413
|
+
} else if (status) {
|
|
414
|
+
this.log.warn(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
415
|
+
} else {
|
|
416
|
+
this.log(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
417
|
+
}
|
|
387
418
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
388
419
|
callback(err, response);
|
|
389
420
|
}.bind(this));
|
|
@@ -408,7 +439,13 @@ function alexaLockController(message, callback) {
|
|
|
408
439
|
}]
|
|
409
440
|
};
|
|
410
441
|
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
411
|
-
|
|
442
|
+
if (err) {
|
|
443
|
+
this.log.error(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""), (err ? "ERROR: " + err : ""));
|
|
444
|
+
} else if (status) {
|
|
445
|
+
this.log.warn(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
446
|
+
} else {
|
|
447
|
+
this.log(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
448
|
+
}
|
|
412
449
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
413
450
|
callback(err, response);
|
|
414
451
|
}.bind(this));
|
|
@@ -473,7 +510,13 @@ function alexaChannelController(message, callback) {
|
|
|
473
510
|
// debug("alexaChannelController", JSON.stringify(message), JSON.stringify(body));
|
|
474
511
|
|
|
475
512
|
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
476
|
-
|
|
513
|
+
if (err) {
|
|
514
|
+
this.log.error(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""), (err ? "ERROR: " + err : ""));
|
|
515
|
+
} else if (status) {
|
|
516
|
+
this.log.warn(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
517
|
+
} else {
|
|
518
|
+
this.log(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
519
|
+
}
|
|
477
520
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
478
521
|
callback(err, response);
|
|
479
522
|
}.bind(this));
|
|
@@ -558,7 +601,13 @@ async function alexaThermostatController(message, callback) {
|
|
|
558
601
|
"characteristics": characteristics
|
|
559
602
|
};
|
|
560
603
|
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
561
|
-
|
|
604
|
+
if (err) {
|
|
605
|
+
this.log.error(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""), (err ? "ERROR: " + err : ""));
|
|
606
|
+
} else if (status) {
|
|
607
|
+
this.log.warn(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
608
|
+
} else {
|
|
609
|
+
this.log(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
610
|
+
}
|
|
562
611
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
563
612
|
callback(err, response);
|
|
564
613
|
}.bind(this));
|
|
@@ -627,7 +676,13 @@ function alexaColorController(message, callback) {
|
|
|
627
676
|
};
|
|
628
677
|
debug("color HB command", body);
|
|
629
678
|
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
630
|
-
|
|
679
|
+
if (err) {
|
|
680
|
+
this.log.error(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""), (err ? "ERROR: " + err : ""));
|
|
681
|
+
} else if (status) {
|
|
682
|
+
this.log.warn(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
683
|
+
} else {
|
|
684
|
+
this.log(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
685
|
+
}
|
|
631
686
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
632
687
|
callback(err, response);
|
|
633
688
|
}.bind(this));
|
|
@@ -682,7 +737,13 @@ function alexaRangeController(message, callback) {
|
|
|
682
737
|
}]
|
|
683
738
|
};
|
|
684
739
|
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
685
|
-
|
|
740
|
+
if (err) {
|
|
741
|
+
this.log.error(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""), (err ? "ERROR: " + err : ""));
|
|
742
|
+
} else if (status) {
|
|
743
|
+
this.log.warn(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
744
|
+
} else {
|
|
745
|
+
this.log(message.directive.header.namespace, action, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
746
|
+
}
|
|
686
747
|
var response = alexaMessages.alexaResponse(message, status, err, rangeValue);
|
|
687
748
|
callback(err, response);
|
|
688
749
|
}.bind(this));
|
|
@@ -868,7 +929,7 @@ function alexaStepSpeaker(message, callback) {
|
|
|
868
929
|
}
|
|
869
930
|
|
|
870
931
|
function alexaMessage(message, callback) {
|
|
871
|
-
debug("alexaMessage:", JSON.stringify(message));
|
|
932
|
+
// debug("alexaMessage:", JSON.stringify(message));
|
|
872
933
|
switch (message.directive.header.name.toLowerCase()) {
|
|
873
934
|
case "reportstate": // aka getStatus
|
|
874
935
|
var action = message.directive.header.name;
|
|
@@ -938,8 +999,7 @@ function alexaMessage(message, callback) {
|
|
|
938
999
|
// debug("alexaMessage - statusArray", statusArray);
|
|
939
1000
|
|
|
940
1001
|
processStatusArray.call(this, statusArray, message).then(response => {
|
|
941
|
-
debug("alexaMessage: Response", JSON.stringify(response
|
|
942
|
-
null, 2));
|
|
1002
|
+
// debug("alexaMessage: Response", JSON.stringify(response));
|
|
943
1003
|
callback(null, response);
|
|
944
1004
|
}).catch(err => {
|
|
945
1005
|
debug("alexaMessage:Error:", err.message);
|
|
@@ -987,6 +1047,7 @@ async function processStatusArray(statusArray, message) {
|
|
|
987
1047
|
// debug("processStatusArray", messageArray);
|
|
988
1048
|
var resultArray = await Promise.all(messageArray);
|
|
989
1049
|
|
|
1050
|
+
// debug("processStatusArray-2", JSON.stringify(resultArray));
|
|
990
1051
|
return (alexaMessages.alexaStateResponse(resultArray, message));
|
|
991
1052
|
} catch (err) {
|
|
992
1053
|
if (this.deviceCleanup) {
|
|
@@ -997,14 +1058,14 @@ async function processStatusArray(statusArray, message) {
|
|
|
997
1058
|
}
|
|
998
1059
|
|
|
999
1060
|
function _HAPstatusByDeviceID(statusObject, message) {
|
|
1000
|
-
debug("_HAPstatusByDeviceID-1", statusObject);
|
|
1061
|
+
// debug("_HAPstatusByDeviceID-1", JSON.stringify(statusObject));
|
|
1001
1062
|
return new Promise((resolve, reject) => {
|
|
1002
1063
|
homebridge.HAPstatusByDeviceID(statusObject.deviceID, statusObject.body, function (err, status) {
|
|
1003
1064
|
if (err) {
|
|
1004
1065
|
// debug("Error: _HAPstatusByDeviceID", err);
|
|
1005
1066
|
reject(err);
|
|
1006
1067
|
} else {
|
|
1007
|
-
debug("_HAPstatusByDeviceID-2", statusObject.deviceID, status);
|
|
1068
|
+
// debug("_HAPstatusByDeviceID-2", statusObject.deviceID, JSON.stringify(status));
|
|
1008
1069
|
resolve(messages.stateToProperties(statusObject, status.characteristics));
|
|
1009
1070
|
}
|
|
1010
1071
|
});
|
package/src/lib/alexaLocal.js
CHANGED
|
@@ -70,11 +70,12 @@ function alexaLocal(options) {
|
|
|
70
70
|
|
|
71
71
|
// debug("Count", this.listenerCount(msg.directive.header.namespace.toLowerCase()));
|
|
72
72
|
if (options.eventBus.listenerCount(msg.directive.header.namespace) > 0) {
|
|
73
|
-
debug('Emitting', msg.directive.header.namespace);
|
|
73
|
+
debug('Emitting', msg.directive.header.namespace, msg.directive.header.name, msg.directive.header.correlationToken, msg.directive.endpoint?.endpointId);
|
|
74
74
|
options.eventBus.emit(msg.directive.header.namespace, msg, function (err, response) {
|
|
75
75
|
// TODO: if no message, return error Response
|
|
76
76
|
if (response == null) {
|
|
77
77
|
response = _alexaErrorResponse(msg);
|
|
78
|
+
this.log.error("ERROR Response", JSON.stringify(msg));
|
|
78
79
|
}
|
|
79
80
|
// debug("Response", JSON.stringify(response));
|
|
80
81
|
connection.client.publish("response/" + username + "/1", JSON.stringify(response));
|
package/src/lib/alexaMessages.js
CHANGED
|
@@ -21,6 +21,7 @@ function alexaResponse(message, hbResponse, err, value) {
|
|
|
21
21
|
"namespace": "Alexa",
|
|
22
22
|
"name": "ErrorResponse",
|
|
23
23
|
"messageId": message.directive.header.messageId,
|
|
24
|
+
"correlationToken": message.directive.header.correlationToken,
|
|
24
25
|
"payloadVersion": "3"
|
|
25
26
|
},
|
|
26
27
|
"endpoint": {
|
|
@@ -40,6 +41,7 @@ function alexaResponse(message, hbResponse, err, value) {
|
|
|
40
41
|
"namespace": "Alexa",
|
|
41
42
|
"name": "ErrorResponse",
|
|
42
43
|
"messageId": message.directive.header.messageId,
|
|
44
|
+
"correlationToken": message.directive.header.correlationToken,
|
|
43
45
|
"payloadVersion": "3"
|
|
44
46
|
},
|
|
45
47
|
"endpoint": {
|
|
@@ -236,7 +236,7 @@ function stateToProperties(statusObject, hbResponse) {
|
|
|
236
236
|
"timeOfSample": now.toISOString(),
|
|
237
237
|
"uncertaintyInMilliseconds": 500
|
|
238
238
|
});
|
|
239
|
-
|
|
239
|
+
}
|
|
240
240
|
break;
|
|
241
241
|
default:
|
|
242
242
|
debug("ERROR: statusReport unknown/handled device", element, reportState);
|
|
@@ -1282,7 +1282,7 @@ function _getValue(element, hbResponse) {
|
|
|
1282
1282
|
}
|
|
1283
1283
|
|
|
1284
1284
|
function _getHBValue(element, hbResponse) {
|
|
1285
|
-
debug("_getHBValue", element, hbResponse);
|
|
1285
|
+
// debug("_getHBValue", JSON.stringify(element), JSON.stringify(hbResponse));
|
|
1286
1286
|
var value, status;
|
|
1287
1287
|
for (var i in hbResponse) {
|
|
1288
1288
|
if (hbResponse[i].aid === element.aid && hbResponse[i].iid === element.iid) {
|
package/src/plugin.js
CHANGED
|
@@ -21,6 +21,7 @@ module.exports = function (homebridge) {
|
|
|
21
21
|
|
|
22
22
|
function alexaHome(log, config, api) {
|
|
23
23
|
this.log = log;
|
|
24
|
+
this.api = api;
|
|
24
25
|
this.eventBus = new EventEmitter();
|
|
25
26
|
this.config = config;
|
|
26
27
|
this.pin = config['pin'] || "031-45-154";
|
|
@@ -113,6 +114,7 @@ alexaHome.prototype.didFinishLaunching = function () {
|
|
|
113
114
|
}
|
|
114
115
|
options = {
|
|
115
116
|
// Shared Options
|
|
117
|
+
api: this.api,
|
|
116
118
|
log: this.log,
|
|
117
119
|
debug: this.debug,
|
|
118
120
|
// MQTT Options
|