homebridge-alexa 0.8.2 → 0.8.3-beta.1

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.
@@ -0,0 +1,97 @@
1
+ #!/bin/env node
2
+
3
+ /**
4
+ * This scripts queries the npm registry to pull out the latest version for a given tag.
5
+ */
6
+
7
+ const assert = require('node:assert')
8
+ const child_process = require('node:child_process')
9
+ const fs = require('node:fs')
10
+ const process = require('node:process')
11
+
12
+ const BRANCH_VERSION_PATTERN = /^([A-Z]+)-(\d+\.\d+\.\d+)$/i
13
+
14
+ // Load the contents of the package.json file
15
+ const packageJSON = JSON.parse(fs.readFileSync('package.json', 'utf8'))
16
+
17
+ const refArgument = process.argv[2]
18
+ const tagArgument = process.argv[3] || 'latest'
19
+
20
+ if (!refArgument) {
21
+ console.error('ref argument is missing')
22
+ console.error('Usage: npm-version-script.js <ref> [tag]')
23
+ process.exit(1)
24
+ }
25
+
26
+ /**
27
+ * Queries the NPM registry for the latest version for the provided base version and tag.
28
+ * If the tag is latest, then the base version is returned if it exists. For other tags, the latest
29
+ * version found for that base version and tag is returned.
30
+ * @param baseVersion The base version to query for, e.g. 2.0.0
31
+ * @param tag The tag to query for, e.g. beta or latest
32
+ * @returns {string} Returns the version, or '' if not found
33
+ */
34
+ function getTagVersionFromNpm(baseVersion, tag) {
35
+ try {
36
+ return JSON.parse(child_process.execSync(`npm info ${packageJSON.name} versions --json`).toString('utf8').trim())
37
+ .filter(v => tag === 'latest' ? v === baseVersion : v.startsWith(`${baseVersion}-${tag}.`)) // find all published versions for this base version and tag
38
+ .reduce((_, current) => current, '') // choose the last as they're sorted in ascending order, or '' if there are none
39
+ } catch (e) {
40
+ console.error(`Failed to query the npm registry for the latest version for tag: ${tag}`, e)
41
+ // throw e;
42
+ return ''
43
+ }
44
+ }
45
+
46
+ function desiredTargetVersion(ref) {
47
+ // ref is a GitHub action ref string
48
+ if (ref.startsWith('refs/pull/')) {
49
+ throw new Error('The version script was executed inside a PR!')
50
+ }
51
+
52
+ assert(ref.startsWith('refs/heads/'))
53
+ const branchName = ref.slice('refs/heads/'.length)
54
+
55
+ const results = branchName.match(BRANCH_VERSION_PATTERN)
56
+ if (results !== null) {
57
+ if (results[1] !== tagArgument) {
58
+ console.warn(`The base branch name (${results[1]}) differs from the tag name ${tagArgument}`)
59
+ }
60
+
61
+ return results[2]
62
+ }
63
+
64
+ throw new Error(`Malformed branch name for ref: ${ref}. Can't derive the base version. Use a branch name like: beta-x.x.x or alpha-x.x.x`)
65
+ }
66
+
67
+ // derive the base version from the branch ref
68
+ const baseVersion = desiredTargetVersion(refArgument)
69
+
70
+ // query the npm registry for the latest version of the provided tag name
71
+ const latestReleasedVersion = getTagVersionFromNpm(baseVersion, tagArgument) // e.g. 0.7.0-beta.12
72
+
73
+ let publishTag
74
+
75
+ if (latestReleasedVersion) {
76
+ console.warn(`Latest published version for ${baseVersion} with tag ${tagArgument} is ${latestReleasedVersion}`)
77
+ publishTag = latestReleasedVersion // set this released beta or alpha to be incremented
78
+ } else {
79
+ console.warn(`No published versions for ${baseVersion} with tag ${tagArgument}`)
80
+ publishTag = baseVersion // start off with a new beta or alpha version
81
+ }
82
+
83
+ if (packageJSON.version !== publishTag) {
84
+ // report the change for CI
85
+ console.warn(`Changing version in package.json from ${packageJSON.version} to ${publishTag}`)
86
+
87
+ // save the package.json
88
+ packageJSON.version = publishTag
89
+ fs.writeFileSync('package.json', JSON.stringify(packageJSON, null, 2))
90
+
91
+ // perform the same change to the package-lock.json
92
+ const packageLockJSON = JSON.parse(fs.readFileSync('package-lock.json', 'utf8'))
93
+ packageLockJSON.version = publishTag
94
+ fs.writeFileSync('package-lock.json', JSON.stringify(packageLockJSON, null, 2))
95
+ } else {
96
+ console.warn(`Leaving version in package.json at ${packageJSON.version}`)
97
+ }
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
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.8.3 (2025-03-29)
6
+
7
+ ## [Version 0.8.3](https://github.com/northernman54/homebridge-alexa/compare/v0.8.2...v0.8.3)
8
+
9
+ #### Bug Fix
10
+
11
+ - Fix for Routines #761
12
+
5
13
  ## 0.8.2 (2024-12-27)
6
14
 
7
15
  ## [Version 0.8.2](https://github.com/northernman54/homebridge-alexa/compare/v0.8.1...v0.8.2)
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "homebridge-alexa",
3
- "version": "0.8.2",
3
+ "version": "0.8.3-beta.1",
4
4
  "description": "Control your Homebridge devices with Amazon Alexa.",
5
5
  "main": "src/plugin.js",
6
6
  "scripts": {
7
- "test": "jest --forceExit --detectOpenHandles --verbose=true --silent ",
7
+ "test": "jest --forceExit --detectOpenHandles --verbose=true ",
8
8
  "api": "documentation build plugin.js lib/alexaActions.js lib/alexaLocal.js lib/alexaMessages.js lib/alexaTranslator.js -f md --config docs/documentation.yml > docs/API.md",
9
9
  "document": "./gh-md-toc --hide-footer README.md ;./gh-md-toc --hide-footer Troubleshooting.md ;./gh-md-toc --hide-footer Installation.md; rm README.md.orig.* README.md.toc.* Troubleshooting.md.orig.* Troubleshooting.md.toc.* Installation.md.orig.* Installation.md.toc.*",
10
10
  "watch": "nodemon",
@@ -73,4 +73,4 @@
73
73
  "src/**"
74
74
  ]
75
75
  }
76
- }
76
+ }
@@ -27,7 +27,8 @@ module.exports = {
27
27
  alexaInputController: alexaInputController,
28
28
  alexaRangeController: alexaRangeController,
29
29
  alexaModeController: alexaModeController,
30
- destroy: destroy
30
+ destroy: destroy,
31
+ setHomebridge: setHomebridge
31
32
  };
32
33
 
33
34
  function hapDiscovery(options) {
@@ -36,7 +37,7 @@ function hapDiscovery(options) {
36
37
  homebridge.on('Ready', function () {
37
38
  alexaDiscovery.call(options, null, function () {
38
39
  // debug("Events", options);
39
- if (options.events) {
40
+ if (options.routines) {
40
41
  registerEvents(messages.checkEventDeviceList.call(options, hbDevices.toEvents()));
41
42
  }
42
43
  });
@@ -49,10 +50,16 @@ function hapDiscovery(options) {
49
50
  // debug("Event Relay - 1", homebridge);
50
51
  }
51
52
 
53
+ // Used for testing
54
+
52
55
  function destroy() {
53
56
  homebridge.destroy();
54
57
  }
55
58
 
59
+ function setHomebridge(hb) {
60
+ homebridge = hb;
61
+ }
62
+
56
63
  function registerEvents(message) {
57
64
  // debug("registerEvents", message);
58
65
 
@@ -95,11 +102,10 @@ function registerEvents(message) {
95
102
  function alexaDiscovery(message, callback) {
96
103
  // debug('alexaDiscovery', this);
97
104
  homebridge.HAPaccessories(function (endPoints) {
98
- debug("alexaDiscovery");
105
+ debug("alexaDiscovery", this);
99
106
  var response;
100
107
 
101
108
  hbDevices = new Homebridges(endPoints, this);
102
- // debug("RESPONSE", JSON.stringify(hbDevices, null, 2));
103
109
  response = hbDevices.toAlexa(this, message);
104
110
 
105
111
  // debug("RESPONSE", JSON.stringify(response, null, 2));
@@ -1,95 +1,121 @@
1
- const { processStatusArray } = require('/Users/sgracey/Code/homebridge-alexa/src/lib/alexaActions.js');
2
- const alexaMessages = require('/Users/sgracey/Code/homebridge-alexa/src/lib/alexaMessages.js');
3
- const homebridge = require('hap-node-client').HAPNodeJSClient;
4
-
5
- jest.mock('hap-node-client');
6
- jest.mock('/Users/sgracey/Code/homebridge-alexa/src/lib/alexaMessages.js');
7
-
8
- describe('processStatusArray', () => {
9
- let statusArray;
10
- let message;
11
-
12
- beforeEach(() => {
13
- statusArray = [
14
- {
15
- deviceID: 'device1',
16
- body: '?id=1.1',
17
- interface: 'Alexa.PowerController',
18
- spacer: ',',
19
- elements: [
20
- { interface: 'Alexa.PowerController', aid: 1, iid: 1 }
21
- ]
22
- },
23
- {
24
- deviceID: 'device2',
25
- body: '?id=2.1',
26
- interface: 'Alexa.BrightnessController',
27
- spacer: ',',
28
- elements: [
29
- { interface: 'Alexa.BrightnessController', aid: 2, iid: 1 }
30
- ]
31
- }
32
- ];
33
- message = { directive: { header: { messageId: '123' } } };
34
-
35
- homebridge.HAPstatusByDeviceID.mockImplementation((deviceID, body, callback) => {
36
- if (deviceID === 'device1') {
37
- callback(null, { characteristics: [{ aid: 1, iid: 1, value: true }] });
38
- } else if (deviceID === 'device2') {
39
- callback(null, { characteristics: [{ aid: 2, iid: 1, value: 50 }] });
40
- } else {
41
- callback(new Error('Device not found'));
42
- }
43
- });
1
+ const { alexaMessage, setHomebridge, destroy } = require('/Users/sgracey/Code/homebridge-alexa/src/lib/alexaActions.js');
44
2
 
45
- alexaMessages.alexaStateResponse.mockImplementation((resultArray, message) => {
46
- return { event: { header: { messageId: message.directive.header.messageId }, payload: { properties: resultArray } } };
47
- });
48
- });
3
+ jest.mock("hap-node-client", () => {
4
+ // console.log('Mock - hap-node-client');
5
+ return { HAPNodeJSClient: jest.fn() };
6
+ });
7
+
8
+ const HAPstatusByDeviceID = (deviceID, body, callback) => {
9
+ // console.log('Mock - HAPstatusByDeviceID', deviceID, body, callback);
10
+ switch (deviceID) {
11
+ case "ColorController-1":
12
+ callback(null, { deviceID: "device123", status: "on" });
13
+ break;
14
+ case "TemperatureSensor-Ok":
15
+ callback(null, { "characteristics": [{ "aid": 52, "iid": 12, "value": 2.5 }] });
16
+ break;
17
+ case "TemperatureSensor-NoData":
18
+ callback(null, { "characteristics": [{ "aid": 52, "iid": 12, "status": -70410 }] });
19
+ break;
20
+ default:
21
+ console.log('Missing Mock - HAPstatusByDeviceID', deviceID, body, callback);
22
+ callback(null, { deviceID: "device123", status: "off" });
23
+ }
24
+ }
25
+
26
+ setHomebridge({
27
+ HAPstatusByDeviceID: HAPstatusByDeviceID,
28
+ destroy: jest.fn()
29
+ });
30
+
31
+ describe('lib/alexaActions', () => {
32
+ describe('alexaMessage', () => {
49
33
 
50
- test.skip('should process status array successfully', async () => {
51
- const result = await processStatusArray(statusArray, message);
52
- expect(result).toEqual({
53
- event: {
54
- header: { messageId: '123' },
55
- payload: {
56
- properties: [
57
- { interface: 'Alexa.PowerController', aid: 1, iid: 1, value: true },
58
- { interface: 'Alexa.BrightnessController', aid: 2, iid: 1, value: 50 }
59
- ]
34
+ test('ReportState - ColorController', async () => {
35
+ const message = {
36
+ directive: {
37
+ header: {
38
+ name: 'ReportState'
39
+ },
40
+ endpoint: {
41
+ cookie: {
42
+ ReportState: '[{"deviceID": "ColorController-1", "interface": "Alexa.ColorController", "hue": {"aid": "1", "iid": "1"}, "saturation": {"aid": "1", "iid": "2"}, "brightness": {"aid": "1", "iid": "3"}}]'
43
+ }
44
+ }
60
45
  }
61
- }
62
- });
63
- });
46
+ };
64
47
 
65
- test.skip('should handle errors during processing', async () => {
66
- homebridge.HAPstatusByDeviceID.mockImplementationOnce((deviceID, body, callback) => {
67
- callback(new Error('Device not found'));
68
- });
48
+ const callback = jest.fn();
49
+ alexaMessage.call({ log: jest.fn() }, message, callback);
50
+
51
+ await sleep(500);
52
+ // Add your assertions here to verify the behavior of the function
53
+ expect(callback).toHaveBeenCalled();
54
+ // expect(callback.mock.calls[0][0].context.properties[0].value).toBe(2.5);
55
+ // ...
56
+ }, 5000);
57
+
58
+ test('ReportState - TemperatureSensor - Ok', async () => {
59
+ const message = { "directive": { "header": { "namespace": "Alexa", "name": "ReportState", "payloadVersion": "3", "messageId": "1cb7b217-3c2d-40e3-ab3d-fb66fb8bca2f", "correlationToken": "AAAAAAAAAAD9h7NYdun8GkFXkq4RJRZvAAIAAAAAAADHILDp6OTWHFoOX24pkmhvbtYnQ8g2cZAZwwHKZaR7/SF/tatX8I5tEBULWfoqY9WqeLu/WmF2n2mq4RFpbVg6yRZMPdeRbllXqMsG+tSGiiVmdyYT7BP32HlAELpOwtSXbnxNqGomxV7dqfZO2HYAj6qXSLUbnXYmSO7pDiMqT/PUbPSO+1MhcjYSF1UGV11JFihHGNuUyd0VN/bUoW46YWbxzB/zYPk+RUqA1uOfUzVWso8NuDNsE2BWFe4xO1thtJCOQjS9Wo5VA0avOeLO48aMNQ4Awby4aJWW+WzT+qp3v5xqQMwa3m0r8b89CTT2L4LcSD+A5JGE5nwppZyXjFeqgX5W1bY41z6cwjL6U+nW9xhQUzMXDDZ0/nD6bw77+oYQBkes2eexQbUgcl3cjw5OrmdbseOcyo4THzNRfuhZbebMQ/jTEameb/GnFWHoXdmpmR8Md5sEaDXv3X6Qfi2oCw7OXzuCBTHngGf82xw6wQd6ETymES0mZdsvwHTL3HUQBhR6xrAcg4MBPYuGSgVSiAAtresmexfxCDvYIcFf1o6c78w+o3c+w4Cprg6sU+OeF16ouuAjhs3qbX+sgmV9W9tWBPGirQA1WXvePz3LP8SPyjj0BAQ9nnr0tJ59jMtSaRwu6FFnwheVSAyZihggIVTD1pQ+nusFrJkahA==" }, "endpoint": { "endpointId": "Njk6NjI6Qjc6QUU6Mzg6RDQtRGVmYXVsdCBNb2RlbC1OUkNIS0IgLSBMYUNyb3NzZS1UWDE0MVctQmFja3lhcmQtMDAwMDAwOEEtMDAwMC0xMDAwLTgwMDAtMDAyNkJCNzY1Mjkx", "cookie": { "ReportState": "[{\"interface\":\"Alexa.TemperatureSensor\",\"deviceID\":\"TemperatureSensor-Ok\",\"aid\":52,\"iid\":12}]" } }, "payload": {} } };
60
+
61
+ const callback = jest.fn();
62
+ alexaMessage.call({ log: jest.fn() }, message, callback);
69
63
 
70
- const result = await processStatusArray(statusArray, message);
71
- expect(result).toEqual({
72
- event: {
73
- header: { messageId: '123' },
74
- payload: {
75
- properties: [
76
- { interface: 'Alexa.PowerController', aid: 1, iid: 1, value: true },
77
- { interface: 'Alexa.BrightnessController', aid: 2, iid: 1, value: 50 }
78
- ]
64
+ await sleep(500);
65
+ // Add your assertions here to verify the behavior of the function
66
+ // console.log(JSON.stringify(callback.mock.calls[0][1], null, 2));
67
+ expect(callback).toHaveBeenCalled();
68
+ const response = callback.mock.calls[0][1];
69
+ expect(response.context.properties[0].value.value).toBe(2.5);
70
+ expect(response.context.properties[0].value.scale).toBe("CELSIUS");
71
+ // ...
72
+ }, 5000);
73
+
74
+ test('ReportState - TemperatureSensor - No Data', async () => {
75
+ const message = { "directive": { "header": { "namespace": "Alexa", "name": "ReportState", "payloadVersion": "3", "messageId": "1cb7b217-3c2d-40e3-ab3d-fb66fb8bca2f", "correlationToken": "AAAAAAAAAAD9h7NYdun8GkFXkq4RJRZvAAIAAAAAAADHILDp6OTWHFoOX24pkmhvbtYnQ8g2cZAZwwHKZaR7/SF/tatX8I5tEBULWfoqY9WqeLu/WmF2n2mq4RFpbVg6yRZMPdeRbllXqMsG+tSGiiVmdyYT7BP32HlAELpOwtSXbnxNqGomxV7dqfZO2HYAj6qXSLUbnXYmSO7pDiMqT/PUbPSO+1MhcjYSF1UGV11JFihHGNuUyd0VN/bUoW46YWbxzB/zYPk+RUqA1uOfUzVWso8NuDNsE2BWFe4xO1thtJCOQjS9Wo5VA0avOeLO48aMNQ4Awby4aJWW+WzT+qp3v5xqQMwa3m0r8b89CTT2L4LcSD+A5JGE5nwppZyXjFeqgX5W1bY41z6cwjL6U+nW9xhQUzMXDDZ0/nD6bw77+oYQBkes2eexQbUgcl3cjw5OrmdbseOcyo4THzNRfuhZbebMQ/jTEameb/GnFWHoXdmpmR8Md5sEaDXv3X6Qfi2oCw7OXzuCBTHngGf82xw6wQd6ETymES0mZdsvwHTL3HUQBhR6xrAcg4MBPYuGSgVSiAAtresmexfxCDvYIcFf1o6c78w+o3c+w4Cprg6sU+OeF16ouuAjhs3qbX+sgmV9W9tWBPGirQA1WXvePz3LP8SPyjj0BAQ9nnr0tJ59jMtSaRwu6FFnwheVSAyZihggIVTD1pQ+nusFrJkahA==" }, "endpoint": { "endpointId": "Njk6NjI6Qjc6QUU6Mzg6RDQtRGVmYXVsdCBNb2RlbC1OUkNIS0IgLSBMYUNyb3NzZS1UWDE0MVctQmFja3lhcmQtMDAwMDAwOEEtMDAwMC0xMDAwLTgwMDAtMDAyNkJCNzY1Mjkx", "cookie": { "ReportState": "[{\"interface\":\"Alexa.TemperatureSensor\",\"deviceID\":\"TemperatureSensor-NoData\",\"aid\":52,\"iid\":12}]" } }, "payload": {} } };
76
+
77
+ const callback = jest.fn();
78
+ alexaMessage.call({ log: jest.fn() }, message, callback);
79
+
80
+ await sleep(500);
81
+ // Add your assertions here to verify the behavior of the function
82
+ // console.log(JSON.stringify(callback.mock.calls[0][1], null, 2));
83
+ expect(callback).toHaveBeenCalled();
84
+ const response = callback.mock.calls[0][1];
85
+ expect(response.event.header.name).toBe('ErrorResponse');
86
+ expect(response.event.payload.type).toBe('ENDPOINT_UNREACHABLE');
87
+ // ...
88
+ }, 5000);
89
+
90
+
91
+ test('should handle unknown directive', () => {
92
+ const message = {
93
+ directive: {
94
+ header: {
95
+ name: 'Unknown'
96
+ },
97
+ endpoint: {
98
+ cookie: {
99
+ reportstate: '[{"deviceID": "1", "interface": "Alexa.ColorController", "hue": {"aid": "1", "iid": "1"}, "saturation": {"aid": "1", "iid": "2"}, "brightness": {"aid": "1", "iid": "3"}}]'
100
+ }
101
+ }
79
102
  }
80
- }
81
- });
82
- });
103
+ };
83
104
 
84
- test.skip('should return correct response format', async () => {
85
- const result = await processStatusArray(statusArray, message);
86
- expect(result).toHaveProperty('event.header.messageId', '123');
87
- expect(result).toHaveProperty('event.payload.properties');
88
- expect(result.event.payload.properties).toHaveLength(2);
89
- });
105
+ const callback = jest.fn();
106
+
107
+ alexaMessage.call({ log: jest.fn() }, message, callback);
90
108
 
109
+ // Add your assertions here to verify the behavior of the function
110
+ expect(callback).toHaveBeenCalled();
111
+ // ...
112
+ });
113
+ });
91
114
  afterAll(() => {
92
- jest.clearAllMocks();
93
- homebridge.destroy();
115
+ destroy();
94
116
  });
95
- });
117
+ });
118
+
119
+ async function sleep(ms) {
120
+ return new Promise(resolve => setTimeout(resolve, ms));
121
+ }
@@ -71,7 +71,7 @@ function handleConnect(options) {
71
71
  version: packageConfig.version,
72
72
  transport: options.transport,
73
73
  keepalive: options.mqttOptions.keepalive,
74
- routines: options.events,
74
+ routines: options.routines,
75
75
  }));
76
76
 
77
77
  connection.client.on('message', (topic, message) => handleMessage(topic, message, options));
@@ -467,12 +467,13 @@ function alexaResponse(message, hbResponse, err, value) {
467
467
  // alexaMessages.alexaStateResponse(message, reportState, status, err);
468
468
  // message, reportState, hbResponse, err
469
469
  function alexaStateResponse(properties, message) {
470
+ // debug("alexaStateResponse", properties, JSON.stringify(message, null, 2));
470
471
  var endpointId = message.directive.endpoint.endpointId;
471
472
  var messageId = message.directive.header.messageId;
472
473
  var correlationToken = message.directive.header.correlationToken;
473
474
  var response;
474
475
 
475
- if (properties instanceof Error) {
476
+ if (properties instanceof Error || properties[0].length === 0) {
476
477
  // console.log("ERROR: alexaStateResponse", properties.message);
477
478
  response = {
478
479
  "event": {
@@ -84,6 +84,24 @@ describe('alexaMessages', () => {
84
84
  expect(response.event.payload.type).toBe('ENDPOINT_UNREACHABLE');
85
85
  });
86
86
 
87
+ test('should return ErrorResponse when properties are empty', () => {
88
+ const properties = [[]];
89
+ const message = {
90
+ directive: {
91
+ header: {
92
+ messageId: '123',
93
+ name: 'ReportState'
94
+ },
95
+ endpoint: {
96
+ endpointId: 'endpoint-001'
97
+ }
98
+ }
99
+ };
100
+ const response = alexaStateResponse(properties, message);
101
+ expect(response.event.header.name).toBe('ErrorResponse');
102
+ expect(response.event.payload.type).toBe('ENDPOINT_UNREACHABLE');
103
+ });
104
+
87
105
  test('should return StateReport for ReportState directive', () => {
88
106
  const properties = [{
89
107
  namespace: 'Alexa.PowerController',
@@ -17,7 +17,7 @@ function Homebridge(devices, context) {
17
17
  this.deviceID = devices.deviceID;
18
18
  this.id = devices.instance.txt.id;
19
19
  this.options = {
20
- events: context.events,
20
+ routines: context.routines,
21
21
  speakers: context.speakers,
22
22
  blind: context.blind,
23
23
  door: context.door,
@@ -0,0 +1,105 @@
1
+ var Homebridges = require('./Homebridges.js').Homebridges;
2
+ const Homebridge = require('./Homebridge');
3
+
4
+ describe('Parse Discovery Response', () => {
5
+
6
+ test('Routines False', () => {
7
+
8
+ const devices = require('../../../test/endPoints.test.json');
9
+
10
+ const message = {};
11
+ const context = {
12
+ pin: '031-45-154',
13
+ filter: null,
14
+ beta: false,
15
+ routines: false,
16
+ combine: [
17
+ { into: 'Living', from: [Array] },
18
+ { into: 'Deck', from: [Array] }
19
+ ],
20
+ oldParser: false,
21
+ refresh: 900,
22
+ speakers: [
23
+ { manufacturer: 'yamaha-home', name: 'Deck' },
24
+ { manufacturer: 'yamaha-home', name: 'Living' },
25
+ { manufacturer: 'HTTP-IRBlaster', name: 'Stereo' }
26
+ ],
27
+ inputs: false,
28
+ channel: false,
29
+ blind: false,
30
+ thermostatTurnOn: 0,
31
+ deviceListHandling: 'none',
32
+ deviceList: [],
33
+ door: false,
34
+ name: 'Alexa',
35
+ mergeServiceName: false,
36
+ CloudTransport: 'wss',
37
+ LegacyCloudTransport: false,
38
+ keepalive: 300,
39
+ enhancedSkip: true,
40
+ deviceCleanup: true,
41
+ debug: true,
42
+ platform: 'Alexa'
43
+ };
44
+
45
+
46
+ const hbDevices = new Homebridges(devices, context);
47
+ expect(hbDevices.homebridges).toHaveLength(21);
48
+
49
+ const response = hbDevices.toAlexa(context, null);
50
+ expect(response.event.payload.endpoints).toHaveLength(87);
51
+
52
+ const discoveryResponse = require('../../../test/discoveryResponse.test.json');
53
+ expect(response).toEqual(discoveryResponse);
54
+
55
+ });
56
+
57
+ test('Routines True', () => {
58
+
59
+ const devices = require('../../../test/endPoints.test.json');
60
+
61
+ const message = {};
62
+ const context = {
63
+ pin: '031-45-154',
64
+ filter: null,
65
+ beta: false,
66
+ routines: true,
67
+ combine: [
68
+ { into: 'Living', from: [Array] },
69
+ { into: 'Deck', from: [Array] }
70
+ ],
71
+ oldParser: false,
72
+ refresh: 900,
73
+ speakers: [
74
+ { manufacturer: 'yamaha-home', name: 'Deck' },
75
+ { manufacturer: 'yamaha-home', name: 'Living' },
76
+ { manufacturer: 'HTTP-IRBlaster', name: 'Stereo' }
77
+ ],
78
+ inputs: false,
79
+ channel: false,
80
+ blind: false,
81
+ thermostatTurnOn: 0,
82
+ deviceListHandling: 'none',
83
+ deviceList: [],
84
+ door: false,
85
+ name: 'Alexa',
86
+ mergeServiceName: false,
87
+ CloudTransport: 'wss',
88
+ LegacyCloudTransport: false,
89
+ keepalive: 300,
90
+ enhancedSkip: true,
91
+ deviceCleanup: true,
92
+ debug: true,
93
+ platform: 'Alexa'
94
+ };
95
+
96
+ const hbDevices = new Homebridges(devices, context);
97
+ expect(hbDevices.homebridges).toHaveLength(21);
98
+
99
+ const response = hbDevices.toAlexa(context, null);
100
+ expect(response.event.payload.endpoints).toHaveLength(87);
101
+
102
+ const discoveryResponse = require('../../../test/discoveryResponse.routines.test.json');
103
+ expect(response).toEqual(discoveryResponse);
104
+ });
105
+ });
@@ -216,11 +216,11 @@ Service.prototype.toAlexa = function (context) {
216
216
  "brightness": this.characteristics["Brightness"].getCharacteristic,
217
217
  "on": this.characteristics["On"].getCharacteristic
218
218
  });
219
- capabilities = capabilities.concat(messages.lookupCapabilities("ColorController", context.events));
219
+ capabilities = capabilities.concat(messages.lookupCapabilities("ColorController", context.routines));
220
220
  }
221
221
  break;
222
222
  case "Thermostat":
223
- capabilities = capabilities.concat(messages.lookupCapabilities("Active", context.events, cookie));
223
+ capabilities = capabilities.concat(messages.lookupCapabilities("Active", context.routines, cookie));
224
224
  case "Heater Cooler":
225
225
  /*
226
226
  reportState.push({
@@ -230,7 +230,7 @@ Service.prototype.toAlexa = function (context) {
230
230
  "aid": this.aid
231
231
  });
232
232
  */
233
- capabilities = capabilities.concat(messages.lookupCapabilities("ThermostatController", context.events, cookie));
233
+ capabilities = capabilities.concat(messages.lookupCapabilities("ThermostatController", context.routines, cookie));
234
234
  break;
235
235
  case "Temperature Sensor":
236
236
  // Fix for issue #237
@@ -244,7 +244,7 @@ Service.prototype.toAlexa = function (context) {
244
244
  case "Input Source":
245
245
  // debug("Input Source", this.characteristics);
246
246
  cookie[normalizeInput(this.characteristics["Configured Name"].value)] = messages.cookieV(this.characteristics["Identifier"].value, context);
247
- capabilities = capabilities.concat(messages.lookupCapabilities("Input Source", context.events, cookie));
247
+ capabilities = capabilities.concat(messages.lookupCapabilities("Input Source", context.routines, cookie));
248
248
  break;
249
249
  }
250
250
  } catch (err) {
@@ -54,192 +54,197 @@ function stateToProperties(statusObject, hbResponse) {
54
54
  // debug("stateToProperties - hbResponse", hbResponse);
55
55
  // Convert each individual HAP hbResponse to Alexa Format
56
56
  statusObject.elements.forEach((element, i) => {
57
- // debug("stateToProperties - element", element, i, hbResponse[i]);
58
-
59
- switch (element.interface.toLowerCase()) {
60
- case "alexa.speaker":
61
- properties.push({
62
- "namespace": "Alexa.Speaker",
63
- "name": "volume",
64
- "value": round(_getValue(element, hbResponse, i).value),
65
- "timeOfSample": now.toISOString(),
66
- "uncertaintyInMilliseconds": 500
67
- });
68
- properties.push({
69
- "namespace": "Alexa.Speaker",
70
- "name": "muted",
71
- "value": false,
72
- "timeOfSample": now.toISOString(),
73
- "uncertaintyInMilliseconds": 500
74
- });
75
- break;
76
- case "alexa.stepspeaker":
77
- // No response needed
78
- break;
79
- case "alexa.powercontroller":
80
- properties.push({
81
- "namespace": "Alexa.PowerController",
82
- "name": "powerState",
83
- "value": _getValue(element, hbResponse, i).value ? "ON" : "OFF",
84
- "timeOfSample": now.toISOString(),
85
- "uncertaintyInMilliseconds": 500
86
- });
87
- break;
88
- case "alexa.powerlevelcontroller":
89
- properties.push({
90
- "namespace": "Alexa.PowerLevelController",
91
- "name": "powerLevel",
92
- "value": round(_getValue(element, hbResponse, i).value),
93
- "timeOfSample": now.toISOString(),
94
- "uncertaintyInMilliseconds": 500
95
- });
96
- break;
97
- case "alexa.rangecontroller":
98
- properties.push({
99
- "namespace": "Alexa.RangeController",
100
- "name": "rangeValue",
101
- "value": round(_getValue(element, hbResponse, i).value),
102
- "timeOfSample": now.toISOString(),
103
- "uncertaintyInMilliseconds": 500
104
- });
105
- break;
106
- case "alexa.modecontroller":
107
- properties.push({
108
- "namespace": "Alexa.ModeController",
109
- "instance": "GarageDoor.Position",
110
- "name": "mode",
111
- "value": _getValue(element, hbResponse, i).value ? "Position.Down" : "Position.Up",
112
- "timeOfSample": now.toISOString(),
113
- "uncertaintyInMilliseconds": 500
114
- });
115
- break;
116
- case "alexa.colortemperaturecontroller":
117
- properties.push({
118
- "namespace": "Alexa.ColorTemperatureController",
119
- "name": "colorTemperatureInKelvin",
120
- "value": round(1000000 / _getValue(element, hbResponse, i).value),
121
- "timeOfSample": now.toISOString(),
122
- "uncertaintyInMilliseconds": 500
123
- });
124
- break;
125
- case "alexa.colorcontroller":
126
- properties.push({
127
- "namespace": "Alexa.ColorController",
128
- "name": "color",
129
- "value": _getValue(element, hbResponse, i).value,
130
- "timeOfSample": now.toISOString(),
131
- "uncertaintyInMilliseconds": 500
132
- });
133
- i = i + 2; // Skip over the 3 color values
134
- break;
135
- case "alexa.temperaturesensor":
136
- properties.push({
137
- "namespace": "Alexa.TemperatureSensor",
138
- "name": "temperature",
139
- "value": {
140
- "value": round(_getValue(element, hbResponse, i).value, 1),
141
- "scale": "CELSIUS"
142
- },
143
- "timeOfSample": now.toISOString(),
144
- "uncertaintyInMilliseconds": 500
145
- });
146
- break;
147
- case "alexa.contactsensor":
148
- properties.push({
149
- "namespace": "Alexa.ContactSensor",
150
- "name": "detectionState",
151
- "value": _getValue(element, hbResponse, i).value ? "DETECTED" : "NOT_DETECTED",
152
- "timeOfSample": now.toISOString(),
153
- "uncertaintyInMilliseconds": 500
154
- });
155
- break;
156
- case "alexa.motionsensor":
157
- properties.push({
158
- "namespace": "Alexa.MotionSensor",
159
- "name": "detectionState",
160
- "value": _getValue(element, hbResponse, i).value ? "DETECTED" : "NOT_DETECTED",
161
- "timeOfSample": now.toISOString(),
162
- "uncertaintyInMilliseconds": 500
163
- });
164
- break;
165
- case "alexa.doorbelleventsource":
166
- properties.push({
167
- "namespace": "Alexa.DoorbellEventSource",
168
- "name": "detectionState",
169
- "value": _getValue(element, hbResponse, i).value ? "DETECTED" : "NOT_DETECTED",
170
- "timeOfSample": now.toISOString(),
171
- "uncertaintyInMilliseconds": 500
172
- });
173
- break;
174
- // Characteristic.LockCurrentState.UNSECURED = 0;
175
- // Characteristic.LockCurrentState.SECURED = 1;
176
- // Characteristic.LockCurrentState.JAMMED = 2;
177
- // Characteristic.LockCurrentState.UNKNOWN = 3;
178
- case "alexa.lockcontroller":
179
- properties.push({
180
- "namespace": "Alexa.LockController",
181
- "name": "lockState",
182
- "value": _lockState(_getValue(element, hbResponse, i).value),
183
- "timeOfSample": now.toISOString(),
184
- "uncertaintyInMilliseconds": 500
185
- });
186
- break;
187
- case "alexa.thermostatcontrollertargetsetpoint":
188
- properties.push({
189
- namespace: "Alexa.ThermostatController",
190
- name: "targetSetpoint",
191
- value: {
192
- value: _getValue(element, hbResponse, i).value,
193
- scale: "CELSIUS"
194
- },
195
- timeOfSample: now.toISOString(),
196
- uncertaintyInMilliseconds: 500
197
- });
198
- break;
199
- case "alexa.thermostatcontrollerlowersetpoint":
200
- properties.push({
201
- "namespace": "Alexa.ThermostatController",
202
- "name": "lowerSetpoint",
203
- "value": {
204
- "value": _getValue(element, hbResponse, i).value,
205
- "scale": "CELSIUS"
206
- },
207
- "timeOfSample": now.toISOString(),
208
- "uncertaintyInMilliseconds": 500
209
- });
210
- break;
211
- case "alexa.thermostatcontrolleruppersetpoint":
212
- properties.push({
213
- "namespace": "Alexa.ThermostatController",
214
- "name": "upperSetpoint",
215
- "value": {
216
- "value": _getValue(element, hbResponse, i).value,
217
- "scale": "CELSIUS"
218
- },
219
- "timeOfSample": now.toISOString(),
220
- "uncertaintyInMilliseconds": 500
221
- });
222
- break;
223
- case "alexa.thermostatcontrollerthermostatmode":
224
- properties.push({
225
- "namespace": "Alexa.ThermostatController",
226
- "name": "thermostatMode",
227
- "value": _getThermoMode(_getValue(element, hbResponse, i).value),
228
- "timeOfSample": now.toISOString(),
229
- "uncertaintyInMilliseconds": 500
230
- });
231
- if (!statusObject.elements.find(x => x.interface.toLowerCase() === "alexa.powercontroller")) {
57
+ // debug("stateToProperties - element", element, _getValue(element, hbResponse, i).status);
58
+
59
+ if (_getValue(element, hbResponse, i).status === 0 || _getValue(element, hbResponse, i).status === undefined) {
60
+
61
+ switch (element.interface.toLowerCase()) {
62
+ case "alexa.speaker":
63
+ properties.push({
64
+ "namespace": "Alexa.Speaker",
65
+ "name": "volume",
66
+ "value": round(_getValue(element, hbResponse, i).value),
67
+ "timeOfSample": now.toISOString(),
68
+ "uncertaintyInMilliseconds": 500
69
+ });
70
+ properties.push({
71
+ "namespace": "Alexa.Speaker",
72
+ "name": "muted",
73
+ "value": false,
74
+ "timeOfSample": now.toISOString(),
75
+ "uncertaintyInMilliseconds": 500
76
+ });
77
+ break;
78
+ case "alexa.stepspeaker":
79
+ // No response needed
80
+ break;
81
+ case "alexa.powercontroller":
232
82
  properties.push({
233
83
  "namespace": "Alexa.PowerController",
234
84
  "name": "powerState",
235
- "value": properties[0].value === "OFF" ? "OFF" : "ON",
85
+ "value": _getValue(element, hbResponse, i).value ? "ON" : "OFF",
236
86
  "timeOfSample": now.toISOString(),
237
87
  "uncertaintyInMilliseconds": 500
238
88
  });
239
- }
240
- break;
241
- default:
242
- debug("ERROR: statusReport unknown/handled device", element, reportState);
89
+ break;
90
+ case "alexa.powerlevelcontroller":
91
+ properties.push({
92
+ "namespace": "Alexa.PowerLevelController",
93
+ "name": "powerLevel",
94
+ "value": round(_getValue(element, hbResponse, i).value),
95
+ "timeOfSample": now.toISOString(),
96
+ "uncertaintyInMilliseconds": 500
97
+ });
98
+ break;
99
+ case "alexa.rangecontroller":
100
+ properties.push({
101
+ "namespace": "Alexa.RangeController",
102
+ "name": "rangeValue",
103
+ "value": round(_getValue(element, hbResponse, i).value),
104
+ "timeOfSample": now.toISOString(),
105
+ "uncertaintyInMilliseconds": 500
106
+ });
107
+ break;
108
+ case "alexa.modecontroller":
109
+ properties.push({
110
+ "namespace": "Alexa.ModeController",
111
+ "instance": "GarageDoor.Position",
112
+ "name": "mode",
113
+ "value": _getValue(element, hbResponse, i).value ? "Position.Down" : "Position.Up",
114
+ "timeOfSample": now.toISOString(),
115
+ "uncertaintyInMilliseconds": 500
116
+ });
117
+ break;
118
+ case "alexa.colortemperaturecontroller":
119
+ properties.push({
120
+ "namespace": "Alexa.ColorTemperatureController",
121
+ "name": "colorTemperatureInKelvin",
122
+ "value": round(1000000 / _getValue(element, hbResponse, i).value),
123
+ "timeOfSample": now.toISOString(),
124
+ "uncertaintyInMilliseconds": 500
125
+ });
126
+ break;
127
+ case "alexa.colorcontroller":
128
+ properties.push({
129
+ "namespace": "Alexa.ColorController",
130
+ "name": "color",
131
+ "value": _getValue(element, hbResponse, i).value,
132
+ "timeOfSample": now.toISOString(),
133
+ "uncertaintyInMilliseconds": 500
134
+ });
135
+ i = i + 2; // Skip over the 3 color values
136
+ break;
137
+ case "alexa.temperaturesensor":
138
+ properties.push({
139
+ "namespace": "Alexa.TemperatureSensor",
140
+ "name": "temperature",
141
+ "value": {
142
+ "value": round(_getValue(element, hbResponse, i).value, 1),
143
+ "scale": "CELSIUS"
144
+ },
145
+ "timeOfSample": now.toISOString(),
146
+ "uncertaintyInMilliseconds": 500
147
+ });
148
+ break;
149
+ case "alexa.contactsensor":
150
+ properties.push({
151
+ "namespace": "Alexa.ContactSensor",
152
+ "name": "detectionState",
153
+ "value": _getValue(element, hbResponse, i).value ? "DETECTED" : "NOT_DETECTED",
154
+ "timeOfSample": now.toISOString(),
155
+ "uncertaintyInMilliseconds": 500
156
+ });
157
+ break;
158
+ case "alexa.motionsensor":
159
+ properties.push({
160
+ "namespace": "Alexa.MotionSensor",
161
+ "name": "detectionState",
162
+ "value": _getValue(element, hbResponse, i).value ? "DETECTED" : "NOT_DETECTED",
163
+ "timeOfSample": now.toISOString(),
164
+ "uncertaintyInMilliseconds": 500
165
+ });
166
+ break;
167
+ case "alexa.doorbelleventsource":
168
+ properties.push({
169
+ "namespace": "Alexa.DoorbellEventSource",
170
+ "name": "detectionState",
171
+ "value": _getValue(element, hbResponse, i).value ? "DETECTED" : "NOT_DETECTED",
172
+ "timeOfSample": now.toISOString(),
173
+ "uncertaintyInMilliseconds": 500
174
+ });
175
+ break;
176
+ // Characteristic.LockCurrentState.UNSECURED = 0;
177
+ // Characteristic.LockCurrentState.SECURED = 1;
178
+ // Characteristic.LockCurrentState.JAMMED = 2;
179
+ // Characteristic.LockCurrentState.UNKNOWN = 3;
180
+ case "alexa.lockcontroller":
181
+ properties.push({
182
+ "namespace": "Alexa.LockController",
183
+ "name": "lockState",
184
+ "value": _lockState(_getValue(element, hbResponse, i).value),
185
+ "timeOfSample": now.toISOString(),
186
+ "uncertaintyInMilliseconds": 500
187
+ });
188
+ break;
189
+ case "alexa.thermostatcontrollertargetsetpoint":
190
+ properties.push({
191
+ namespace: "Alexa.ThermostatController",
192
+ name: "targetSetpoint",
193
+ value: {
194
+ value: _getValue(element, hbResponse, i).value,
195
+ scale: "CELSIUS"
196
+ },
197
+ timeOfSample: now.toISOString(),
198
+ uncertaintyInMilliseconds: 500
199
+ });
200
+ break;
201
+ case "alexa.thermostatcontrollerlowersetpoint":
202
+ properties.push({
203
+ "namespace": "Alexa.ThermostatController",
204
+ "name": "lowerSetpoint",
205
+ "value": {
206
+ "value": _getValue(element, hbResponse, i).value,
207
+ "scale": "CELSIUS"
208
+ },
209
+ "timeOfSample": now.toISOString(),
210
+ "uncertaintyInMilliseconds": 500
211
+ });
212
+ break;
213
+ case "alexa.thermostatcontrolleruppersetpoint":
214
+ properties.push({
215
+ "namespace": "Alexa.ThermostatController",
216
+ "name": "upperSetpoint",
217
+ "value": {
218
+ "value": _getValue(element, hbResponse, i).value,
219
+ "scale": "CELSIUS"
220
+ },
221
+ "timeOfSample": now.toISOString(),
222
+ "uncertaintyInMilliseconds": 500
223
+ });
224
+ break;
225
+ case "alexa.thermostatcontrollerthermostatmode":
226
+ properties.push({
227
+ "namespace": "Alexa.ThermostatController",
228
+ "name": "thermostatMode",
229
+ "value": _getThermoMode(_getValue(element, hbResponse, i).value),
230
+ "timeOfSample": now.toISOString(),
231
+ "uncertaintyInMilliseconds": 500
232
+ });
233
+ if (!statusObject.elements.find(x => x.interface.toLowerCase() === "alexa.powercontroller")) {
234
+ properties.push({
235
+ "namespace": "Alexa.PowerController",
236
+ "name": "powerState",
237
+ "value": properties[0].value === "OFF" ? "OFF" : "ON",
238
+ "timeOfSample": now.toISOString(),
239
+ "uncertaintyInMilliseconds": 500
240
+ });
241
+ }
242
+ break;
243
+ default:
244
+ debug("ERROR: statusReport unknown/handled device", element, reportState);
245
+ }
246
+ } else {
247
+ debug("ERROR: statusReport error", element, _getValue(element, hbResponse, i));
243
248
  }
244
249
  });
245
250
 
@@ -765,8 +770,8 @@ function lookupCapabilities(capability, options, operations, devices) {
765
770
  "supported": [{
766
771
  "name": "detectionState"
767
772
  }],
768
- "proactivelyReported": options.events,
769
- "retrievable": true
773
+ "proactivelyReported": options.routines,
774
+ "retrievable": !options.routines
770
775
  }
771
776
  });
772
777
  break;
@@ -782,8 +787,8 @@ function lookupCapabilities(capability, options, operations, devices) {
782
787
  "supported": [{
783
788
  "name": "detectionState"
784
789
  }],
785
- "proactivelyReported": options.events,
786
- "retrievable": true
790
+ "proactivelyReported": options.routines,
791
+ "retrievable": !options.routines
787
792
  }
788
793
  });
789
794
  break;
@@ -1271,7 +1276,7 @@ function _getValue(element, hbResponse) {
1271
1276
  saturation: _round(_getHBValue(element.saturation, hbResponse).value / 100, 4),
1272
1277
  brightness: _round(_getHBValue(element.brightness, hbResponse).value / 100, 4)
1273
1278
  };
1274
- debug("Color Value", value);
1279
+ // debug("Color Value", value);
1275
1280
  return {
1276
1281
  value: value,
1277
1282
  status: 0
@@ -0,0 +1,96 @@
1
+ const { lookupCapabilities } = require('./messages');
2
+
3
+ describe('lib/parse/messages', () => {
4
+ describe('lookupCapabilities', () => {
5
+ test('should return supported operations for PlaybackController capability', () => {
6
+ const capability = 'PlaybackController';
7
+ const options = {};
8
+ const operations = {
9
+ Play: {},
10
+ Pause: {},
11
+ Stop: {},
12
+ };
13
+ const devices = {};
14
+
15
+ const result = lookupCapabilities(capability, options, operations, devices);
16
+
17
+ expect(result).toEqual([
18
+ {
19
+ type: 'AlexaInterface',
20
+ interface: 'Alexa.PlaybackController',
21
+ version: '3',
22
+ supportedOperations: ['Play', 'Pause', 'Stop'],
23
+ },
24
+ ]);
25
+ });
26
+
27
+ test('should return supported properties for ChannelController capability', () => {
28
+ const capability = 'ChannelController';
29
+ const options = {};
30
+ const operations = {};
31
+ const devices = {};
32
+
33
+ const result = lookupCapabilities(capability, options, operations, devices);
34
+
35
+ expect(result).toEqual([
36
+ {
37
+ type: 'AlexaInterface',
38
+ interface: 'Alexa.ChannelController',
39
+ version: '3',
40
+ properties: {
41
+ supported: [{ name: 'channel' }],
42
+ proactivelyReported: false,
43
+ retrievable: true,
44
+ },
45
+ },
46
+ ]);
47
+ });
48
+
49
+ test('should return supported properties for Motion Detected capability - Routines false', () => {
50
+ const capability = 'Motion Detected';
51
+ const options = { routines: false };
52
+ const operations = {};
53
+ const devices = {};
54
+
55
+ const result = lookupCapabilities(capability, options, operations, devices);
56
+
57
+ expect(result).toEqual([
58
+ {
59
+ type: 'AlexaInterface',
60
+ interface: 'Alexa.MotionSensor',
61
+ version: '3',
62
+ properties: {
63
+ supported: [{ name: 'detectionState' }],
64
+ proactivelyReported: false,
65
+ retrievable: true,
66
+ },
67
+ },
68
+ ]);
69
+ });
70
+
71
+ test('should return supported properties for Motion Detected capability - Routines true', () => {
72
+ const capability = 'Motion Detected';
73
+ const options = { routines: true };
74
+ const operations = {};
75
+ const devices = {};
76
+
77
+ const result = lookupCapabilities(capability, options, operations, devices);
78
+
79
+ expect(result).toEqual([
80
+ {
81
+ type: 'AlexaInterface',
82
+ interface: 'Alexa.MotionSensor',
83
+ version: '3',
84
+ properties: {
85
+ supported: [{ name: 'detectionState' }],
86
+ proactivelyReported: true,
87
+ retrievable: false,
88
+ },
89
+ },
90
+ ]);
91
+ });
92
+
93
+ // Add more test cases for other capabilities
94
+
95
+ });
96
+ });
@@ -49,39 +49,38 @@ describe('stateToProperties', () => {
49
49
 
50
50
  test('should convert Alexa.TemperatureSensor error response correctly', () => {
51
51
  const statusObject = {
52
- elements: [{ interface: 'Alexa.TemperatureSensor', aid: 101, iid: 10 }]
52
+ elements: [{ interface: 'Alexa.TemperatureSensor', aid: 123, iid: 10 }]
53
53
  };
54
54
  const hbResponse = [{ aid: 123, iid: 10, status: -70410 }];
55
55
 
56
56
  const result = stateToProperties(statusObject, hbResponse);
57
57
 
58
- expect(result).toEqual([{
59
- namespace: 'Alexa.TemperatureSensor',
60
- name: 'temperature',
61
- value: {
62
- "scale": "CELSIUS",
63
- "value": 25,
64
- },
65
- timeOfSample: mockDate,
66
- uncertaintyInMilliseconds: 500
67
- }]);
58
+ expect(result).toHaveLength(0);
68
59
  });
69
60
 
70
61
  test('should convert Alexa.ColorController response correctly', () => {
71
62
  const statusObject = {
72
- elements: [{ interface: 'Alexa.ColorController', aid: 101, iid: 10 }]
63
+ elements: [{
64
+ interface: 'Alexa.ColorController',
65
+ hue: { aid: 9, iid: 14 },
66
+ saturation: { aid: 9, iid: 15 },
67
+ brightness: { aid: 9, iid: 11 }
68
+ }]
73
69
  };
74
- const hbResponse = [{ aid: 101, iid: 10, value: true }];
70
+
71
+ const hbResponse = [
72
+ { aid: 9, iid: 11, value: 0 },
73
+ { aid: 9, iid: 13, value: 242 },
74
+ { aid: 9, iid: 14, value: 44 },
75
+ { aid: 9, iid: 15, value: 24 },
76
+ { aid: 9, iid: 10, value: 0 }
77
+ ];
75
78
 
76
79
  const result = stateToProperties(statusObject, hbResponse);
77
80
 
78
81
  expect(result).toEqual([{
79
- namespace: 'Alexa.ColorController',
80
- name: 'temperature',
81
- value: {
82
- "scale": "CELSIUS",
83
- "value": 25,
84
- },
82
+ namespace: "Alexa.ColorController",
83
+ name: "color", "value": { "hue": 44, "saturation": 0.24, "brightness": 0 },
85
84
  timeOfSample: mockDate,
86
85
  uncertaintyInMilliseconds: 500
87
86
  }]);
@@ -160,4 +159,5 @@ describe('stateToProperties', () => {
160
159
 
161
160
  expect(result).toEqual([]);
162
161
  });
163
- });
162
+ });
163
+
package/src/plugin.js CHANGED
@@ -122,7 +122,7 @@ class AlexaHome {
122
122
  deviceList: this.deviceList,
123
123
  door: this.door,
124
124
  mergeServiceName: this.mergeServiceName,
125
- events: this.routines,
125
+ routines: this.routines,
126
126
  enhancedSkip: this.enhancedSkip,
127
127
  };
128
128
 
@@ -18,7 +18,7 @@ describe.skip('alexaHome', () => {
18
18
  username: 'testUser',
19
19
  password: 'testPass',
20
20
  filter: 'testFilter',
21
- beta: false,
21
+ beta: false,
22
22
  routines: false,
23
23
  combine: false,
24
24
  oldParser: false,