homebridge-alexa 0.6.6 → 0.6.8-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/.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
+ }
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.6.7 (2023-07-07)
6
+
7
+ ## [Version 0.6.7](https://github.com/northernman54/homebridge-alexa/compare/v0.6.6...v0.6.7)
8
+
9
+ #### Changes
10
+
11
+ - Fix for issue #579, AC can't change temperature
12
+
5
13
  ## 0.6.6 (2023-07-07)
6
14
 
7
15
  ## [Version 0.6.6](https://github.com/northernman54/homebridge-alexa/compare/v0.6.5...v0.6.6)
package/Installation.md CHANGED
@@ -2,46 +2,10 @@ Installation and Configuration of Homebridge Alexa
2
2
  ==================================================
3
3
 
4
4
  <!--ts-->
5
- * [Installation and Configuration of Homebridge Alexa](#installation-and-configuration-of-homebridge-alexa)
6
- * [Setup Instructions](#setup-instructions)
7
- * [Create Homebridge-Alexa Cloud Services Account](#create-homebridge-alexa-cloud-services-account)
8
- * [Install and Configure the Plugin](#install-and-configure-the-plugin)
9
- * [Installation in Homebridge UI](#installation-in-homebridge-ui)
10
- * [Configuration in Homebridge UI](#configuration-in-homebridge-ui)
11
- * [Enabling and linking the Homebridge Smart Home Skill](#enabling-and-linking-the-homebridge-smart-home-skill)
12
- * [Viewing Account Status](#viewing-account-status)
13
- * [Advanced Setup Instructions, including advanced configuration options](#advanced-setup-instructions-including-advanced-configuration-options)
14
- * [Prepare Homebridge for plugin installation](#prepare-homebridge-for-plugin-installation)
15
- * [Install Plugin](#install-plugin)
16
- * [Create homebridge-alexa account](#create-homebridge-alexa-account)
17
- * [HomeBridge-alexa plugin configuration](#homebridge-alexa-plugin-configuration)
18
- * [Required Settings](#required-settings)
19
- * [Optional Settings](#optional-settings)
20
- * [debug](#debug)
21
- * [pin](#pin)
22
- * [routines](#routines)
23
- * [deviceList &amp; deviceListHandling - Filtering of devices by name, either allow or allow](#devicelist--devicelisthandling---filtering-of-devices-by-name-either-allow-or-allow)
24
- * [Advanced Settings](#advanced-settings)
25
- * [CloudTransport - Cloud Server Connection Transport](#cloudtransport---cloud-server-connection-transport)
26
- * [keepalive - Cloud Server Connection Keepalive](#keepalive---cloud-server-connection-keepalive)
27
- * [refresh - Accessory Cache Refresh Interval](#refresh---accessory-cache-refresh-interval)
28
- * [filter - Homebridge Instance Filter](#filter---homebridge-instance-filter)
29
- * [mergeServiceName - Alternate device naming](#mergeservicename---alternate-device-naming)
30
- * [blind](#blind)
31
- * [door](#door)
32
- * [Speaker Settings](#speaker-settings)
33
- * [speakers](#speakers)
34
- * [Combine Accessories](#combine-accessories)
35
- * [combine](#combine)
36
- * [Inputs](#inputs)
37
- * [Apple TV](#apple-tv)
38
- * [Yamaha Spotify Controls](#yamaha-spotify-controls)
39
- * [Initial Testing and confirming configuration](#initial-testing-and-confirming-configuration)
40
- * [Enable Homebridge smarthome skill and link accounts](#enable-homebridge-smarthome-skill-and-link-accounts)
41
- * [Discover Devices](#discover-devices)
5
+
42
6
 
43
7
  <!-- Created by https://github.com/ekalinin/github-markdown-toc -->
44
- <!-- Added by: sgracey, at: Fri 7 Jul 2023 10:05:41 EDT -->
8
+ <!-- Added by: sgracey, at: Wed 27 Sep 2023 19:52:25 EDT -->
45
9
 
46
10
  <!--te-->
47
11
 
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
 
@@ -37,54 +37,10 @@ Country availability - The plugin is available in these countries, English (AU),
37
37
 
38
38
  # Table of Contents
39
39
  <!--ts-->
40
- * [Note to users of the service](#note-to-users-of-the-service)
41
- * [New Users](#new-users)
42
- * [Availability](#availability)
43
- * [Features](#features)
44
- * [Table of Contents](#table-of-contents)
45
- * [Supported devices](#supported-devices)
46
- * [HomeKit/Homebridge Devices supported](#homekithomebridge-devices-supported)
47
- * [Native Support](#native-support)
48
- * [Supported as Other Types](#supported-as-other-types)
49
- * [Non-Homebridge Devices](#non-homebridge-devices)
50
- * [Unsupported device types](#unsupported-device-types)
51
- * [Alexa Voice Commands](#alexa-voice-commands)
52
- * [Setup](#setup)
53
- * [Light bulbs / Switches / Dimmer Switches](#light-bulbs--switches--dimmer-switches)
54
- * [Color lights](#color-lights)
55
- * [Color temperature](#color-temperature)
56
- * [Color Temperatures](#color-temperatures)
57
- * [Garage door, Blinds and Window Coverings](#garage-door-blinds-and-window-coverings)
58
- * [Garage Door With door = false](#garage-door-with-door--false)
59
- * [Window coverings / blinds With blind = false](#window-coverings--blinds-with-blind--false)
60
- * [Garage Door With blind = true ( Not supported in all countries )](#garage-door-with-blind--true--not-supported-in-all-countries-)
61
- * [Window coverings / blinds With blind = true ( Not supported in all countries )](#window-coverings--blinds-with-blind--true--not-supported-in-all-countries-)
62
- * [Thermostat's and Heater / Cooler's](#thermostats-and-heater--coolers)
63
- * [Lock / Unlock Doors](#lock--unlock-doors)
64
- * [Temperature sensors](#temperature-sensors)
65
- * [AppleTV ( homebridge-apple-tv or homebridge-apple-tv-remote )](#appletv--homebridge-apple-tv-or-homebridge-apple-tv-remote-)
66
- * [HomeKit Television](#homekit-television)
67
- * [HomeKit Television - Tested plugins](#homekit-television---tested-plugins)
68
- * [Television Inputs and Channels](#television-inputs-and-channels)
69
- * [Speakers](#speakers)
70
- * [Bose SoundLink - Change preset](#bose-soundlink---change-preset)
71
- * [Yamaha Receiver/Spotify control](#yamaha-receiverspotify-control)
72
- * [Contact and Motion Sensors](#contact-and-motion-sensors)
73
- * [Door bell devices](#door-bell-devices)
74
- * [Installation of homebridge-alexa](#installation-of-homebridge-alexa)
75
- * [Service Availability and Issues](#service-availability-and-issues)
76
- * [Homebridge cloud service monitoring ( homebridge.ca )](#homebridge-cloud-service-monitoring--homebridgeca-)
77
- * [Raising Issues and Troubleshooting](#raising-issues-and-troubleshooting)
78
- * [Troubleshooting](#troubleshooting)
79
- * [Known Issues](#known-issues)
80
- * [Discord Channel](#discord-channel)
81
- * [Debug logs](#debug-logs)
82
- * [Homebridge Accessory Dump](#homebridge-accessory-dump)
83
- * [Roadmap](#roadmap)
84
- * [Credits](#credits)
40
+
85
41
 
86
42
  <!-- Created by https://github.com/ekalinin/github-markdown-toc -->
87
- <!-- Added by: sgracey, at: Fri 7 Jul 2023 10:05:40 EDT -->
43
+ <!-- Added by: sgracey, at: Wed 27 Sep 2023 19:52:24 EDT -->
88
44
 
89
45
  <!--te-->
90
46
 
@@ -1,40 +1,10 @@
1
1
  **Troubleshooting Tips**
2
2
 
3
3
  <!--ts-->
4
- * [Initial Setup](#initial-setup)
5
- * [[Alexa] ERROR: ( homebridge-alexa) Login to homebridge.ca failed, please validate your credentials in config.json and restart homebridge.](#alexa-error--homebridge-alexa-login-to-homebridgeca-failed-please-validate-your-credentials-in-configjson-and-restart-homebridge)
6
- * [- Bad login or password in your config.json for <a href="https://www.homebridge.ca" rel="nofollow">https://www.homebridge.ca</a>](#--bad-login-or-password-in-your-configjson-for-httpswwwhomebridgeca)
7
- * [[Alexa] ERROR: ( homebridge-alexa) You have an issue with your installation, please review the README.](#alexa-error--homebridge-alexa-you-have-an-issue-with-your-installation-please-review-the-readme)
8
- * [- Cloud Server DDOS Protection has blocked your IP address](#--cloud-server-ddos-protection-has-blocked-your-ip-address)
9
- * [- Multiple copies of homebridge-alexa on your network](#--multiple-copies-of-homebridge-alexa-on-your-network)
10
- * [- VPN Software interfering with homebridge-alexa to homebridge.ca communications](#--vpn-software-interfering-with-homebridge-alexa-to-homebridgeca-communications)
11
- * [[Alexa] ERROR: ( homebridge-alexa) Stopping Home Skill connection due to excessive reconnects, please review the README.](#alexa-error--homebridge-alexa-stopping-home-skill-connection-due-to-excessive-reconnects-please-review-the-readme)
12
- * [[Alexa] WARNING: Duplicate device name xxxxx](#alexa-warning-duplicate-device-name-xxxxx)
13
- * [Initial Setup Messages from DEBUG mode](#initial-setup-messages-from-debug-mode)
14
- * [alexaHAP HAP Discover failed ... is not running in insecure mode](#alexahap-hap-discover-failed--is-not-running-in-insecure-mode)
15
- * [HAP Discover failed ..... error code 470](#hap-discover-failed--error-code-470)
16
- * [Upgraded from old version and am seeing this error message](#upgraded-from-old-version-and-am-seeing-this-error-message)
17
- * [[Alexa] ERROR: HAP Discovery failed, please review config](#alexa-error-hap-discovery-failed-please-review-config)
18
- * [alexaLocal ERROR: connect ECONNREFUSED 35.169.132.61:1883 -&gt; ECONNREFUSED](#alexalocal-error-connect-econnrefused-35169132611883----econnrefused)
19
- * [alexaLocal error { Error: connect ECONNREFUSED 35.169.132.61:8883](#alexalocal-error--error-connect-econnrefused-35169132618883)
20
- * [Device Discovery](#device-discovery)
21
- * [Device discovery fails and the plugin logs show no issues.](#device-discovery-fails-and-the-plugin-logs-show-no-issues)
22
- * [Device discovery fails, and this message is in the logs ERROR: Empty accessory name, parsing failed.](#device-discovery-fails-and-this-message-is-in-the-logs-error-empty-accessory-name-parsing-failed)
23
- * [Device discovery fails, and this message is in the logs ERROR: Maximum devices/accessories of 300 exceeded.](#device-discovery-fails-and-this-message-is-in-the-logs-error-maximum-devicesaccessories-of-300-exceeded)
24
- * [Device discovery fails, and this message is in the logs ERROR: Parsing failed, duplicate endpointID.](#device-discovery-fails-and-this-message-is-in-the-logs-error-parsing-failed-duplicate-endpointid)
25
- * [After restarting homebridge Alexa can't find devices and needs to discover them again. Or you have duplicate devices in Alexa](#after-restarting-homebridge-alexa-cant-find-devices-and-needs-to-discover-them-again--or-you-have-duplicate-devices-in-alexa)
26
- * [Controlling devices](#controlling-devices)
27
- * [[Alexa] PowerController TurnOff 192.168.1.226 51826 undefined Error: Homebridge auth failed, invalid PIN](#alexa-powercontroller-turnoff-1921681226-51826-undefined-error-homebridge-auth-failed-invalid-pin)
28
- * [Event error messages](#event-error-messages)
29
- * [[Alexa] WARNING: ( homebridge-alexa) Dropped event message, message rate too high.](#alexa-warning--homebridge-alexa-dropped-event-message-message-rate-too-high)
30
- * [ERROR: Error: getAccessToken No data Error: XXXXXXXXXX](#error--error-getaccesstoken-no-data-error-xxxxxxxxxx)
31
- * [ERROR: Error: getAccessToken Token not found](#error--error-getaccesstoken-token-not-found)
32
- * [Unsuccessful event message ( No event gateway token )](#unsuccessful-event-message--no-event-gateway-token-)
33
- * [Successful event message being sent to Alexa](#successful-event-message-being-sent-to-alexa)
34
- * [[Alexa] ERROR: Event gateway token refresh error: 400](#alexa-error--event-gateway-token-refresh-error-400)
4
+
35
5
 
36
6
  <!-- Created by https://github.com/ekalinin/github-markdown-toc -->
37
- <!-- Added by: sgracey, at: Fri 7 Jul 2023 10:05:40 EDT -->
7
+ <!-- Added by: sgracey, at: Wed 27 Sep 2023 19:52:25 EDT -->
38
8
 
39
9
  <!--te-->
40
10
 
@@ -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
- var haAction = JSON.parse(message.directive.endpoint.cookie[index]);
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 missing action", index, e.message, message.directive.endpoint.cookie);
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
- // case "AdjustTargetTemperature":
541
- // Future expansion
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,8 +910,8 @@ function alexaMessage(message, callback) {
866
910
  }
867
911
  });
868
912
  break;
869
- // case "Alexa.ThermostatControllerthermostatMode":
870
- // case "Alexa.ThermostatControllertargetSetpoint":
913
+ // case "Alexa.ThermostatControllerthermostatMode":
914
+ // case "Alexa.ThermostatControllertargetSetpoint":
871
915
  default:
872
916
  statusArray[element.deviceID].body = statusArray[element.deviceID].body + statusArray[element.deviceID].spacer + element.aid + "." + element.iid;
873
917
  statusArray[element.deviceID].interface = statusArray[element.deviceID].interface + statusArray[element.deviceID].spacer + element.interface;
@@ -942,7 +986,7 @@ async function processStatusArray(statusArray, message) {
942
986
  function _HAPstatusByDeviceID(statusObject, message) {
943
987
  debug("_HAPstatusByDeviceID-1", statusObject);
944
988
  return new Promise((resolve, reject) => {
945
- homebridge.HAPstatusByDeviceID(statusObject.deviceID, statusObject.body, function(err, status) {
989
+ homebridge.HAPstatusByDeviceID(statusObject.deviceID, statusObject.body, function (err, status) {
946
990
  if (err) {
947
991
  // debug("Error: _HAPstatusByDeviceID", err);
948
992
  reject(err);
@@ -957,7 +1001,7 @@ function _HAPstatusByDeviceID(statusObject, message) {
957
1001
  function alexaEvent(events) {
958
1002
  debug("Events", JSON.stringify(events));
959
1003
  // create alexa message
960
- events.forEach(function(event) {
1004
+ events.forEach(function (event) {
961
1005
  // debug('alexaEvent - event', event);
962
1006
  var x = {
963
1007
  'deviceID': event.deviceID,
@@ -257,19 +257,19 @@ function alexaResponse(message, hbResponse, err, value) {
257
257
  response = {
258
258
  "context": {
259
259
  "properties": [{
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
- }
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.6",
3
+ "version": "0.6.8-beta.0",
4
4
  "description": "Control your Homebridge devices with Amazon Alexa.",
5
5
  "main": "plugin.js",
6
6
  "scripts": {
@@ -34,7 +34,7 @@
34
34
  "devDependencies": {
35
35
  "@oznu/hap-client": "^1.8.1",
36
36
  "documentation": "^14.0.1",
37
- "nodemon": "^2.0.4"
37
+ "nodemon": "^3.0.1"
38
38
  },
39
39
  "dependencies": {
40
40
  "bottleneck": "^2.19.5",