homebridge-alexa 0.8.2 → 0.8.3-beta.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.
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-alexa",
3
- "version": "0.8.2",
3
+ "version": "0.8.3-beta.0",
4
4
  "description": "Control your Homebridge devices with Amazon Alexa.",
5
5
  "main": "src/plugin.js",
6
6
  "scripts": {
@@ -73,4 +73,4 @@
73
73
  "src/**"
74
74
  ]
75
75
  }
76
- }
76
+ }
@@ -36,7 +36,7 @@ function hapDiscovery(options) {
36
36
  homebridge.on('Ready', function () {
37
37
  alexaDiscovery.call(options, null, function () {
38
38
  // debug("Events", options);
39
- if (options.events) {
39
+ if (options.routines) {
40
40
  registerEvents(messages.checkEventDeviceList.call(options, hbDevices.toEvents()));
41
41
  }
42
42
  });
@@ -95,11 +95,10 @@ function registerEvents(message) {
95
95
  function alexaDiscovery(message, callback) {
96
96
  // debug('alexaDiscovery', this);
97
97
  homebridge.HAPaccessories(function (endPoints) {
98
- debug("alexaDiscovery");
98
+ debug("alexaDiscovery", this);
99
99
  var response;
100
100
 
101
101
  hbDevices = new Homebridges(endPoints, this);
102
- // debug("RESPONSE", JSON.stringify(hbDevices, null, 2));
103
102
  response = hbDevices.toAlexa(this, message);
104
103
 
105
104
  // debug("RESPONSE", JSON.stringify(response, null, 2));
@@ -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));
@@ -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,54 @@
1
+ var Homebridges = require('./Homebridges.js').Homebridges;
2
+ const Homebridge = require('./Homebridge');
3
+
4
+ describe('Homebridges', () => {
5
+ test('should create an array of Homebridge instances', () => {
6
+
7
+ const fs = require('fs');
8
+ const storagePath = 'test/endPoints.test.json';
9
+ const devices = fs.readFileSync(storagePath);
10
+
11
+ const context = {
12
+ pin: '031-45-154',
13
+ filter: null,
14
+ beta: false,
15
+ routines: true,
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
+ const homebridges = new Homebridges(JSON.parse(devices), context);
46
+
47
+ expect(homebridges.homebridges).toHaveLength(21);
48
+ homebridges.homebridges.forEach((homebridge, index) => {
49
+ expect(homebridge).toBeInstanceOf(Homebridge);
50
+ expect(homebridge.element).toEqual(devices[index]);
51
+ expect(homebridge.context).toBe(context);
52
+ });
53
+ });
54
+ });
@@ -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) {
@@ -765,8 +765,8 @@ function lookupCapabilities(capability, options, operations, devices) {
765
765
  "supported": [{
766
766
  "name": "detectionState"
767
767
  }],
768
- "proactivelyReported": options.events,
769
- "retrievable": true
768
+ "proactivelyReported": options.routines,
769
+ "retrievable": !options.routines
770
770
  }
771
771
  });
772
772
  break;
@@ -782,8 +782,8 @@ function lookupCapabilities(capability, options, operations, devices) {
782
782
  "supported": [{
783
783
  "name": "detectionState"
784
784
  }],
785
- "proactivelyReported": options.events,
786
- "retrievable": true
785
+ "proactivelyReported": options.routines,
786
+ "retrievable": !options.routines
787
787
  }
788
788
  });
789
789
  break;
@@ -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
+ });
@@ -60,7 +60,7 @@ describe('stateToProperties', () => {
60
60
  name: 'temperature',
61
61
  value: {
62
62
  "scale": "CELSIUS",
63
- "value": 25,
63
+ "value": NaN,
64
64
  },
65
65
  timeOfSample: mockDate,
66
66
  uncertaintyInMilliseconds: 500
@@ -69,19 +69,27 @@ describe('stateToProperties', () => {
69
69
 
70
70
  test('should convert Alexa.ColorController response correctly', () => {
71
71
  const statusObject = {
72
- elements: [{ interface: 'Alexa.ColorController', aid: 101, iid: 10 }]
72
+ elements: [{
73
+ interface: 'Alexa.ColorController',
74
+ hue: { aid: 9, iid: 14 },
75
+ saturation: { aid: 9, iid: 15 },
76
+ brightness: { aid: 9, iid: 11 }
77
+ }]
73
78
  };
74
- const hbResponse = [{ aid: 101, iid: 10, value: true }];
79
+
80
+ const hbResponse = [
81
+ { aid: 9, iid: 11, value: 0 },
82
+ { aid: 9, iid: 13, value: 242 },
83
+ { aid: 9, iid: 14, value: 44 },
84
+ { aid: 9, iid: 15, value: 24 },
85
+ { aid: 9, iid: 10, value: 0 }
86
+ ];
75
87
 
76
88
  const result = stateToProperties(statusObject, hbResponse);
77
89
 
78
90
  expect(result).toEqual([{
79
- namespace: 'Alexa.ColorController',
80
- name: 'temperature',
81
- value: {
82
- "scale": "CELSIUS",
83
- "value": 25,
84
- },
91
+ namespace: "Alexa.ColorController",
92
+ name: "color", "value": { "hue": 44, "saturation": 0.24, "brightness": 0 },
85
93
  timeOfSample: mockDate,
86
94
  uncertaintyInMilliseconds: 500
87
95
  }]);
@@ -160,4 +168,5 @@ describe('stateToProperties', () => {
160
168
 
161
169
  expect(result).toEqual([]);
162
170
  });
163
- });
171
+ });
172
+
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,