homebridge-alexa 0.10.0-beta.8 → 0.10.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 +25 -0
- package/README.md +12 -0
- package/config.schema.json +26 -1
- package/package.json +17 -11
- package/src/lib/alexaActions.js +28 -23
- package/src/lib/alexaActions.test.js +81 -1
- package/src/lib/alexaLocal.js +2 -5
- package/src/lib/alexaLocal.test.js +1 -0
- package/src/lib/alexaMessages.js +2 -2
- package/src/lib/alexaMessages.test.js +47 -3
- package/src/lib/discovery.notest.js +1 -0
- package/src/lib/parse/Accessory.js +3 -3
- package/src/lib/parse/Characteristic.js +23 -1
- package/src/lib/parse/Homebridge.js +15 -10
- package/src/lib/parse/Homebridges.js +11 -7
- package/src/lib/parse/Homebridges.test.js +47 -8
- package/src/lib/parse/Service.js +3 -1
- package/src/lib/parse/messages.js +90 -65
- package/src/lib/parse/messages.lookup.test.js +62 -1
- package/src/lib/parse/messages.stateToProperties.test.ts +1 -1
- package/src/plugin.js +6 -1
- package/src/plugin.notest.js +13 -9
- package/.eslintrc +0 -31
- package/.github/dependabot.yml +0 -47
- package/.github/npm-version-script.js +0 -97
- package/.github/workflows/Build_and_Publish.yml +0 -127
- package/eslint.config.mjs +0 -34
package/CHANGELOG.md
CHANGED
|
@@ -2,10 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/).
|
|
4
4
|
|
|
5
|
+
## 0.10.0 (2026-10-23)
|
|
6
|
+
|
|
7
|
+
## [Version 0.10.0](https://github.com/northernman54/homebridge-alexa/compare/0.9.3...0.10.0)
|
|
8
|
+
|
|
9
|
+
#### New Features
|
|
10
|
+
|
|
11
|
+
- **Smoke, Carbon Monoxide and Leak sensors as Contact Sensors** (#798, #799) – A new optional setting, `alexaAlertSensors`, sends these sensors to Alexa as Contact Sensors so they can trigger Alexa routines. For example, Alexa can announce which sensor went off. An alert shows as **DETECTED** and a clear sensor as **NOT_DETECTED**. These sensors work only in routines; there are no voice commands for them. Turn on `routines` as well so Alexa gets sensor events as they happen.
|
|
12
|
+
- **`instanceDenylist`** (#806) – Leave out whole Homebridge instances by their username (MAC address, e.g. `0E:12:34:56:78:9A`). This works the same way as in homebridge-gsh. You can set it in the plugin settings in the Homebridge UI.
|
|
13
|
+
|
|
14
|
+
#### Fixes
|
|
15
|
+
|
|
16
|
+
- Fixed playback controls on Yamaha Home accessories. Names with parentheses or quotes are now handled correctly.
|
|
17
|
+
- Motion, Contact, Smoke, Carbon Monoxide and Leak sensors can now always be queried, so Alexa can check their state when routines are enabled.
|
|
18
|
+
- `sendDeleteReport` now logs its errors properly, and a log line is written each time a delete report is sent.
|
|
19
|
+
- Each batch of pending device delete reports is now limited to 250.
|
|
20
|
+
|
|
21
|
+
#### Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies, including `@homebridge/hap-client` 5.3, `mqtt` 5.15, ESLint 10 and `axios`.
|
|
24
|
+
- Fixed lint issues (#813).
|
|
25
|
+
|
|
5
26
|
## 0.9.3 (2025-10-18)
|
|
6
27
|
|
|
7
28
|
## [Version 0.9.3](https://github.com/northernman54/homebridge-alexa/compare/0.9.2...0.9.3)
|
|
8
29
|
|
|
30
|
+
#### Fixes
|
|
31
|
+
|
|
32
|
+
- Fix for RangeController response property name for window covering state reporting (#786)
|
|
33
|
+
|
|
9
34
|
#### Changes
|
|
10
35
|
|
|
11
36
|
- Dependency Updates
|
package/README.md
CHANGED
|
@@ -71,6 +71,7 @@ Country availability - The plugin is available in these countries, English (AU),
|
|
|
71
71
|
* [Bose SoundLink - Change preset](#bose-soundlink---change-preset)
|
|
72
72
|
* [Yamaha Receiver/Spotify control](#yamaha-receiverspotify-control)
|
|
73
73
|
* [Contact and Motion Sensors](#contact-and-motion-sensors)
|
|
74
|
+
* [Smoke, Carbon Monoxide and Leak Sensors](#smoke-carbon-monoxide-and-leak-sensors)
|
|
74
75
|
* [Door bell devices](#door-bell-devices)
|
|
75
76
|
* [Installation of homebridge-alexa](#installation-of-homebridge-alexa)
|
|
76
77
|
* [Service Availability and Issues](#service-availability-and-issues)
|
|
@@ -95,6 +96,7 @@ Country availability - The plugin is available in these countries, English (AU),
|
|
|
95
96
|
* Support for Temperature, Contact and Motion Sensors.
|
|
96
97
|
* Support for Occupancy Sensors as a Contact sensor.
|
|
97
98
|
* Also supports sending real time updates from Contact, Occupancy and Motion sensors to Alexa, for use in routines.
|
|
99
|
+
* Support for Smoke, Carbon Monoxide and Leak sensors as Contact Sensors for Alexa routines (requires `alexaAlertSensors` option to be enabled)
|
|
98
100
|
* Support for Fan2 aka Dyson fans
|
|
99
101
|
* Support for Valves, Sprinklers and Shower Heads (As Alexa doesn't support these, they are Other)
|
|
100
102
|
* Support for more than 100 accessories
|
|
@@ -133,6 +135,7 @@ This only supports accessories connected via a homebridge plugin, any 'Homekit'
|
|
|
133
135
|
* Fans, Humidifier Dehumidifier and Air Purifiers - Supported as a Switch
|
|
134
136
|
* Valves, Sprinklers and Shower Heads - Supported as a light bulb
|
|
135
137
|
* Occupancy Sensors - Supported as a Contact Sensor
|
|
138
|
+
* Smoke, Carbon Monoxide and Leak Sensors - Supported as a Contact Sensor (requires `alexaAlertSensors` option)
|
|
136
139
|
|
|
137
140
|
### Non-Homebridge Devices
|
|
138
141
|
|
|
@@ -314,6 +317,14 @@ These are the remote buttons
|
|
|
314
317
|
|
|
315
318
|
* These are only visible to routines, no voice commands are available
|
|
316
319
|
|
|
320
|
+
## Smoke, Carbon Monoxide and Leak Sensors
|
|
321
|
+
|
|
322
|
+
* When the `alexaAlertSensors` option is enabled, Smoke, Carbon Monoxide and Leak sensors are published to Alexa as Contact Sensors.
|
|
323
|
+
* These are only visible to routines, no voice commands are available.
|
|
324
|
+
* When a sensor detects an alert (value = 1), Alexa sees the contact as **DETECTED** (open). When clear (value = 0), Alexa sees it as **NOT_DETECTED** (closed).
|
|
325
|
+
* This allows you to create Alexa routines triggered by smoke, CO or leak events, for example to make an Alexa announcement identifying which sensor was triggered.
|
|
326
|
+
* Enable the `routines` option alongside `alexaAlertSensors` to have Alexa proactively receive sensor events for use in routines.
|
|
327
|
+
|
|
317
328
|
## Door bell devices
|
|
318
329
|
|
|
319
330
|
* Their is no voice control of door bells, only the ability to have Alexa announce when the door bell is triggered. For a sample here is my [Door Bell](https://youtu.be/PhGbc_TO8pk) being rang.
|
|
@@ -407,3 +418,4 @@ See [Roadmap](Roadmap.md)
|
|
|
407
418
|
* jelvs - Validate TV Integration for homebridge-samsung-tizen
|
|
408
419
|
* krocko - bose soundlink preset / channel change
|
|
409
420
|
* pwilms - deviceList feature
|
|
421
|
+
|
package/config.schema.json
CHANGED
|
@@ -189,6 +189,14 @@
|
|
|
189
189
|
"functionBody": "if (model.deviceListHandling === 'allow' || model.deviceListHandling === 'deny') { return true } else { return false };"
|
|
190
190
|
}
|
|
191
191
|
},
|
|
192
|
+
"instanceDenylist": {
|
|
193
|
+
"title": "Homebridge instances to be denied",
|
|
194
|
+
"type": "array",
|
|
195
|
+
"items": {
|
|
196
|
+
"type": "string",
|
|
197
|
+
"pattern": "^([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}$"
|
|
198
|
+
}
|
|
199
|
+
},
|
|
192
200
|
"combine": {
|
|
193
201
|
"type": "array",
|
|
194
202
|
"items": {
|
|
@@ -232,6 +240,12 @@
|
|
|
232
240
|
"type": "boolean",
|
|
233
241
|
"placeholder": false,
|
|
234
242
|
"description": "This option will change the behaviour of the next or skip command of the 'appletv-enhanced' plugin, from skip to select. This will enable the wording 'Alexa tv skip' to press the select button on the Apple TV remote. This is useful for skipping adds on YouTube."
|
|
243
|
+
},
|
|
244
|
+
"alexaAlertSensors": {
|
|
245
|
+
"title": "<b>Smoke, Carbon Monoxide and Leak Sensors as Contact Sensors</b>",
|
|
246
|
+
"type": "boolean",
|
|
247
|
+
"placeholder": false,
|
|
248
|
+
"description": "Enables Smoke, Carbon Monoxide and Leak sensors to be published to Alexa as Contact Sensors. This allows these sensors to trigger Alexa routines when used with the 'Routines' option. Defaults to false."
|
|
235
249
|
}
|
|
236
250
|
}
|
|
237
251
|
},
|
|
@@ -261,6 +275,7 @@
|
|
|
261
275
|
"items": [
|
|
262
276
|
"pin",
|
|
263
277
|
"routines",
|
|
278
|
+
"alexaAlertSensors",
|
|
264
279
|
"deviceCleanup",
|
|
265
280
|
"debug",
|
|
266
281
|
"thermostatTurnOn",
|
|
@@ -277,6 +292,16 @@
|
|
|
277
292
|
"condition": {
|
|
278
293
|
"functionBody": "return model.deviceListHandling !== 'none';"
|
|
279
294
|
}
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
"key": "instanceDenylist",
|
|
298
|
+
"type": "array",
|
|
299
|
+
"items": {
|
|
300
|
+
"title": "UserName",
|
|
301
|
+
"description": "username of Homebridge instance you want to ignore",
|
|
302
|
+
"type": "string",
|
|
303
|
+
"placeholder": "Enter homebridge username..."
|
|
304
|
+
}
|
|
280
305
|
}
|
|
281
306
|
]
|
|
282
307
|
},
|
|
@@ -368,4 +393,4 @@
|
|
|
368
393
|
]
|
|
369
394
|
}
|
|
370
395
|
]
|
|
371
|
-
}
|
|
396
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-alexa",
|
|
3
|
-
"version": "0.10.0
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Control your Homebridge devices with Amazon Alexa.",
|
|
5
5
|
"main": "src/plugin.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"watch": [],
|
|
16
16
|
"ext": "js",
|
|
17
17
|
"ignore": [],
|
|
18
|
-
"exec": "~/
|
|
18
|
+
"exec": "~/node_modules/homebridge/bin/homebridge.js -U ./test/hbConfig -T -D -P .",
|
|
19
19
|
"signal": "SIGTERM",
|
|
20
20
|
"env": {
|
|
21
21
|
"NODE_OPTIONS": "--trace-warnings"
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
"homebridge-plugin"
|
|
35
35
|
],
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
37
|
+
"@eslint/js": "^10.0.1",
|
|
38
|
+
"@homebridge/hap-client": "^5.3.0",
|
|
39
39
|
"@types/jest": "^30.0.0",
|
|
40
|
-
"@
|
|
41
|
-
"eslint": "^9.37.0",
|
|
42
|
-
"eslint-plugin-format": "^1.0.2",
|
|
43
|
-
"eslint-plugin-jest": "^29.0.1",
|
|
40
|
+
"@types/node": "^25.4.0",
|
|
44
41
|
"babel-jest": "^30.2.0",
|
|
45
|
-
"
|
|
42
|
+
"eslint": "^10.0.3",
|
|
43
|
+
"eslint-plugin-format": "^2.0.1",
|
|
44
|
+
"eslint-plugin-jest": "^29.0.1",
|
|
45
|
+
"globals": "^17.4.0",
|
|
46
46
|
"jest": "^30.2.0",
|
|
47
47
|
"mqtt-connection": "^4.1.0",
|
|
48
48
|
"nodemon": "^3.1.9",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"debug": "4.4.3",
|
|
56
56
|
"hap-node-client": "^0.2.9",
|
|
57
57
|
"is-my-json-valid": "2.20.6",
|
|
58
|
-
"mqtt": "5.
|
|
58
|
+
"mqtt": "5.15.0"
|
|
59
59
|
},
|
|
60
60
|
"author": "NorthernMan54",
|
|
61
61
|
"license": "Apache-2.0",
|
|
@@ -72,5 +72,11 @@
|
|
|
72
72
|
"collectCoverageFrom": [
|
|
73
73
|
"src/**"
|
|
74
74
|
]
|
|
75
|
+
},
|
|
76
|
+
"allowScripts": {
|
|
77
|
+
"fsevents": true,
|
|
78
|
+
"@parcel/watcher": true,
|
|
79
|
+
"unrs-resolver": true,
|
|
80
|
+
"nodemon": true
|
|
75
81
|
}
|
|
76
|
-
}
|
|
82
|
+
}
|
package/src/lib/alexaActions.js
CHANGED
|
@@ -66,7 +66,7 @@ function registerEvents(message) {
|
|
|
66
66
|
|
|
67
67
|
var HBMessage = [];
|
|
68
68
|
|
|
69
|
-
for (
|
|
69
|
+
for (const key in message) {
|
|
70
70
|
var endpoint = JSON.parse(key);
|
|
71
71
|
var device = {
|
|
72
72
|
"aid": endpoint.aid,
|
|
@@ -86,7 +86,7 @@ function registerEvents(message) {
|
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
for (
|
|
89
|
+
for (const register in HBMessage) {
|
|
90
90
|
// console.log("send", instance, HBMessage[instance]);
|
|
91
91
|
var hbInstance = JSON.parse(register);
|
|
92
92
|
debug("Event Register %s ->", hbInstance.deviceID, HBMessage[register]);
|
|
@@ -123,7 +123,7 @@ function alexaDiscovery(message, callback) {
|
|
|
123
123
|
|
|
124
124
|
var deleteSeen = [];
|
|
125
125
|
|
|
126
|
-
for (
|
|
126
|
+
for (let i = 0; i < response.event.payload.endpoints.length; i++) {
|
|
127
127
|
var endpoint = response.event.payload.endpoints[i];
|
|
128
128
|
if (deleteSeen[endpoint.friendlyName]) {
|
|
129
129
|
this.log("WARNING: Duplicate device name", endpoint.friendlyName);
|
|
@@ -221,7 +221,7 @@ function checkDeviceList(endpoints) {
|
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
function verifyDeviceInList(deviceList, deviceName) {
|
|
224
|
-
for (
|
|
224
|
+
for (let i = 0, len = deviceList.length; i < len; i++) {
|
|
225
225
|
if (deviceName === deviceList[i] || deviceName.match(new RegExp(deviceList[i]))) return true;
|
|
226
226
|
}
|
|
227
227
|
return false;
|
|
@@ -491,7 +491,7 @@ function alexaChannelController(message, callback) {
|
|
|
491
491
|
return;
|
|
492
492
|
}
|
|
493
493
|
|
|
494
|
-
var channel
|
|
494
|
+
var channel;
|
|
495
495
|
if (message.directive.payload.channel.number) {
|
|
496
496
|
channel = message.directive.payload.channel.number;
|
|
497
497
|
} else if (message.directive.payload.channelMetadata.name) {
|
|
@@ -572,13 +572,13 @@ async function alexaThermostatController(message, callback) {
|
|
|
572
572
|
// targetSetpoint, lowerSetpoint, upperSetpoint
|
|
573
573
|
// debug("alexaThermostatController - SetTargetTemperature", JSON.stringify(payloads));
|
|
574
574
|
var characteristics = [];
|
|
575
|
-
for (
|
|
575
|
+
for (const index in payloads) {
|
|
576
576
|
try {
|
|
577
577
|
if (message.directive.endpoint.cookie[index]) {
|
|
578
578
|
haAction = JSON.parse(message.directive.endpoint.cookie[index]);
|
|
579
579
|
} else {
|
|
580
580
|
if (index === "targetSetpoint" && (message.directive.endpoint.cookie['lowerSetpoint'] || message.directive.endpoint.cookie['upperSetpoint'])) {
|
|
581
|
-
|
|
581
|
+
let mode = await retriveThermostatMode(message.directive.endpoint.cookie['ReportState']);
|
|
582
582
|
if (mode === 1) {
|
|
583
583
|
// Mode is Heat
|
|
584
584
|
haAction = JSON.parse(message.directive.endpoint.cookie['lowerSetpoint']);
|
|
@@ -598,7 +598,7 @@ async function alexaThermostatController(message, callback) {
|
|
|
598
598
|
} catch (e) {
|
|
599
599
|
// debug("alexaThermostatController ERROR: '%s' Action: '%s' ", e.message, index, message.directive.endpoint.cookie);
|
|
600
600
|
this.log("alexaThermostatController ERROR: '%s' Action: '%s' ", e.message, index, message.directive.endpoint.cookie);
|
|
601
|
-
|
|
601
|
+
let response = alexaMessages.alexaResponse(message, "", e);
|
|
602
602
|
response.event.payload.type = "INVALID_VALUE"; // The directive contains a value that is not valid for the target endpoint. For example, an invalid heating mode, channel, or program value.
|
|
603
603
|
callback(e, response);
|
|
604
604
|
return;
|
|
@@ -615,7 +615,7 @@ async function alexaThermostatController(message, callback) {
|
|
|
615
615
|
}
|
|
616
616
|
|
|
617
617
|
// debug("alexaThermostatController - characteristics", JSON.stringify(characteristics));
|
|
618
|
-
|
|
618
|
+
body = {
|
|
619
619
|
"characteristics": characteristics
|
|
620
620
|
};
|
|
621
621
|
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
@@ -636,7 +636,7 @@ async function alexaThermostatController(message, callback) {
|
|
|
636
636
|
var err = {
|
|
637
637
|
message: "Unknown action" + action
|
|
638
638
|
};
|
|
639
|
-
|
|
639
|
+
response = alexaMessages.alexaResponse(message, "", err);
|
|
640
640
|
response.event.payload.type = "INVALID_VALUE"; // The directive contains a value that is not valid for the target endpoint. For example, an invalid heating mode, channel, or program value.
|
|
641
641
|
callback(err, response);
|
|
642
642
|
}
|
|
@@ -766,12 +766,13 @@ function alexaRangeController(message, callback) {
|
|
|
766
766
|
callback(err, response);
|
|
767
767
|
}.bind(this));
|
|
768
768
|
break;
|
|
769
|
-
default:
|
|
769
|
+
default: {
|
|
770
770
|
var e = new Error("ERROR: alexaRangeController missing " + action);
|
|
771
771
|
this.log(e.message, message.directive.endpoint.cookie);
|
|
772
|
-
|
|
772
|
+
const response = alexaMessages.alexaResponse(message, "", e);
|
|
773
773
|
response.event.payload.type = "INVALID_VALUE"; // The directive contains a value that is not valid for the target endpoint. For example, an invalid heating mode, channel, or program value.
|
|
774
774
|
callback(e, response);
|
|
775
|
+
}
|
|
775
776
|
}
|
|
776
777
|
}
|
|
777
778
|
|
|
@@ -943,11 +944,11 @@ function alexaStepSpeaker(message, callback) {
|
|
|
943
944
|
callback(err, response);
|
|
944
945
|
}.bind(this));
|
|
945
946
|
break;
|
|
946
|
-
case "setmute":
|
|
947
|
+
case "setmute": {
|
|
947
948
|
// Characteristic.VolumeSelector.INCREMENT = 0;
|
|
948
949
|
// Characteristic.VolumeSelector.DECREMENT = 1;
|
|
949
950
|
const payload = message.directive.payload.mute;
|
|
950
|
-
|
|
951
|
+
const body = {
|
|
951
952
|
"characteristics": [{
|
|
952
953
|
"aid": haAction.aid,
|
|
953
954
|
"iid": haAction.iid,
|
|
@@ -960,6 +961,7 @@ function alexaStepSpeaker(message, callback) {
|
|
|
960
961
|
callback(err, response);
|
|
961
962
|
}.bind(this));
|
|
962
963
|
break;
|
|
964
|
+
}
|
|
963
965
|
default:
|
|
964
966
|
this.log.error("Unhandled alexaStepSpeaker Directive", message.directive.header.name);
|
|
965
967
|
}
|
|
@@ -1054,7 +1056,7 @@ function alexaMessage(message, callback) {
|
|
|
1054
1056
|
|
|
1055
1057
|
default:
|
|
1056
1058
|
this.log("Unhandled alexaMessage Directive", message.directive.header.name);
|
|
1057
|
-
|
|
1059
|
+
response = {
|
|
1058
1060
|
"event": {
|
|
1059
1061
|
"header": {
|
|
1060
1062
|
"name": "ErrorResponse",
|
|
@@ -1098,7 +1100,7 @@ async function processStatusArray(statusArray, message) {
|
|
|
1098
1100
|
}
|
|
1099
1101
|
}
|
|
1100
1102
|
|
|
1101
|
-
function _HAPstatusByDeviceID(statusObject
|
|
1103
|
+
function _HAPstatusByDeviceID(statusObject) {
|
|
1102
1104
|
// debug("_HAPstatusByDeviceID-1", JSON.stringify(statusObject));
|
|
1103
1105
|
return new Promise((resolve, reject) => {
|
|
1104
1106
|
homebridge.HAPstatusByDeviceID(statusObject.deviceID, statusObject.body, function (err, status) {
|
|
@@ -1169,16 +1171,18 @@ let errorReportTimer = null;
|
|
|
1169
1171
|
function reportDeviceError(message) {
|
|
1170
1172
|
const endpointId = message.directive.endpoint.endpointId;
|
|
1171
1173
|
|
|
1172
|
-
//
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1174
|
+
// Add endpointId to the set, unless the set is already full
|
|
1175
|
+
if (pendingErrors.size >= 250) {
|
|
1176
|
+
this.log.error("Error: Device not responding, too many pending delete reports, skipping", endpointId);
|
|
1177
|
+
} else {
|
|
1178
|
+
this.log.error("Error: Device not responding, scheduling delete report", endpointId);
|
|
1179
|
+
pendingErrors.add(endpointId);
|
|
1180
|
+
}
|
|
1177
1181
|
|
|
1178
1182
|
// Start a single timer if not already running
|
|
1179
1183
|
if (!errorReportTimer) {
|
|
1180
1184
|
errorReportTimer = setTimeout(() => {
|
|
1181
|
-
sendDeleteReport();
|
|
1185
|
+
sendDeleteReport.call(this);
|
|
1182
1186
|
}, 30000); // 30-second delay
|
|
1183
1187
|
}
|
|
1184
1188
|
}
|
|
@@ -1206,8 +1210,9 @@ function sendDeleteReport() {
|
|
|
1206
1210
|
}
|
|
1207
1211
|
}
|
|
1208
1212
|
});
|
|
1213
|
+
this.log("sendDeleteReport - sent delete report for %s devices", endpoints.length);
|
|
1209
1214
|
} catch (e) {
|
|
1210
|
-
|
|
1215
|
+
this.log.error("sendDeleteReport error:", e);
|
|
1211
1216
|
} finally {
|
|
1212
1217
|
pendingErrors.clear();
|
|
1213
1218
|
errorReportTimer = null; // Reset timer reference
|
|
@@ -1,3 +1,83 @@
|
|
|
1
|
+
/* global __dirname */
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
describe('lib/alexaActions', () => {
|
|
6
|
+
describe('checkDeviceList', () => {
|
|
7
|
+
// Helper to load the two functions from the source file without executing the whole module
|
|
8
|
+
function loadCheckDeviceList() {
|
|
9
|
+
const filePath = path.join(__dirname, 'alexaActions.js');
|
|
10
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
11
|
+
|
|
12
|
+
// Extract verifyDeviceInList
|
|
13
|
+
const verifyStart = content.indexOf('function verifyDeviceInList');
|
|
14
|
+
const alexaNext = 'function alexaColorTemperatureController';
|
|
15
|
+
const verifyEnd = content.indexOf(alexaNext, verifyStart);
|
|
16
|
+
if (verifyStart === -1 || verifyEnd === -1) {
|
|
17
|
+
throw new Error('Could not locate verifyDeviceInList in alexaActions.js');
|
|
18
|
+
}
|
|
19
|
+
const verifySource = content.substring(verifyStart, verifyEnd).trim();
|
|
20
|
+
|
|
21
|
+
// Extract checkDeviceList which appears before verifyDeviceInList
|
|
22
|
+
const checkStart = content.indexOf('function checkDeviceList');
|
|
23
|
+
if (checkStart === -1) {
|
|
24
|
+
throw new Error('Could not locate checkDeviceList in alexaActions.js');
|
|
25
|
+
}
|
|
26
|
+
const checkEnd = verifyStart; // up to verify function
|
|
27
|
+
const checkSource = content.substring(checkStart, checkEnd).trim();
|
|
28
|
+
|
|
29
|
+
// Build an isolated evaluator that returns the two functions
|
|
30
|
+
const wrapper = `${verifySource}\n\n${checkSource}\n\nreturn { verifyDeviceInList, checkDeviceList };`;
|
|
31
|
+
|
|
32
|
+
const fn = new Function(wrapper);
|
|
33
|
+
return fn();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
test('returns same endpoints when deviceList not configured', () => {
|
|
37
|
+
const { checkDeviceList } = loadCheckDeviceList();
|
|
38
|
+
const ctx = {}; // no deviceList
|
|
39
|
+
const endpoints = [{ friendlyName: 'One' }, { friendlyName: 'Two' }];
|
|
40
|
+
const result = checkDeviceList.call(ctx, endpoints);
|
|
41
|
+
expect(result).toEqual(endpoints);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('allow mode keeps only listed devices (exact match)', () => {
|
|
45
|
+
const { checkDeviceList } = loadCheckDeviceList();
|
|
46
|
+
const ctx = {
|
|
47
|
+
deviceList: ['Lamp'],
|
|
48
|
+
deviceListHandling: 'allow',
|
|
49
|
+
log: () => { }
|
|
50
|
+
};
|
|
51
|
+
const endpoints = [{ friendlyName: 'Lamp' }, { friendlyName: 'Fan' }];
|
|
52
|
+
const result = checkDeviceList.call(ctx, endpoints);
|
|
53
|
+
expect(result).toEqual([{ friendlyName: 'Lamp' }]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('allow mode supports regex entries', () => {
|
|
57
|
+
const { checkDeviceList } = loadCheckDeviceList();
|
|
58
|
+
const ctx = {
|
|
59
|
+
deviceList: ['^Lamp'],
|
|
60
|
+
deviceListHandling: 'allow',
|
|
61
|
+
log: () => { }
|
|
62
|
+
};
|
|
63
|
+
const endpoints = [{ friendlyName: 'Lamp 1' }, { friendlyName: 'Lamp 2' }, { friendlyName: 'Other' }];
|
|
64
|
+
const result = checkDeviceList.call(ctx, endpoints);
|
|
65
|
+
expect(result).toEqual([{ friendlyName: 'Lamp 1' }, { friendlyName: 'Lamp 2' }]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('deny mode removes listed devices', () => {
|
|
69
|
+
const { checkDeviceList } = loadCheckDeviceList();
|
|
70
|
+
const ctx = {
|
|
71
|
+
deviceList: ['ExcludeMe'],
|
|
72
|
+
deviceListHandling: 'deny',
|
|
73
|
+
log: () => { }
|
|
74
|
+
};
|
|
75
|
+
const endpoints = [{ friendlyName: 'KeepMe' }, { friendlyName: 'ExcludeMe' }];
|
|
76
|
+
const result = checkDeviceList.call(ctx, endpoints);
|
|
77
|
+
expect(result).toEqual([{ friendlyName: 'KeepMe' }]);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
1
81
|
const { alexaMessage, setHomebridge, destroy, alexaThermostatController } = require('./alexaActions.js');
|
|
2
82
|
|
|
3
83
|
jest.mock("hap-node-client", () => {
|
|
@@ -315,7 +395,7 @@ const message1 = {
|
|
|
315
395
|
"cookie": {
|
|
316
396
|
"TurnOn": "{\"deviceID\":\"ColorController-1\",\"aid\":10,\"iid\":10,\"value\":1}",
|
|
317
397
|
"AdjustPowerLevel": "{\"deviceID\":\"ColorController-1\",\"aid\":10,\"iid\":11}",
|
|
318
|
-
"ReportState": "[{\"interface\":\"Alexa.PowerLevelController\",\"deviceID\":\"ColorController-1\",\"aid\":10,\"iid\":11}
|
|
398
|
+
"ReportState": "[{\"interface\":\"Alexa.PowerLevelController\",\"deviceID\":\"ColorController-1\",\"aid\":10,\"iid\":11},{\"interface\":\"Alexa.ColorTemperatureController\",\"deviceID\":\"ColorController-1\",\"aid\":10,\"iid\":13},{\"interface\":\"Alexa.PowerController\",\"deviceID\":\"ColorController-1\",\"aid\":10,\"iid\":10},{\"interface\":\"Alexa.ColorController\",\"deviceID\":\"ColorController-1\",\"hue\":{\"aid\":10,\"iid\":14},\"saturation\":{\"aid\":10,\"iid\":15},\"brightness\":{\"aid\":10,\"iid\":11},\"on\":{\"aid\":10,\"iid\":10}}]",
|
|
319
399
|
"SetColorTemperature": "{\"deviceID\":\"ColorController-1\",\"aid\":10,\"iid\":13}",
|
|
320
400
|
"BrightnessTurnOn": "true",
|
|
321
401
|
"DecreaseColorTemperature": "{\"deviceID\":\"ColorController-1\",\"aid\":10,\"iid\":13}",
|
package/src/lib/alexaLocal.js
CHANGED
|
@@ -4,11 +4,7 @@ const process = require('process');
|
|
|
4
4
|
const mqtt = require('mqtt');
|
|
5
5
|
const debug = require('debug')('alexaLocal');
|
|
6
6
|
const Bottleneck = require('bottleneck');
|
|
7
|
-
const Validator = require('is-my-json-valid');
|
|
8
7
|
const packageConfig = require('../../package.json');
|
|
9
|
-
const alexaSchema = require('./alexa_smart_home_message_schema.json');
|
|
10
|
-
|
|
11
|
-
const checkAlexaMessage = Validator(alexaSchema, { verbose: true });
|
|
12
8
|
|
|
13
9
|
let connection = {};
|
|
14
10
|
let count = 0;
|
|
@@ -146,13 +142,14 @@ function handleError(err, options) {
|
|
|
146
142
|
}
|
|
147
143
|
|
|
148
144
|
switch (err.code) {
|
|
149
|
-
case 5:
|
|
145
|
+
case 5: {
|
|
150
146
|
const errorMessage = process.uptime() < 20
|
|
151
147
|
? "Login failed. Validate credentials in config.json."
|
|
152
148
|
: "Login failed. Validate configuration in config.json.";
|
|
153
149
|
options.log.error(`ERROR: (homebridge-alexa) ${errorMessage}`);
|
|
154
150
|
connection.client.end({ force: true });
|
|
155
151
|
break;
|
|
152
|
+
}
|
|
156
153
|
case 'ECONNREFUSED':
|
|
157
154
|
options.log.error("ERROR: Cloud service DDOS Protection triggered. Stop Homebridge for 5-10 minutes and try again.");
|
|
158
155
|
break;
|
package/src/lib/alexaMessages.js
CHANGED
|
@@ -190,7 +190,7 @@ function alexaResponse(message, hbResponse, err, value) {
|
|
|
190
190
|
"properties": [{
|
|
191
191
|
"namespace": "Alexa.RangeController",
|
|
192
192
|
"instance": message.directive.header.instance,
|
|
193
|
-
"name":
|
|
193
|
+
"name": "rangeValue",
|
|
194
194
|
"value": value,
|
|
195
195
|
"timeOfSample": now.toISOString(),
|
|
196
196
|
"uncertaintyInMilliseconds": 500
|
|
@@ -704,7 +704,7 @@ function eventMessage(event, device) {
|
|
|
704
704
|
console.log("ERROR: homebridge-alexa.alexaMessages Missing device");
|
|
705
705
|
}
|
|
706
706
|
} catch (err) {
|
|
707
|
-
|
|
707
|
+
debug("ERROR: homebridge-alexa.alexaMessages.eventMessage", err);
|
|
708
708
|
}
|
|
709
709
|
return (message);
|
|
710
710
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const { alexaResponse, alexaStateResponse, eventMessage } = require('
|
|
2
|
-
const messages = require('
|
|
1
|
+
const { alexaResponse, alexaStateResponse, eventMessage } = require('./alexaMessages');
|
|
2
|
+
const messages = require('./parse/messages');
|
|
3
3
|
|
|
4
|
-
jest.mock('
|
|
4
|
+
jest.mock('./parse/messages');
|
|
5
5
|
|
|
6
6
|
describe('alexaMessages', () => {
|
|
7
7
|
describe('alexaResponse', () => {
|
|
@@ -81,6 +81,50 @@ describe('alexaMessages', () => {
|
|
|
81
81
|
expect(response.context.properties[0].value).toBe('ON');
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
+
test('should return correct response for Alexa.RangeController SetRangeValue', () => {
|
|
85
|
+
const message = {
|
|
86
|
+
directive: {
|
|
87
|
+
header: {
|
|
88
|
+
messageId: '123',
|
|
89
|
+
namespace: 'Alexa.RangeController',
|
|
90
|
+
name: 'SetRangeValue',
|
|
91
|
+
instance: 'Blind.Lift'
|
|
92
|
+
},
|
|
93
|
+
endpoint: {
|
|
94
|
+
endpointId: 'endpoint-001'
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const rangeValue = 50;
|
|
99
|
+
const response = alexaResponse(message, { characteristics: [{ status: 0 }] }, null, rangeValue);
|
|
100
|
+
expect(response.context.properties[0].namespace).toBe('Alexa.RangeController');
|
|
101
|
+
expect(response.context.properties[0].instance).toBe('Blind.Lift');
|
|
102
|
+
expect(response.context.properties[0].name).toBe('rangeValue');
|
|
103
|
+
expect(response.context.properties[0].value).toBe(50);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('should return correct response for Alexa.RangeController AdjustRangeValue', () => {
|
|
107
|
+
const message = {
|
|
108
|
+
directive: {
|
|
109
|
+
header: {
|
|
110
|
+
messageId: '123',
|
|
111
|
+
namespace: 'Alexa.RangeController',
|
|
112
|
+
name: 'AdjustRangeValue',
|
|
113
|
+
instance: 'Blind.Lift'
|
|
114
|
+
},
|
|
115
|
+
endpoint: {
|
|
116
|
+
endpointId: 'endpoint-001'
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const rangeValue = 75;
|
|
121
|
+
const response = alexaResponse(message, { characteristics: [{ status: 0 }] }, null, rangeValue);
|
|
122
|
+
expect(response.context.properties[0].namespace).toBe('Alexa.RangeController');
|
|
123
|
+
expect(response.context.properties[0].instance).toBe('Blind.Lift');
|
|
124
|
+
expect(response.context.properties[0].name).toBe('rangeValue');
|
|
125
|
+
expect(response.context.properties[0].value).toBe(75);
|
|
126
|
+
});
|
|
127
|
+
|
|
84
128
|
// Add more test cases for other namespaces and scenarios
|
|
85
129
|
});
|
|
86
130
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var debug = require('debug')('alexa:Accessory');
|
|
1
|
+
// var debug = require('debug')('alexa:Accessory');
|
|
2
2
|
var Service = require('./Service.js').Service;
|
|
3
3
|
var messages = require('./messages.js');
|
|
4
4
|
|
|
@@ -112,8 +112,8 @@ Accessory.prototype.toAlexa = function (context) {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
for (
|
|
116
|
-
|
|
115
|
+
for (const index in this.services) {
|
|
116
|
+
const service = this.services[index];
|
|
117
117
|
if ((this.television && service.service === "Speaker") || service.service === "Television" || service.service === "Input Source") {
|
|
118
118
|
// Skip television accessories
|
|
119
119
|
} else if (service.name === "Alexa" && service.service === "Contact Sensor" && service.info.Manufacturer === "homebridge-alexa") {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var debug = require('debug')('alexa:Characteristic');
|
|
1
|
+
// var debug = require('debug')('alexa:Characteristic');
|
|
2
2
|
var messages = require('./messages.js');
|
|
3
3
|
|
|
4
4
|
module.exports = {
|
|
@@ -166,6 +166,27 @@ function _getActions(description, context, devices) {
|
|
|
166
166
|
"template": "ContactSensor"
|
|
167
167
|
};
|
|
168
168
|
break;
|
|
169
|
+
case "Smoke Detected": // Smoke Sensor
|
|
170
|
+
case "Carbon Monoxide Detected": // Carbon Monoxide Sensor
|
|
171
|
+
case "Leak Detected": // Leak Sensor
|
|
172
|
+
// Publish these sensors as contact sensors so they can trigger Alexa routines
|
|
173
|
+
// Value 1 = detected, Value 0 = not detected
|
|
174
|
+
if (context.options.alexaAlertSensors) {
|
|
175
|
+
reportState.push(messages.reportState("Alexa.ContactSensor", context));
|
|
176
|
+
hapEvents[JSON.stringify({
|
|
177
|
+
"deviceID": context.deviceID,
|
|
178
|
+
|
|
179
|
+
"aid": context.aid,
|
|
180
|
+
"iid": context.liid
|
|
181
|
+
})] = {
|
|
182
|
+
"endpointID": context.endpointID,
|
|
183
|
+
"friendlyName": context.name,
|
|
184
|
+
"1": "DETECTED", // Smoke/CO/Leak detected maps to contact open
|
|
185
|
+
"0": "NOT_DETECTED",
|
|
186
|
+
"template": "ContactSensor"
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
break;
|
|
169
190
|
case "Programmable Switch Event": // aka Doorbell
|
|
170
191
|
// debug("PSE", context.service, context);
|
|
171
192
|
if (context.service === 'Doorbell') { // Only for PSE's that are part of the Doorbell service
|
|
@@ -265,6 +286,7 @@ function _getActions(description, context, devices) {
|
|
|
265
286
|
cookie["TurnOn"] = messages.cookieV(context.options.thermostatTurnOn, context); // Defaults to That command does not work
|
|
266
287
|
}
|
|
267
288
|
cookie["TurnOff"] = messages.cookieV(0, context); // OFF
|
|
289
|
+
// falls through
|
|
268
290
|
case "Target Heater-Cooler State":
|
|
269
291
|
case "Target Heater Cooler State":
|
|
270
292
|
reportState.push(messages.reportState("Alexa.ThermostatControllerthermostatMode", context));
|