homebridge-alexa 0.6.6 → 0.6.8
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/.eslintrc +31 -0
- package/.github/workflows/Build and Publish.yml +92 -0
- package/CHANGELOG.md +16 -0
- package/Installation.md +1 -1
- package/README.md +3 -3
- package/Troubleshooting.md +1 -1
- package/lib/alexaActions.js +88 -39
- package/lib/alexaMessages.js +13 -13
- package/package.json +4 -4
- package/alexaDiscovery.json +0 -3016
package/.eslintrc
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parser": "@typescript-eslint/parser",
|
|
3
|
+
"extends": [
|
|
4
|
+
"eslint:recommended",
|
|
5
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
6
|
+
"plugin:@typescript-eslint/recommended", // uses the recommended rules from the @typescript-eslint/eslint-plugin
|
|
7
|
+
"plugin:jest/recommended" // enables eslint-plugin-jest
|
|
8
|
+
],
|
|
9
|
+
"parserOptions": {
|
|
10
|
+
"ecmaVersion": 2018,
|
|
11
|
+
"sourceType": "module"
|
|
12
|
+
},
|
|
13
|
+
"ignorePatterns": [
|
|
14
|
+
"bin/",
|
|
15
|
+
"lib/"
|
|
16
|
+
],
|
|
17
|
+
"rules": {
|
|
18
|
+
"quotes": ["error", "double"],
|
|
19
|
+
"indent": ["error", 2, { "SwitchCase": 1 }],
|
|
20
|
+
"linebreak-style": ["error", "unix"],
|
|
21
|
+
"semi": ["error", "always"],
|
|
22
|
+
|
|
23
|
+
"comma-dangle": ["error", "always-multiline"],
|
|
24
|
+
"dot-notation": "error",
|
|
25
|
+
"eqeqeq": ["error", "always", {"null": "ignore"}],
|
|
26
|
+
"curly": ["error", "all"],
|
|
27
|
+
"brace-style": ["error"],
|
|
28
|
+
|
|
29
|
+
"@typescript-eslint/no-non-null-assertion": "off" // currently disabled, hap-nodejs has some bad typing (like getCharacteristic) for this to be enabled
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
name: "Build and Publish"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [beta-*.*.*, beta]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
get_tags:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
steps:
|
|
13
|
+
# checkout repo
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
# get branch / tag name
|
|
17
|
+
- name: Get Branch / Tag Name
|
|
18
|
+
id: get_branch
|
|
19
|
+
run: |
|
|
20
|
+
export BRANCH_NAME=$(if [[ ${GITHUB_REF} =~ "refs/tags/" ]]; then echo ${GITHUB_REF/refs\/tags\//}; else echo ${GITHUB_REF/refs\/heads\//}; fi)
|
|
21
|
+
echo $BRANCH_NAME
|
|
22
|
+
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT
|
|
23
|
+
|
|
24
|
+
# generate the image tag
|
|
25
|
+
- name: Get Image Tag
|
|
26
|
+
id: get_tag
|
|
27
|
+
run: |
|
|
28
|
+
export TARGET_IMAGE_TAG=$(if [ "${{ steps.get_branch.outputs.BRANCH_NAME }}" = "main" ]; then echo "main"; else echo "${{ steps.get_branch.outputs.BRANCH_NAME }}" | awk -F- '{ print $1 }'; fi)
|
|
29
|
+
echo $TARGET_IMAGE_TAG
|
|
30
|
+
echo "TARGET_IMAGE_TAG=${TARGET_IMAGE_TAG}" >> $GITHUB_OUTPUT
|
|
31
|
+
|
|
32
|
+
outputs:
|
|
33
|
+
BRANCH_NAME: ${{ steps.get_branch.outputs.BRANCH_NAME }}
|
|
34
|
+
TARGET_IMAGE_TAG: ${{ steps.get_tag.outputs.TARGET_IMAGE_TAG }}
|
|
35
|
+
|
|
36
|
+
create_documentation:
|
|
37
|
+
runs-on: ubuntu-latest
|
|
38
|
+
|
|
39
|
+
steps:
|
|
40
|
+
# checkout repo
|
|
41
|
+
- uses: actions/checkout@v4
|
|
42
|
+
with:
|
|
43
|
+
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
|
|
44
|
+
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
|
|
45
|
+
|
|
46
|
+
- uses: actions/setup-node@v3
|
|
47
|
+
with:
|
|
48
|
+
node-version: lts/*
|
|
49
|
+
|
|
50
|
+
- name: Retrieve github-markdown-toc
|
|
51
|
+
run: |
|
|
52
|
+
wget -q https://raw.githubusercontent.com/ekalinin/github-markdown-toc/master/gh-md-toc
|
|
53
|
+
chmod a+x gh-md-toc
|
|
54
|
+
|
|
55
|
+
- name: Create Table of Contents
|
|
56
|
+
run: |
|
|
57
|
+
npm run-script document
|
|
58
|
+
|
|
59
|
+
- name: Commit files
|
|
60
|
+
run: |
|
|
61
|
+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
|
62
|
+
git config --local user.name "github-actions[bot]"
|
|
63
|
+
git commit -a -m "Update TOC"
|
|
64
|
+
|
|
65
|
+
- name: Push changes
|
|
66
|
+
uses: ad-m/github-push-action@master
|
|
67
|
+
with:
|
|
68
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
69
|
+
branch: ${{ github.ref }}
|
|
70
|
+
|
|
71
|
+
publish_release:
|
|
72
|
+
needs: [get_tags, create_documentation]
|
|
73
|
+
name: Publish Release Version
|
|
74
|
+
if: ${{ needs.get_tags.outputs.BRANCH_NAME == 'main' }}
|
|
75
|
+
uses: homebridge/.github/.github/workflows/npm-publish.yml@latest
|
|
76
|
+
with:
|
|
77
|
+
install_cmd: npm ci
|
|
78
|
+
secrets:
|
|
79
|
+
npm_auth_token: ${{ secrets.npm_token }}
|
|
80
|
+
|
|
81
|
+
publish_test:
|
|
82
|
+
needs: [get_tags, create_documentation]
|
|
83
|
+
name: Publish Test Version - ${{ needs.get_tags.outputs.BRANCH_NAME }}
|
|
84
|
+
if: ${{ needs.get_tags.outputs.BRANCH_NAME != 'main' }}
|
|
85
|
+
uses: homebridge/.github/.github/workflows/npm-publish.yml@latest
|
|
86
|
+
with:
|
|
87
|
+
tag: ${{ needs.get_tags.outputs.TARGET_IMAGE_TAG }}
|
|
88
|
+
dynamically_adjust_version: true
|
|
89
|
+
npm_version_command: 'pre'
|
|
90
|
+
pre_id: ${{ needs.get_tags.outputs.TARGET_IMAGE_TAG }}
|
|
91
|
+
secrets:
|
|
92
|
+
npm_auth_token: ${{ secrets.npm_token }}
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
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.6.8 (2023-12-13)
|
|
6
|
+
|
|
7
|
+
## [Version 0.6.8](https://github.com/northernman54/homebridge-alexa/compare/v0.6.7...v0.6.8)
|
|
8
|
+
|
|
9
|
+
#### Changes
|
|
10
|
+
|
|
11
|
+
- Fix for issue #591, Window coverings / blinds show as unresponsive in the Alexa App
|
|
12
|
+
|
|
13
|
+
## 0.6.7 (2023-09-27)
|
|
14
|
+
|
|
15
|
+
## [Version 0.6.7](https://github.com/northernman54/homebridge-alexa/compare/v0.6.6...v0.6.7)
|
|
16
|
+
|
|
17
|
+
#### Changes
|
|
18
|
+
|
|
19
|
+
- Fix for issue #579, AC can't change temperature
|
|
20
|
+
|
|
5
21
|
## 0.6.6 (2023-07-07)
|
|
6
22
|
|
|
7
23
|
## [Version 0.6.6](https://github.com/northernman54/homebridge-alexa/compare/v0.6.5...v0.6.6)
|
package/Installation.md
CHANGED
|
@@ -41,7 +41,7 @@ Installation and Configuration of Homebridge Alexa
|
|
|
41
41
|
* [Discover Devices](#discover-devices)
|
|
42
42
|
|
|
43
43
|
<!-- Created by https://github.com/ekalinin/github-markdown-toc -->
|
|
44
|
-
<!-- Added by:
|
|
44
|
+
<!-- Added by: runner, at: Wed Dec 13 14:15:55 UTC 2023 -->
|
|
45
45
|
|
|
46
46
|
<!--te-->
|
|
47
47
|
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<img src="docs/homebridge.png" height="200">
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
|
-
Enable Amazon Alexa to control your homebridge smart home devices and accessories. Please note, that this does **NOT** bring Alexa enabled devices into homebridge. Full support for all Amazon Alexa devices, including the echo 2nd Generation and software based solutions. Uses an Amazon smart home skill based approach for integration between HomeBridge and Amazon Alexa.
|
|
9
|
+
Enable Amazon Alexa to control your homebridge smart home devices and accessories. Please note, that this does **NOT** bring Alexa enabled devices into homebridge, for this please try [homebridge-alexa-smarthome](https://github.com/joeyhage/homebridge-alexa-smarthome). Full support for all Amazon Alexa devices, including the echo 2nd Generation and software based solutions. Uses an Amazon smart home skill based approach for integration between HomeBridge and Amazon Alexa.
|
|
10
10
|
|
|
11
11
|
# Note to users of the service
|
|
12
12
|
|
|
@@ -84,7 +84,7 @@ Country availability - The plugin is available in these countries, English (AU),
|
|
|
84
84
|
* [Credits](#credits)
|
|
85
85
|
|
|
86
86
|
<!-- Created by https://github.com/ekalinin/github-markdown-toc -->
|
|
87
|
-
<!-- Added by:
|
|
87
|
+
<!-- Added by: runner, at: Wed Dec 13 14:15:55 UTC 2023 -->
|
|
88
88
|
|
|
89
89
|
<!--te-->
|
|
90
90
|
|
|
@@ -333,7 +333,7 @@ From here you should be able to determine if your plugin is communicating with t
|
|
|
333
333
|
|
|
334
334
|
### Known Issues
|
|
335
335
|
|
|
336
|
-
* I have started recording troubleshooting tips here based on issues seen by the community [Troubleshooting](Troubleshooting.
|
|
336
|
+
* I have started recording troubleshooting tips here based on issues seen by the community [Troubleshooting](Troubleshooting.md).
|
|
337
337
|
* All homebridge PIN's in your setup need to be set to the same value.
|
|
338
338
|
* An Alexa device or a software based Alexa is required. Using just the App or Website does not work, and device discovery will fail to find devices. The Reverb app is a software based Alexa that is known to work.
|
|
339
339
|
* The maximum number of supported devices is 300. This is a limitation from the from the Amazon side, and not the plugin.
|
package/Troubleshooting.md
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* [[Alexa] ERROR: Event gateway token refresh error: 400](#alexa-error--event-gateway-token-refresh-error-400)
|
|
35
35
|
|
|
36
36
|
<!-- Created by https://github.com/ekalinin/github-markdown-toc -->
|
|
37
|
-
<!-- Added by:
|
|
37
|
+
<!-- Added by: runner, at: Wed Dec 13 14:15:55 UTC 2023 -->
|
|
38
38
|
|
|
39
39
|
<!--te-->
|
|
40
40
|
|
package/lib/alexaActions.js
CHANGED
|
@@ -32,8 +32,8 @@ module.exports = {
|
|
|
32
32
|
function hapDiscovery(options) {
|
|
33
33
|
homebridge = new HAPNodeJSClient(options);
|
|
34
34
|
|
|
35
|
-
homebridge.on('Ready', function() {
|
|
36
|
-
alexaDiscovery.call(options, null, function() {
|
|
35
|
+
homebridge.on('Ready', function () {
|
|
36
|
+
alexaDiscovery.call(options, null, function () {
|
|
37
37
|
// debug("Events", options);
|
|
38
38
|
if (options.events) {
|
|
39
39
|
registerEvents(messages.checkEventDeviceList.call(options, hbDevices.toEvents()));
|
|
@@ -41,7 +41,7 @@ function hapDiscovery(options) {
|
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
homebridge.on('hapEvent', function(event) {
|
|
44
|
+
homebridge.on('hapEvent', function (event) {
|
|
45
45
|
// debug("Event Relay - 2", event);
|
|
46
46
|
options.eventBus.emit('hapEvent', event);
|
|
47
47
|
});
|
|
@@ -77,7 +77,7 @@ function registerEvents(message) {
|
|
|
77
77
|
// console.log("send", instance, HBMessage[instance]);
|
|
78
78
|
var hbInstance = JSON.parse(register);
|
|
79
79
|
debug("Event Register %s ->", hbInstance.deviceID, HBMessage[register]);
|
|
80
|
-
homebridge.HAPeventByDeviceID(hbInstance.deviceID, JSON.stringify(HBMessage[register]), function(err, status) {
|
|
80
|
+
homebridge.HAPeventByDeviceID(hbInstance.deviceID, JSON.stringify(HBMessage[register]), function (err, status) {
|
|
81
81
|
if (!err) {
|
|
82
82
|
// debug("Registered Event %s:%s ->", hbInstance.host, hbInstance.port, status);
|
|
83
83
|
} else {
|
|
@@ -89,7 +89,7 @@ function registerEvents(message) {
|
|
|
89
89
|
|
|
90
90
|
function alexaDiscovery(message, callback) {
|
|
91
91
|
// debug('alexaDiscovery', this);
|
|
92
|
-
homebridge.HAPaccessories(function(endPoints) {
|
|
92
|
+
homebridge.HAPaccessories(function (endPoints) {
|
|
93
93
|
debug("alexaDiscovery");
|
|
94
94
|
var response;
|
|
95
95
|
|
|
@@ -123,7 +123,7 @@ function alexaDiscovery(message, callback) {
|
|
|
123
123
|
} else {
|
|
124
124
|
var mdnsCache = homebridge.mdnsCache();
|
|
125
125
|
var output = "";
|
|
126
|
-
for (const instance in mdnsCache) {
|
|
126
|
+
for (const instance in mdnsCache) {
|
|
127
127
|
output = output + '\nHomebridge Accessory Information Dump for ' + mdnsCache[instance].name;
|
|
128
128
|
// debug('Homebridge Accessory Instance Dump for', mdnsCache[instance].name);
|
|
129
129
|
output = output + '\ncurl -X PUT ' + mdnsCache[instance].url + '/accessories --header "Content-Type:Application/json" --header "authorization: ' + this.pin + '"\n';
|
|
@@ -226,7 +226,7 @@ function alexaColorTemperatureController(message, callback) {
|
|
|
226
226
|
case "increasecolortemperature":
|
|
227
227
|
// This characteristic describes color temperature which is represented in the reciprocal megakelvin (MK-1) or mirek scale. MK = 1,000,000 / K where MK is the desired mirek value and K is temperature in Kelvins.
|
|
228
228
|
|
|
229
|
-
homebridge.HAPstatusByDeviceID(haAction.deviceID, "?id=" + haAction.aid + "." + haAction.iid, function(err, status) {
|
|
229
|
+
homebridge.HAPstatusByDeviceID(haAction.deviceID, "?id=" + haAction.aid + "." + haAction.iid, function (err, status) {
|
|
230
230
|
this.log("ColorTemperatureController-get", action, haAction.deviceID, status, err);
|
|
231
231
|
|
|
232
232
|
var colorTemperatureDelta = 40;
|
|
@@ -242,7 +242,7 @@ function alexaColorTemperatureController(message, callback) {
|
|
|
242
242
|
"value": colorTemperature
|
|
243
243
|
}]
|
|
244
244
|
};
|
|
245
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
245
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
246
246
|
this.log("ColorTemperatureController-change", action, haAction.deviceID, status, body, err);
|
|
247
247
|
var response = alexaMessages.alexaResponse(message, status, err, _round(1000000 / colorTemperature));
|
|
248
248
|
callback(err, response);
|
|
@@ -259,7 +259,7 @@ function alexaColorTemperatureController(message, callback) {
|
|
|
259
259
|
"value": colorTemperature
|
|
260
260
|
}]
|
|
261
261
|
};
|
|
262
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
262
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
263
263
|
this.log("ColorTemperatureController-set", action, haAction.deviceID, status, body, err);
|
|
264
264
|
var response = alexaMessages.alexaResponse(message, status, err, message.directive.payload.colorTemperatureInKelvin);
|
|
265
265
|
callback(err, response);
|
|
@@ -286,7 +286,7 @@ function alexaPlaybackController(message, callback) {
|
|
|
286
286
|
"value": haAction.value
|
|
287
287
|
}]
|
|
288
288
|
};
|
|
289
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
289
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
290
290
|
this.log("PlaybackController", action, haAction.deviceID, status, err);
|
|
291
291
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
292
292
|
callback(err, response);
|
|
@@ -311,7 +311,7 @@ function alexaInputController(message, callback) {
|
|
|
311
311
|
"value": haAction.value
|
|
312
312
|
}]
|
|
313
313
|
};
|
|
314
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
314
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
315
315
|
this.log("InputController", action, haAction.deviceID, status, err);
|
|
316
316
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
317
317
|
callback(err, response);
|
|
@@ -336,7 +336,7 @@ function alexaPowerController(message, callback) {
|
|
|
336
336
|
"value": haAction.value
|
|
337
337
|
}]
|
|
338
338
|
};
|
|
339
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
339
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
340
340
|
this.log("PowerController", action, haAction.deviceID, status, err);
|
|
341
341
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
342
342
|
callback(err, response);
|
|
@@ -377,7 +377,7 @@ function alexaModeController(message, callback) {
|
|
|
377
377
|
"value": value
|
|
378
378
|
}]
|
|
379
379
|
};
|
|
380
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
380
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
381
381
|
this.log("ModeController", action, haAction.deviceID, status, err);
|
|
382
382
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
383
383
|
callback(err, response);
|
|
@@ -402,7 +402,7 @@ function alexaLockController(message, callback) {
|
|
|
402
402
|
"value": haAction.value
|
|
403
403
|
}]
|
|
404
404
|
};
|
|
405
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
405
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
406
406
|
this.log("alexaLockController", action, haAction.deviceID, status, err);
|
|
407
407
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
408
408
|
callback(err, response);
|
|
@@ -467,14 +467,14 @@ function alexaChannelController(message, callback) {
|
|
|
467
467
|
|
|
468
468
|
// debug("alexaChannelController", JSON.stringify(message), JSON.stringify(body));
|
|
469
469
|
|
|
470
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
470
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
471
471
|
this.log("alexaChannelController", channel, haAction.deviceID, status, err);
|
|
472
472
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
473
473
|
callback(err, response);
|
|
474
474
|
}.bind(this));
|
|
475
475
|
}
|
|
476
476
|
|
|
477
|
-
function alexaThermostatController(message, callback) {
|
|
477
|
+
async function alexaThermostatController(message, callback) {
|
|
478
478
|
// debug("alexaThermostatController", JSON.stringify(message));
|
|
479
479
|
var action = message.directive.header.name;
|
|
480
480
|
var payloads = message.directive.payload;
|
|
@@ -498,7 +498,7 @@ function alexaThermostatController(message, callback) {
|
|
|
498
498
|
"value": haAction.value
|
|
499
499
|
}]
|
|
500
500
|
};
|
|
501
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
501
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
502
502
|
this.log("SetThermostatMode", mode, haAction.deviceID, status, err);
|
|
503
503
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
504
504
|
callback(err, response);
|
|
@@ -507,11 +507,32 @@ function alexaThermostatController(message, callback) {
|
|
|
507
507
|
case "SetTargetTemperature":
|
|
508
508
|
// targetSetpoint, lowerSetpoint, upperSetpoint
|
|
509
509
|
var characteristics = [];
|
|
510
|
+
var haAction;
|
|
510
511
|
for (var index in payloads) {
|
|
511
512
|
try {
|
|
512
|
-
|
|
513
|
+
if (message.directive.endpoint.cookie[index]) {
|
|
514
|
+
haAction = JSON.parse(message.directive.endpoint.cookie[index]);
|
|
515
|
+
} else {
|
|
516
|
+
if (index === "targetSetpoint" && (message.directive.endpoint.cookie['lowerSetpoint'] || message.directive.endpoint.cookie['upperSetpoint'])) {
|
|
517
|
+
var mode = await retriveThermostatMode(message.directive.endpoint.cookie['ReportState']);
|
|
518
|
+
if (mode === 1) {
|
|
519
|
+
// Mode is Heat
|
|
520
|
+
haAction = JSON.parse(message.directive.endpoint.cookie['lowerSetpoint']);
|
|
521
|
+
action += '-Heat';
|
|
522
|
+
} else if (mode === 2) {
|
|
523
|
+
// Mode is Cool
|
|
524
|
+
haAction = JSON.parse(message.directive.endpoint.cookie['upperSetpoint']);
|
|
525
|
+
action += '-Cool';
|
|
526
|
+
} else {
|
|
527
|
+
throw new Error('Thermostat Mode is not Heat or Cool');
|
|
528
|
+
}
|
|
529
|
+
} else {
|
|
530
|
+
throw new Error('missing action');
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
debug("alexaThermostatController - haAction", JSON.stringify(haAction));
|
|
513
534
|
} catch (e) {
|
|
514
|
-
this.log("alexaThermostatController
|
|
535
|
+
this.log("alexaThermostatController ERROR: '%s' Action: '%s' ", e.message, index, message.directive.endpoint.cookie);
|
|
515
536
|
var response = alexaMessages.alexaResponse(message, "", e);
|
|
516
537
|
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.
|
|
517
538
|
callback(e, response);
|
|
@@ -531,14 +552,14 @@ function alexaThermostatController(message, callback) {
|
|
|
531
552
|
var body = {
|
|
532
553
|
"characteristics": characteristics
|
|
533
554
|
};
|
|
534
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
555
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
535
556
|
this.log("ThermostatController", action, haAction.deviceID, status, err);
|
|
536
557
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
537
558
|
callback(err, response);
|
|
538
559
|
}.bind(this));
|
|
539
560
|
break;
|
|
540
|
-
|
|
541
|
-
|
|
561
|
+
// case "AdjustTargetTemperature":
|
|
562
|
+
// Future expansion
|
|
542
563
|
default:
|
|
543
564
|
var err = {
|
|
544
565
|
message: "Unknown action" + action
|
|
@@ -549,6 +570,29 @@ function alexaThermostatController(message, callback) {
|
|
|
549
570
|
}
|
|
550
571
|
}
|
|
551
572
|
|
|
573
|
+
|
|
574
|
+
async function retriveThermostatMode(reportState) {
|
|
575
|
+
var mode = JSON.parse(reportState);
|
|
576
|
+
|
|
577
|
+
const foundObject = mode.find(obj => obj.interface === "Alexa.ThermostatControllerthermostatMode");
|
|
578
|
+
var body = "?id=" + foundObject.aid + "." + foundObject.iid;
|
|
579
|
+
var result = await promisifiedHAPstatusByDeviceID(foundObject.deviceID, body);
|
|
580
|
+
return result.characteristics[0].value;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// Wrap the HAPstatusByDeviceID function with async/await
|
|
584
|
+
function promisifiedHAPstatusByDeviceID(deviceID, body) {
|
|
585
|
+
return new Promise((resolve, reject) => {
|
|
586
|
+
homebridge.HAPstatusByDeviceID(deviceID, body, (error, result) => {
|
|
587
|
+
if (error) {
|
|
588
|
+
reject(error);
|
|
589
|
+
} else {
|
|
590
|
+
resolve(result);
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
|
|
552
596
|
function alexaColorController(message, callback) {
|
|
553
597
|
var action = message.directive.header.name;
|
|
554
598
|
try {
|
|
@@ -577,7 +621,7 @@ function alexaColorController(message, callback) {
|
|
|
577
621
|
}]
|
|
578
622
|
};
|
|
579
623
|
debug("color HB command", body);
|
|
580
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
624
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
581
625
|
this.log("ColorController", action, haAction.deviceID, status, err);
|
|
582
626
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
583
627
|
callback(err, response);
|
|
@@ -601,7 +645,7 @@ function alexaRangeController(message, callback) {
|
|
|
601
645
|
switch (action.toLowerCase()) {
|
|
602
646
|
case "adjustrangevalue":
|
|
603
647
|
// Need to get current value prior to dimming
|
|
604
|
-
homebridge.HAPstatusByDeviceID(haAction.deviceID, "?id=" + haAction.aid + "." + haAction.iid, function(err, status) {
|
|
648
|
+
homebridge.HAPstatusByDeviceID(haAction.deviceID, "?id=" + haAction.aid + "." + haAction.iid, function (err, status) {
|
|
605
649
|
this.log("RangeController-get", action, haAction.deviceID, status, err);
|
|
606
650
|
|
|
607
651
|
var rangeValueDelta = message.directive.payload.rangeValueDelta;
|
|
@@ -615,7 +659,7 @@ function alexaRangeController(message, callback) {
|
|
|
615
659
|
"value": rangeLevel
|
|
616
660
|
}]
|
|
617
661
|
};
|
|
618
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
662
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
619
663
|
this.log("RangeController-set", action, haAction.deviceID, status, body, err);
|
|
620
664
|
var response = alexaMessages.alexaResponse(message, status, err, rangeLevel);
|
|
621
665
|
callback(err, response);
|
|
@@ -632,7 +676,7 @@ function alexaRangeController(message, callback) {
|
|
|
632
676
|
"value": rangeValue
|
|
633
677
|
}]
|
|
634
678
|
};
|
|
635
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
679
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
636
680
|
this.log("RangeController", action, haAction.deviceID, status, body, err);
|
|
637
681
|
var response = alexaMessages.alexaResponse(message, status, err, rangeValue);
|
|
638
682
|
callback(err, response);
|
|
@@ -668,7 +712,7 @@ function alexaPowerLevelController(message, callback) {
|
|
|
668
712
|
switch (action.toLowerCase()) {
|
|
669
713
|
case "adjustpowerlevel":
|
|
670
714
|
// Need to get current value prior to dimming
|
|
671
|
-
homebridge.HAPstatusByDeviceID(haAction.deviceID, "?id=" + haAction.aid + "." + haAction.iid, function(err, status) {
|
|
715
|
+
homebridge.HAPstatusByDeviceID(haAction.deviceID, "?id=" + haAction.aid + "." + haAction.iid, function (err, status) {
|
|
672
716
|
this.log("PowerLevelController-get", action, haAction.deviceID, status, err);
|
|
673
717
|
|
|
674
718
|
var powerLevelDelta = message.directive.payload.powerLevelDelta;
|
|
@@ -688,7 +732,7 @@ function alexaPowerLevelController(message, callback) {
|
|
|
688
732
|
"value": turnOn.value
|
|
689
733
|
});
|
|
690
734
|
}
|
|
691
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
735
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
692
736
|
this.log("PowerLevelController-set", action, haAction.deviceID, status, body, err);
|
|
693
737
|
var response = alexaMessages.alexaResponse(message, status, err, powerLevel);
|
|
694
738
|
callback(err, response);
|
|
@@ -712,7 +756,7 @@ function alexaPowerLevelController(message, callback) {
|
|
|
712
756
|
"value": turnOn.value
|
|
713
757
|
});
|
|
714
758
|
}
|
|
715
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
759
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
716
760
|
this.log("PowerLevelController", action, haAction.deviceID, status, body, err);
|
|
717
761
|
var response = alexaMessages.alexaResponse(message, status, err, powerLevel);
|
|
718
762
|
callback(err, response);
|
|
@@ -738,7 +782,7 @@ function alexaSpeaker(message, callback) {
|
|
|
738
782
|
switch (action.toLowerCase()) {
|
|
739
783
|
case "adjustvolume":
|
|
740
784
|
// Need to get current value prior to dimming
|
|
741
|
-
homebridge.HAPstatusByDeviceID(haAction.deviceID, "?id=" + haAction.aid + "." + haAction.iid, function(err, status) {
|
|
785
|
+
homebridge.HAPstatusByDeviceID(haAction.deviceID, "?id=" + haAction.aid + "." + haAction.iid, function (err, status) {
|
|
742
786
|
this.log("Speaker-get", action, haAction.deviceID, status, err);
|
|
743
787
|
|
|
744
788
|
if (!err) {
|
|
@@ -752,7 +796,7 @@ function alexaSpeaker(message, callback) {
|
|
|
752
796
|
"value": volume
|
|
753
797
|
}]
|
|
754
798
|
};
|
|
755
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
799
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
756
800
|
this.log("Speaker-set", action, haAction.deviceID, status, body, err);
|
|
757
801
|
var response = alexaMessages.alexaResponse(message, status, err, volume);
|
|
758
802
|
callback(err, response);
|
|
@@ -773,7 +817,7 @@ function alexaSpeaker(message, callback) {
|
|
|
773
817
|
"value": volume
|
|
774
818
|
}]
|
|
775
819
|
};
|
|
776
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
820
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
777
821
|
this.log("Speaker", action, haAction.deviceID, status, body, err);
|
|
778
822
|
var response = alexaMessages.alexaResponse(message, status, err, volume);
|
|
779
823
|
callback(err, response);
|
|
@@ -809,7 +853,7 @@ function alexaStepSpeaker(message, callback) {
|
|
|
809
853
|
"value": value
|
|
810
854
|
}]
|
|
811
855
|
};
|
|
812
|
-
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function(err, status) {
|
|
856
|
+
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
813
857
|
this.log("StepSpeaker", action, haAction.deviceID, status, body, err);
|
|
814
858
|
var response = alexaMessages.alexaResponse(message, status, err, volume);
|
|
815
859
|
callback(err, response);
|
|
@@ -834,7 +878,7 @@ function alexaMessage(message, callback) {
|
|
|
834
878
|
}
|
|
835
879
|
|
|
836
880
|
var statusArray = [];
|
|
837
|
-
reportState.forEach(function(element) {
|
|
881
|
+
reportState.forEach(function (element) {
|
|
838
882
|
if (!statusArray[element.deviceID]) {
|
|
839
883
|
statusArray[element.deviceID] = {};
|
|
840
884
|
statusArray[element.deviceID].body = "?id=";
|
|
@@ -866,10 +910,15 @@ function alexaMessage(message, callback) {
|
|
|
866
910
|
}
|
|
867
911
|
});
|
|
868
912
|
break;
|
|
869
|
-
|
|
870
|
-
|
|
913
|
+
// case "Alexa.ThermostatControllerthermostatMode":
|
|
914
|
+
// case "Alexa.ThermostatControllertargetSetpoint":
|
|
871
915
|
default:
|
|
872
|
-
|
|
916
|
+
|
|
917
|
+
var body = statusArray[element.deviceID].body + statusArray[element.deviceID].spacer;
|
|
918
|
+
// debug("alexaMessage: %s != %s", body, statusArray[element.deviceID].spacer + element.aid + "." + element.iid + statusArray[element.deviceID].spacer);
|
|
919
|
+
if (!body.includes(statusArray[element.deviceID].spacer + element.aid + "." + element.iid + statusArray[element.deviceID].spacer) && !body.includes("=" + element.aid + "." + element.iid + statusArray[element.deviceID].spacer)) {
|
|
920
|
+
statusArray[element.deviceID].body = statusArray[element.deviceID].body + statusArray[element.deviceID].spacer + element.aid + "." + element.iid;
|
|
921
|
+
}
|
|
873
922
|
statusArray[element.deviceID].interface = statusArray[element.deviceID].interface + statusArray[element.deviceID].spacer + element.interface;
|
|
874
923
|
statusArray[element.deviceID].spacer = ",";
|
|
875
924
|
statusArray[element.deviceID].elements.push({
|
|
@@ -942,7 +991,7 @@ async function processStatusArray(statusArray, message) {
|
|
|
942
991
|
function _HAPstatusByDeviceID(statusObject, message) {
|
|
943
992
|
debug("_HAPstatusByDeviceID-1", statusObject);
|
|
944
993
|
return new Promise((resolve, reject) => {
|
|
945
|
-
homebridge.HAPstatusByDeviceID(statusObject.deviceID, statusObject.body, function(err, status) {
|
|
994
|
+
homebridge.HAPstatusByDeviceID(statusObject.deviceID, statusObject.body, function (err, status) {
|
|
946
995
|
if (err) {
|
|
947
996
|
// debug("Error: _HAPstatusByDeviceID", err);
|
|
948
997
|
reject(err);
|
|
@@ -957,7 +1006,7 @@ function _HAPstatusByDeviceID(statusObject, message) {
|
|
|
957
1006
|
function alexaEvent(events) {
|
|
958
1007
|
debug("Events", JSON.stringify(events));
|
|
959
1008
|
// create alexa message
|
|
960
|
-
events.forEach(function(event) {
|
|
1009
|
+
events.forEach(function (event) {
|
|
961
1010
|
// debug('alexaEvent - event', event);
|
|
962
1011
|
var x = {
|
|
963
1012
|
'deviceID': event.deviceID,
|
package/lib/alexaMessages.js
CHANGED
|
@@ -257,19 +257,19 @@ function alexaResponse(message, hbResponse, err, value) {
|
|
|
257
257
|
response = {
|
|
258
258
|
"context": {
|
|
259
259
|
"properties": [{
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
260
|
+
"namespace": "Alexa.Speaker",
|
|
261
|
+
"name": "volume",
|
|
262
|
+
"value": value,
|
|
263
|
+
"timeOfSample": now.toISOString(),
|
|
264
|
+
"uncertaintyInMilliseconds": 500
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"namespace": "Alexa.Speaker",
|
|
268
|
+
"name": "muted",
|
|
269
|
+
"value": false,
|
|
270
|
+
"timeOfSample": now.toISOString(),
|
|
271
|
+
"uncertaintyInMilliseconds": 500
|
|
272
|
+
}
|
|
273
273
|
]
|
|
274
274
|
},
|
|
275
275
|
"event": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-alexa",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8",
|
|
4
4
|
"description": "Control your Homebridge devices with Amazon Alexa.",
|
|
5
5
|
"main": "plugin.js",
|
|
6
6
|
"scripts": {
|
|
@@ -32,16 +32,16 @@
|
|
|
32
32
|
"homebridge": ">=0.4.16"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@oznu/hap-client": "^1.
|
|
35
|
+
"@oznu/hap-client": "^1.9.0",
|
|
36
36
|
"documentation": "^14.0.1",
|
|
37
|
-
"nodemon": "^
|
|
37
|
+
"nodemon": "^3.0.2"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"bottleneck": "^2.19.5",
|
|
41
41
|
"debug": "^4.3.4",
|
|
42
42
|
"hap-node-client": "^0.2.4",
|
|
43
43
|
"is-my-json-valid": "^2.20.6",
|
|
44
|
-
"mqtt": "^4.3.
|
|
44
|
+
"mqtt": "^4.3.8"
|
|
45
45
|
},
|
|
46
46
|
"author": "NorthernMan54",
|
|
47
47
|
"license": "Apache-2.0",
|