homebridge-alexa 0.9.0 → 0.9.1-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.
- package/.github/npm-version-script.js +97 -0
- package/CHANGELOG.md +9 -0
- package/package.json +2 -2
- package/src/lib/alexaActions.js +4 -1
- package/src/lib/alexaActions.test.js +96 -2
|
@@ -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,15 @@
|
|
|
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
|
+
|
|
6
|
+
## 0.9.1 (2025-08-13)
|
|
7
|
+
|
|
8
|
+
## [Version 0.9.1](https://github.com/northernman54/homebridge-alexa/compare/v0.9.0...v0.9.1)
|
|
9
|
+
|
|
10
|
+
#### Bug Fix
|
|
11
|
+
|
|
12
|
+
- AC can't change temperature #579
|
|
13
|
+
|
|
5
14
|
## 0.9.0 (2025-03-30)
|
|
6
15
|
|
|
7
16
|
## [Version 0.9.0](https://github.com/northernman54/homebridge-alexa/compare/v0.8.2...v0.9.0)
|
package/package.json
CHANGED
package/src/lib/alexaActions.js
CHANGED
|
@@ -539,7 +539,7 @@ function alexaChannelController(message, callback) {
|
|
|
539
539
|
|
|
540
540
|
async function alexaThermostatController(message, callback) {
|
|
541
541
|
// debug("alexaThermostatController", JSON.stringify(message));
|
|
542
|
-
|
|
542
|
+
let action = message.directive.header.name;
|
|
543
543
|
const payloads = message.directive.payload;
|
|
544
544
|
var haAction;
|
|
545
545
|
// directive.header.name = SetThermostatMode, SetTargetTemperature
|
|
@@ -570,6 +570,7 @@ async function alexaThermostatController(message, callback) {
|
|
|
570
570
|
break;
|
|
571
571
|
case "SetTargetTemperature":
|
|
572
572
|
// targetSetpoint, lowerSetpoint, upperSetpoint
|
|
573
|
+
// debug("alexaThermostatController - SetTargetTemperature", JSON.stringify(payloads));
|
|
573
574
|
var characteristics = [];
|
|
574
575
|
for (var index in payloads) {
|
|
575
576
|
try {
|
|
@@ -595,6 +596,7 @@ async function alexaThermostatController(message, callback) {
|
|
|
595
596
|
}
|
|
596
597
|
debug("alexaThermostatController - haAction", JSON.stringify(haAction));
|
|
597
598
|
} catch (e) {
|
|
599
|
+
// debug("alexaThermostatController ERROR: '%s' Action: '%s' ", e.message, index, message.directive.endpoint.cookie);
|
|
598
600
|
this.log("alexaThermostatController ERROR: '%s' Action: '%s' ", e.message, index, message.directive.endpoint.cookie);
|
|
599
601
|
var response = alexaMessages.alexaResponse(message, "", e);
|
|
600
602
|
response.event.payload.type = "INVALID_VALUE"; // The directive contains a value that is not valid for the target endpoint. For example, an invalid heating mode, channel, or program value.
|
|
@@ -612,6 +614,7 @@ async function alexaThermostatController(message, callback) {
|
|
|
612
614
|
});
|
|
613
615
|
}
|
|
614
616
|
|
|
617
|
+
// debug("alexaThermostatController - characteristics", JSON.stringify(characteristics));
|
|
615
618
|
var body = {
|
|
616
619
|
"characteristics": characteristics
|
|
617
620
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { alexaMessage, setHomebridge, destroy } = require('./alexaActions.js');
|
|
1
|
+
const { alexaMessage, setHomebridge, destroy, alexaThermostatController } = require('./alexaActions.js');
|
|
2
2
|
|
|
3
3
|
jest.mock("hap-node-client", () => {
|
|
4
4
|
// console.log('Mock - hap-node-client');
|
|
@@ -16,17 +16,42 @@ const HAPstatusByDeviceID = (deviceID, body, callback) => {
|
|
|
16
16
|
break;
|
|
17
17
|
case "TemperatureSensor-NotResponding":
|
|
18
18
|
callback(null, { "characteristics": [{ "aid": 52, "iid": 12, "status": -70402 }] });
|
|
19
|
+
break;
|
|
19
20
|
case "TemperatureSensor-NoDevice":
|
|
20
21
|
callback(null, { "characteristics": [{ "aid": 52, "iid": 12, "status": -70410 }] });
|
|
21
22
|
break;
|
|
23
|
+
case "0E:53:9E:7C:32:AC": // Thermostat
|
|
24
|
+
callback(null, {
|
|
25
|
+
"characteristics": [
|
|
26
|
+
{ "aid": 61, "iid": 4, "value": 1 }, // PowerState
|
|
27
|
+
{ "aid": 61, "iid": 6, "value": 1 }, // ThermostatMode
|
|
28
|
+
{ "aid": 61, "iid": 7, "value": 20.0 }, // Temperature
|
|
29
|
+
{ "aid": 61, "iid": 8, "value": 18.0 }, // LowerSetpoint
|
|
30
|
+
{ "aid": 61, "iid": 9, "value": 22.0 } // UpperSetpoint
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
break;
|
|
22
34
|
default:
|
|
23
35
|
console.log('Missing Mock - HAPstatusByDeviceID', deviceID, body, callback);
|
|
24
36
|
callback(null, { deviceID: "device123", status: "off" });
|
|
25
37
|
}
|
|
26
38
|
}
|
|
27
39
|
|
|
40
|
+
const HAPcontrolByDeviceID = (deviceID, body, callback) => {
|
|
41
|
+
// console.log('Mock - HAPstatusByDeviceID', deviceID, body, callback);
|
|
42
|
+
switch (deviceID) {
|
|
43
|
+
case "0E:53:9E:7C:32:AC": // Thermostat
|
|
44
|
+
callback(null, null);
|
|
45
|
+
break;
|
|
46
|
+
default:
|
|
47
|
+
console.log('Missing Mock - HAPcontrolByDeviceID', deviceID, body, callback);
|
|
48
|
+
callback(null);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
28
52
|
setHomebridge({
|
|
29
53
|
HAPstatusByDeviceID: HAPstatusByDeviceID,
|
|
54
|
+
HAPcontrolByDeviceID: HAPcontrolByDeviceID,
|
|
30
55
|
destroy: jest.fn()
|
|
31
56
|
});
|
|
32
57
|
|
|
@@ -200,7 +225,7 @@ describe('ReportState', () => {
|
|
|
200
225
|
expect(callback).toHaveBeenCalled();
|
|
201
226
|
expect(context.log).toHaveBeenCalledTimes(0);
|
|
202
227
|
expect(context.log.error).toHaveBeenCalledTimes(1);
|
|
203
|
-
expect(context.log.error).toHaveBeenCalledWith("Error: Device not responding,
|
|
228
|
+
expect(context.log.error).toHaveBeenCalledWith("Error: Device not responding, scheduling delete report", "Njk6NjI6Qjc6QUU6Mzg6RDQtRGVmYXVsdCBNb2RlbC1OUkNIS0IgLSBMYUNyb3NzZS1UWDE0MVctQmFja3lhcmQtMDAwMDAwOEEtMDAwMC0xMDAwLTgwMDAtMDAyNkJCNzY1Mjkx");
|
|
204
229
|
const response = callback.mock.calls[0][1];
|
|
205
230
|
expect(response.event.header.name).toBe('ErrorResponse');
|
|
206
231
|
expect(response.event.payload.type).toBe('ENDPOINT_UNREACHABLE');
|
|
@@ -223,6 +248,45 @@ describe('ReportState', () => {
|
|
|
223
248
|
});
|
|
224
249
|
});
|
|
225
250
|
|
|
251
|
+
describe('Controller', () => {
|
|
252
|
+
const callback = jest.fn();
|
|
253
|
+
describe('alexaThermostatController', () => {
|
|
254
|
+
describe('SetTargetTemperature', () => {
|
|
255
|
+
const context = {
|
|
256
|
+
deviceCleanup: false,
|
|
257
|
+
log: jest.fn()
|
|
258
|
+
};
|
|
259
|
+
context.log.error = jest.fn();
|
|
260
|
+
context.log.warn = jest.fn();
|
|
261
|
+
|
|
262
|
+
beforeEach(() => {
|
|
263
|
+
callback.mockClear();
|
|
264
|
+
context.log.mockClear();
|
|
265
|
+
context.log.error.mockClear();
|
|
266
|
+
context.log.warn.mockClear();
|
|
267
|
+
});
|
|
268
|
+
test('targetSetpoint', async () => {
|
|
269
|
+
alexaThermostatController.call(context, thermostatSet, callback);
|
|
270
|
+
|
|
271
|
+
await sleep(500);
|
|
272
|
+
// Add your assertions here to verify the behavior of the function
|
|
273
|
+
expect(context.log).toHaveBeenCalledTimes(1);
|
|
274
|
+
expect(context.log).toHaveBeenCalledWith('Alexa.ThermostatController', 'SetTargetTemperature-Heat', '0E:53:9E:7C:32:AC', 'Q0M6MjI6M0Q6RTM6Q0Y6MzMtaG9tZWJyaWRnZS1TaWduaWZ5IE5ldGhlcmxhbmRzIEIuVi4tQWxpY2XigJlzIExpZ2h0LTAwMDAwMDQzLTAwMDAtMTAwMC04MDAwLTAwMjZCQjc2NTI5MQ==', '');
|
|
275
|
+
expect(context.log.error).toHaveBeenCalledTimes(0);
|
|
276
|
+
expect(context.log.warn).toHaveBeenCalledTimes(0);
|
|
277
|
+
expect(callback).toHaveBeenCalled();
|
|
278
|
+
const response = callback.mock.calls[0][1].context.properties;
|
|
279
|
+
//expect(response[0].value).toBe(45);
|
|
280
|
+
expect(response[0].name).toBe("targetSetpoint");
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
afterAll(() => {
|
|
285
|
+
destroy();
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
|
|
226
290
|
async function sleep(ms) {
|
|
227
291
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
228
292
|
}
|
|
@@ -265,4 +329,34 @@ const message4 = {
|
|
|
265
329
|
}
|
|
266
330
|
}
|
|
267
331
|
}
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
const thermostatSet = {
|
|
335
|
+
directive: {
|
|
336
|
+
header: {
|
|
337
|
+
namespace: "Alexa.ThermostatController",
|
|
338
|
+
"name": "SetTargetTemperature", "payloadVersion": "3", "messageId": "bbca65f0-183f-4bc9-9c3f-277e963106aa", "correlationToken": "AAAAAAAAAABr5SUHNe8BBkCT1sRvubl2AAIAAAAAAAB90j2CBpD9gvkdeRQB7XdUryxMTIusyHgcdCdx3swJ17yGKRsJsZi4Lx+VxDYBxWrXR8/zNW1axGXiPFGPIMZW9UQCfboB6lvDU8Gwfjxu/BruHTKTjbtLB/OLFc9i+XdGjT5g4NaFSqz8jLNTiHt/gjpEPRhf4nQTLLnqlrAQ/UBqEro+qCrD13Z741DG9qRiMjt9Ell8MfIWF/tMI8nAo5Tl/RN7Vgjq5rfF162bXWWbwiEm+NALzW0rh6SqTG1zv7CEczLKBh3HYIDaAo7W11Gbr8yMayElieKtzuB6rll3s9hJxRID6EY/7Qk4U8F4qflv+ZnpUS78HKkwaqlJOaKbiiRcJ01kM+QxhXD/uTuNYoSHfMoI2cJPJKy7s0QkazZtYQhfrXIm2zWVUX6BbpQOLA6PghDrI0+E37xGpibNwiteLYKgMPySOnJQ819yNjninJfTlKZYeDs3X1nybUysNezzpz+KyQmTlzGj31FV/G+nBzaqcSIfQu9OytV7Oo0midw0Jed3qT9UUO2hzNTM3VyUOupZT0N/h8WkQZQyu8yIy6KWXrEDgW+7LphqlEJ858R8u8fod0Hy75kvm578st9nEF3BhwLQSTq/thXLa0rA/S7w+iOZxg8slHKoUrl+VJyg4CwAnEF92LvTDDIYRY3jtI5QtBCPzA0uGg=="
|
|
339
|
+
},
|
|
340
|
+
"endpoint": {
|
|
341
|
+
"endpointId": "Q0M6MjI6M0Q6RTM6Q0Y6MzMtaG9tZWJyaWRnZS1TaWduaWZ5IE5ldGhlcmxhbmRzIEIuVi4tQWxpY2XigJlzIExpZ2h0LTAwMDAwMDQzLTAwMDAtMTAwMC04MDAwLTAwMjZCQjc2NTI5MQ==",
|
|
342
|
+
"cookie": {
|
|
343
|
+
thermostatModeCOOL: '{"deviceID":"0E:53:9E:7C:32:AC","aid":61,"iid":6,"value":2}',
|
|
344
|
+
TurnOn: '{"deviceID":"0E:53:9E:7C:32:AC","aid":61,"iid":4,"value":1}',
|
|
345
|
+
upperSetpoint: '{"deviceID":"0E:53:9E:7C:32:AC","aid":61,"iid":9}',
|
|
346
|
+
ReportState: '[{"interface":"Alexa.PowerController","deviceID":"0E:53:9E:7C:32:AC","aid":61,"iid":4},{"interface":"Alexa.ThermostatControllerthermostatMode","deviceID":"0E:53:9E:7C:32:AC","aid":61,"iid":6},{"interface":"Alexa.TemperatureSensor","deviceID":"0E:53:9E:7C:32:AC","aid":61,"iid":7},{"interface":"Alexa.ThermostatControllerlowerSetpoint","deviceID":"0E:53:9E:7C:32:AC","aid":61,"iid":8},{"interface":"Alexa.ThermostatControllerupperSetpoint","deviceID":"0E:53:9E:7C:32:AC","aid":61,"iid":9}]',
|
|
347
|
+
thermostatModeOFF: '{"deviceID":"0E:53:9E:7C:32:AC","aid":61,"iid":6,"value":0}',
|
|
348
|
+
lowerSetpoint: '{"deviceID":"0E:53:9E:7C:32:AC","aid":61,"iid":8}',
|
|
349
|
+
thermostatMode: '{"deviceID":"0E:53:9E:7C:32:AC","aid":61,"iid":6}',
|
|
350
|
+
thermostatModeAUTO: '{"deviceID":"0E:53:9E:7C:32:AC","aid":61,"iid":6,"value":3}',
|
|
351
|
+
TurnOff: '{"deviceID":"0E:53:9E:7C:32:AC","aid":61,"iid":4,"value":0}',
|
|
352
|
+
thermostatModeHEAT: '{"deviceID":"0E:53:9E:7C:32:AC","aid":61,"iid":6,"value":1}'
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
payload: {
|
|
356
|
+
targetSetpoint: {
|
|
357
|
+
"value": 20.0,
|
|
358
|
+
"scale": "CELSIUS"
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
268
362
|
};
|