homebridge-alexa 0.5.53 → 0.5.59

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/CHANGELOG.md CHANGED
@@ -2,15 +2,16 @@
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.5.52 (2021-12-28)
5
+ ## 0.5.54 (2021-01-03)
6
6
 
7
- ## [Version 0.5.51](https://github.com/northernman54/homebridge-alexa/compare/v0.5.37...v0.5.52)
7
+ ## [Version 0.5.54](https://github.com/northernman54/homebridge-alexa/compare/v0.5.52...v0.5.54)
8
8
 
9
9
  #### Changes
10
10
 
11
- - Workaround for issue #481
12
- - Cloud service connection tuning
13
- - Jump version numbers
11
+ - Merge current beta into master
12
+ - Expose cloud connection keep alive tuning parameter #479
13
+ - Extend filtering to routines event registration - Resolve #458 #459 #461 #465
14
+ - Reduce amount of logging
14
15
 
15
16
  ## 0.5.37 (2021-06-15)
16
17
 
@@ -58,6 +58,20 @@
58
58
  "placeholder": "900",
59
59
  "description": "Frequency of refreshes of the homebridge accessory cache, in seconds. Defaults to 15 minutes."
60
60
  },
61
+ "keepalive": {
62
+ "title": "Cloud Server Connection Keepalive",
63
+ "type": "integer",
64
+ "placeholder": "20",
65
+ "description": "Frequency of keepalive messages to cloud server, in minutes. Defaults to 20 minutes. Do not change from default unless requested as part of problem investigation.",
66
+ "minimum": 1,
67
+ "maximum": 59
68
+ },
69
+ "LegacyCloudTransport": {
70
+ "title": "Legacy Cloud Server Connection",
71
+ "type": "boolean",
72
+ "default": false,
73
+ "description": "Enable Legacy Transport ( mqtt ) to Cloud Servers ( This is from version 0.5.55 or older )."
74
+ },
61
75
  "filter": {
62
76
  "title": "Instance Filter",
63
77
  "type": "string",
@@ -65,14 +79,12 @@
65
79
  "description": "Limits accessories shared with Alexa to a single homebridge instance.",
66
80
  "pattern": "^[^{}/ :\\\\]+(?::\\d+)?$"
67
81
  },
68
-
69
82
  "deviceListHandling": {
70
83
  "title": "How to handle devices in the deviceList",
71
84
  "type": "string",
72
85
  "required": true,
73
86
  "default": "allow",
74
- "oneOf": [
75
- {
87
+ "oneOf": [{
76
88
  "title": "Allow devices",
77
89
  "enum": [
78
90
  "allow"
@@ -169,40 +181,45 @@
169
181
  }
170
182
  ]
171
183
  },
184
+ {
185
+ "type": "fieldset",
186
+ "title": "Advanced Settings",
187
+ "expandable": true,
188
+ "expanded": false,
189
+ "items": [
190
+ "keepalive",
191
+ "LegacyCloudTransport"
192
+ ]
193
+ },
172
194
  {
173
195
  "type": "fieldset",
174
196
  "title": "Speakers",
175
197
  "description": "Devices to configure as speakers as HomeKit currently does not have a Speaker service.",
176
198
  "expandable": true,
177
199
  "expanded": false,
178
- "items": [
179
- {
180
- "notitle": true,
181
- "key": "speakers",
182
- "type": "array",
183
- "items": [
200
+ "items": [{
201
+ "notitle": true,
202
+ "key": "speakers",
203
+ "type": "array",
204
+ "items": [{
205
+ "type": "div",
206
+ "displayFlex": true,
207
+ "flex-direction": "row",
208
+ "items": [{
209
+ "key": "speakers[].manufacturer",
210
+ "flex": "1 1 50px",
211
+ "notitle": true,
212
+ "placeholder": "Manufacturer"
213
+ },
184
214
  {
185
- "type": "div",
186
- "displayFlex": true,
187
- "flex-direction": "row",
188
- "items": [
189
- {
190
- "key": "speakers[].manufacturer",
191
- "flex": "1 1 50px",
192
- "notitle": true,
193
- "placeholder": "Manufacturer"
194
- },
195
- {
196
- "key": "speakers[].name",
197
- "flex": "4 4 200px",
198
- "notitle": true,
199
- "placeholder": "Name"
200
- }
201
- ]
215
+ "key": "speakers[].name",
216
+ "flex": "4 4 200px",
217
+ "notitle": true,
218
+ "placeholder": "Name"
202
219
  }
203
220
  ]
204
- }
205
- ]
221
+ }]
222
+ }]
206
223
  },
207
224
  {
208
225
  "type": "fieldset",
@@ -210,37 +227,30 @@
210
227
  "description": "Combine disparate accessories into one common device.",
211
228
  "expandable": true,
212
229
  "expanded": false,
213
- "items": [
214
- {
215
- "notitle": true,
216
- "key": "combine",
217
- "type": "array",
218
- "items": [
230
+ "items": [{
231
+ "notitle": true,
232
+ "key": "combine",
233
+ "type": "array",
234
+ "items": [{
235
+ "type": "div",
236
+ "items": [{
237
+ "key": "combine[].into",
238
+ "title": "Into",
239
+ "placeholder": "Target Accessory Name"
240
+ },
219
241
  {
220
- "type": "div",
221
- "items": [
222
- {
223
- "key": "combine[].into",
224
- "title": "Into",
225
- "placeholder": "Target Accessory Name"
226
- },
227
- {
228
- "key": "combine[].from",
229
- "notitle": true,
230
- "items": [
231
- {
232
- "title": "From",
233
- "key": "combine[].from[]",
242
+ "key": "combine[].from",
243
+ "notitle": true,
244
+ "items": [{
245
+ "title": "From",
246
+ "key": "combine[].from[]",
234
247
 
235
- "placeholder": "Source Accessory Name"
236
- }
237
- ]
238
- }
239
- ]
248
+ "placeholder": "Source Accessory Name"
249
+ }]
240
250
  }
241
251
  ]
242
- }
243
- ]
252
+ }]
253
+ }]
244
254
  }
245
255
  ]
246
256
  }
@@ -36,9 +36,7 @@ function hapDiscovery(options) {
36
36
  alexaDiscovery.call(options, null, function() {
37
37
  // debug("Events", options);
38
38
  if (options.events) {
39
-
40
- registerEvents(hbDevices.toEvents());
41
-
39
+ registerEvents.call(options, messages.checkEventDeviceList.call(options, hbDevices.toEvents()));
42
40
  }
43
41
  });
44
42
  });
@@ -51,12 +49,11 @@ function hapDiscovery(options) {
51
49
  }
52
50
 
53
51
  function registerEvents(message) {
54
- debug("registerEvents", message);
52
+ // debug("registerEvents", message);
55
53
 
56
54
  var HBMessage = [];
57
55
 
58
56
  for (var key in message) {
59
- // console.log("Key", key, JSON.parse(key));
60
57
  var endpoint = JSON.parse(key);
61
58
  var device = {
62
59
  "aid": endpoint.aid,
@@ -76,10 +73,12 @@ function registerEvents(message) {
76
73
  };
77
74
  }
78
75
  }
76
+
77
+ this.log("registerEvents - registered %s event sources", Object.keys(HBMessage).length);
79
78
  for (var register in HBMessage) {
80
79
  // console.log("send", instance, HBMessage[instance]);
81
80
  var hbInstance = JSON.parse(register);
82
- debug("Event Register %s ->", hbInstance.deviceID, HBMessage[register]);
81
+ // debug("Event Register %s ->", hbInstance.deviceID, HBMessage[register]);
83
82
  homebridge.HAPeventByDeviceID(hbInstance.deviceID, JSON.stringify(HBMessage[register]), function(err, status) {
84
83
  if (!err) {
85
84
  // debug("Registered Event %s:%s ->", hbInstance.host, hbInstance.port, status);
@@ -111,7 +110,7 @@ function alexaDiscovery(message, callback) {
111
110
  for (var i = 0; i < response.event.payload.endpoints.length; i++) {
112
111
  var endpoint = response.event.payload.endpoints[i];
113
112
  if (deleteSeen[endpoint.friendlyName]) {
114
- this.log("WARNING: Duplicate device name", endpoint.friendlyName);
113
+ this.log.warn("WARNING: Duplicate device name", endpoint.friendlyName);
115
114
  // response.event.payload.endpoints.splice(i, 1);
116
115
  } else {
117
116
  deleteSeen[endpoint.friendlyName] = true;
@@ -119,7 +118,7 @@ function alexaDiscovery(message, callback) {
119
118
  }
120
119
 
121
120
  if (response && response.event.payload.endpoints.length < 1) {
122
- this.log("ERROR: HAP Discovery failed, please review config");
121
+ this.log.error("ERROR: HAP Discovery failed, please review config");
123
122
  } else {
124
123
  if (process.uptime() > 600) { // Only use console during startup
125
124
  debug("alexaDiscovery - returned %s devices", response.event.payload.endpoints.length);
@@ -127,7 +126,7 @@ function alexaDiscovery(message, callback) {
127
126
  this.log("alexaDiscovery - returned %s devices", response.event.payload.endpoints.length);
128
127
  }
129
128
  if (response.event.payload.endpoints.length > 300) {
130
- this.log("ERROR: Maximum devices/accessories of 300 exceeded.");
129
+ this.log.error("ERROR: Maximum devices/accessories of 300 exceeded.");
131
130
  }
132
131
  }
133
132
  // debug("Discovery Response", JSON.stringify(response, null, 2));
@@ -144,7 +143,7 @@ function alexaDiscovery(message, callback) {
144
143
  function removeLargeCookieEndpoints(endpoints) {
145
144
  var response = [];
146
145
  endpoints.forEach((endpoint) => {
147
- debug("Cookie Object: ", JSON.stringify(endpoint.cookie).length);
146
+ // debug("Cookie Object: ", JSON.stringify(endpoint.cookie).length);
148
147
  if (JSON.stringify(endpoint.cookie).length < 5000) {
149
148
  response.push(endpoint);
150
149
  } else {
@@ -162,7 +161,7 @@ function removeDuplicateEndpoints(endpoints) {
162
161
  var response = [];
163
162
  endpoints.forEach((endpoint) => {
164
163
  if (deleteSeen[endpoint.endpointId]) {
165
- this.log("ERROR: Parsing failed, removing duplicate endpointID =>", endpoint.friendlyName);
164
+ this.log.error("ERROR: Parsing failed, removing duplicate endpointID =>", endpoint.friendlyName);
166
165
  } else {
167
166
  response.push(endpoint);
168
167
  }
package/lib/alexaLocal.js CHANGED
@@ -16,7 +16,6 @@ var checkAlexaMessage = Validator(alexaSchema, {
16
16
  verbose: true
17
17
  });
18
18
 
19
- var connection = {};
20
19
  var count = 0;
21
20
  var username;
22
21
  var limiter;
@@ -45,24 +44,28 @@ function alexaLocal(options) {
45
44
  }
46
45
 
47
46
  limiter.on("dropped", function(dropped) {
48
- options.log("WARNING: ( homebridge-alexa) Dropped event message, message rate too high.");
47
+ options.log.warn("WARNING: ( homebridge-alexa) Dropped event message, message rate too high.");
49
48
  });
50
49
 
51
- username = options.username;
52
- connection.client = mqtt.connect(options);
53
- // connection.client.setMaxListeners(0);
54
- connection.client.on('connect', function() {
55
- debug('connect', "command/" + options.username + "/#");
50
+ username = options.mqttOptions.username;
51
+ var connection = mqtt.connect(options.mqttURL, options.mqttOptions);
52
+ connection.on('connect', function() {
53
+ debug('connect', "command/" + username + "/#");
56
54
  if (options.alexaService) {
57
55
  options.alexaService.setCharacteristic(Characteristic.ContactSensorState, Characteristic.ContactSensorState.CONTACT_DETECTED);
58
56
  }
59
- connection.client.removeAllListeners('message'); // Clean up event handlers
60
- connection.client.subscribe("command/" + options.username + "/#");
61
- connection.client.publish("presence/" + options.username + "/1", JSON.stringify({
57
+ connection.subscribe("command/" + username + "/#");
58
+ connection.publish("presence/" + username + "/1", JSON.stringify({
62
59
  Connected: options.username,
63
- version: packageConfig.version
60
+ version: packageConfig.version,
61
+ transport: options.transport,
62
+ keepalive: options.mqttOptions.keepalive,
63
+ routines: options.events
64
64
  }));
65
- connection.client.on('message', function(topic, message) {
65
+ });
66
+
67
+ connection.on('message', function(topic, message) {
68
+ try {
66
69
  var msg = JSON.parse(message.toString());
67
70
 
68
71
  // debug("Count", this.listenerCount(msg.directive.header.namespace.toLowerCase()));
@@ -74,55 +77,63 @@ function alexaLocal(options) {
74
77
  response = _alexaErrorResponse(msg);
75
78
  }
76
79
  // debug("Response", JSON.stringify(response));
77
- connection.client.publish("response/" + options.username + "/1", JSON.stringify(response));
80
+ connection.publish("response/" + username + "/1", JSON.stringify(response));
78
81
  });
79
82
  } else {
80
- debug('No listener for', msg.directive.header.namespace.toLowerCase());
83
+ debug('ERROR: No alexa action listener for', msg);
81
84
  var response = _alexaErrorResponse(msg);
82
- connection.client.publish("response/" + options.username + "/1", JSON.stringify(response));
83
- debug("Response", JSON.stringify(response, null, 2));
85
+ connection.publish("response/" + username + "/1", JSON.stringify(response));
86
+ // debug("Response", JSON.stringify(response, null, 2));
84
87
  }
85
- });
88
+ } catch (err) {
89
+ options.log.error("ERROR: MQTT Message on topic \"%s\" triggered an internal error\n", topic, err);
90
+ }
86
91
  });
87
92
 
88
- connection.client.on('offline', function() {
93
+ connection.on('offline', function() {
89
94
  debug('offline');
90
95
  if (options.alexaService) {
91
96
  options.alexaService.setCharacteristic(Characteristic.ContactSensorState, Characteristic.ContactSensorState.CONTACT_NOT_DETECTED);
92
97
  }
93
98
  });
94
99
 
95
- connection.client.on('reconnect', function() {
100
+ connection.on('reconnect', function() {
96
101
  count++;
97
102
  debug('reconnect');
98
103
  if (options.alexaService) {
99
104
  options.alexaService.setCharacteristic(Characteristic.ContactSensorState, Characteristic.ContactSensorState.CONTACT_NOT_DETECTED);
100
105
  }
101
- if (count % 5 === 0) options.log("ERROR: ( homebridge-alexa) You have an issue with your installation, please review the README.");
106
+ if (count % 5 === 0) options.log.error("ERROR: ( homebridge-alexa) You have an issue with your installation, please review the README.");
102
107
  if (count > 1000) {
103
- connection.client.end({
108
+ connection.end({
104
109
  force: true
105
110
  });
106
111
  if (options.alexaService) {
107
112
  options.alexaService.setCharacteristic(Characteristic.ContactSensorState, Characteristic.ContactSensorState.CONTACT_NOT_DETECTED);
108
113
  }
109
- options.log("ERROR: ( homebridge-alexa) Stopping Home Skill connection due to excessive reconnects, please review the README.");
114
+ options.log.error("ERROR: ( homebridge-alexa) Stopping Home Skill connection due to excessive reconnects, please review the README.");
110
115
  }
111
116
  });
112
117
 
113
- connection.client.on('error', function(err) {
118
+ connection.on('error', function(err) {
114
119
  if (options.alexaService) {
115
120
  options.alexaService.setCharacteristic(Characteristic.ContactSensorState, Characteristic.ContactSensorState.CONTACT_NOT_DETECTED);
116
121
  }
122
+ debug('ERROR: %s -> %s\n', err.message, err.code, err);
117
123
  switch (err.code) {
118
124
  case 5:
119
- options.log("ERROR: ( homebridge-alexa) Login to homebridge.ca failed, please validate your credentials in config.json and restart homebridge.");
120
- connection.client.end({
121
- force: true
122
- });
125
+ if (process.uptime() < 20) { // If uptime is less than 20 seconds then error is a bad password and not a backend issue
126
+ options.log.error("ERROR: ( homebridge-alexa) Login to homebridge.ca failed, please validate your credentials in config.json and restart homebridge.");
127
+ connection.end({
128
+ force: true
129
+ });
130
+ }
131
+ break;
132
+ case 'ECONNREFUSED':
133
+ options.log.error("ERROR: Cloud service DDOS Protection tripped, please stop homebridge for 5 to 10 minutes and try again.");
123
134
  break;
124
135
  default:
125
- debug('ERROR: %s -> ', err.message, err.code);
136
+ debug('ERROR: %s -> %d\n', err.message, err.code, err);
126
137
  }
127
138
  });
128
139
  }
@@ -139,7 +150,7 @@ function alexaEvent(message) {
139
150
  var topic = "event/" + username + "/1";
140
151
  var publish = function(callback) {
141
152
  debug("Sending message", JSON.stringify(message));
142
- connection.client.publish(topic, JSON.stringify(message), {
153
+ connection.publish(topic, JSON.stringify(message), {
143
154
  retain: false
144
155
  }, callback);
145
156
  };
@@ -151,16 +162,18 @@ function alexaPriorityEvent(message) {
151
162
  var topic = "event/" + username + "/1";
152
163
  var publish = function(callback) {
153
164
  debug("Sending priority message", JSON.stringify(message));
154
- connection.client.publish(topic, JSON.stringify(message), {
165
+ connection.publish(topic, JSON.stringify(message), {
155
166
  retain: false
156
167
  }, callback);
157
168
  };
158
- limiter.submit({ priority: 4 }, publish);
169
+ limiter.submit({
170
+ priority: 4
171
+ }, publish);
159
172
 
160
173
  /*
161
174
  var topic = "event/" + username + "/1";
162
175
  debug("Sending priority message", JSON.stringify(message));
163
- connection.client.publish(topic, JSON.stringify(message));
176
+ connection.publish(topic, JSON.stringify(message));
164
177
  */
165
178
  }
166
179
 
@@ -116,6 +116,8 @@ Accessory.prototype.toAlexa = function(context) {
116
116
  var service = this.services[index];
117
117
  if ((this.television && service.service === "Speaker") || service.service === "Television" || service.service === "Input Source") {
118
118
  // Skip television accessories
119
+ } else if (service.name === "Alexa" && service.service === "Contact Sensor" && service.info.Manufacturer === "homebridge-alexa") {
120
+ // Skip the Alexa contact sensors made by the plugin
119
121
  } else {
120
122
  var alexa = service.toAlexa(context);
121
123
  if (alexa) {
@@ -52,6 +52,7 @@ function _getActions(description, context, devices) {
52
52
  var cookie = {};
53
53
  var reportState = [];
54
54
  var hapEvents = [];
55
+ // debug("_getActions", description, devices);
55
56
  switch (description) {
56
57
  case "Active": // Active on a Fan 2 aka Dyson or Valve
57
58
  case "On": // Accessory On/Off
@@ -92,6 +93,7 @@ function _getActions(description, context, devices) {
92
93
  "iid": context.liid
93
94
  })] = {
94
95
  "endpointID": context.endpointID,
96
+ "friendlyName": context.name,
95
97
  "true": "DETECTED",
96
98
  "false": "NOT_DETECTED",
97
99
  "1": "DETECTED",
@@ -118,6 +120,7 @@ function _getActions(description, context, devices) {
118
120
  "iid": context.liid
119
121
  })] = {
120
122
  "endpointID": context.endpointID,
123
+ "friendlyName": context.name,
121
124
  "0": "DETECTED", // Aka open for Alexa
122
125
  "1": "NOT_DETECTED",
123
126
  // "2": "DETECTED",
@@ -157,6 +160,7 @@ function _getActions(description, context, devices) {
157
160
  "iid": context.liid
158
161
  })] = {
159
162
  "endpointID": context.endpointID,
163
+ "friendlyName": context.name,
160
164
  "1": "DETECTED", // Aka open for Alexa
161
165
  "0": "NOT_DETECTED",
162
166
  "template": "ContactSensor"
@@ -172,6 +176,7 @@ function _getActions(description, context, devices) {
172
176
  "iid": context.liid
173
177
  })] = {
174
178
  "endpointID": context.endpointID,
179
+ "friendlyName": context.name,
175
180
  "0": "DETECTED", // Aka open for Alexa
176
181
  "1": "NOT_DETECTED",
177
182
  "template": "DoorbellEventSource"
@@ -253,6 +258,7 @@ function _getActions(description, context, devices) {
253
258
  cookie["targetSetpoint"] = messages.cookie(context);
254
259
  }
255
260
  break;
261
+ case "Target Heater-Cooler State":
256
262
  case "Target Heater Cooler State":
257
263
  case "Target Heating Cooling State":
258
264
  reportState.push(messages.reportState("Alexa.ThermostatControllerthermostatMode", context));
@@ -91,12 +91,16 @@ Homebridges.prototype.toEvents = function(endpoint) {
91
91
  for (var index in accessory.services) {
92
92
  var service = accessory.services[index];
93
93
  // debug("characteristics", service.characteristics.length);
94
- for (var index in service.characteristics) {
95
- var hapEvents = service.characteristics[index].hapEvents;
96
- if (Object.keys(hapEvents).length > 0) {
97
- list = Object.assign(list, hapEvents);
98
- // debug("hapEvents", hapEvents, Object.keys(hapEvents).length);
99
- // debug("List", list);
94
+ if (service.name === "Alexa" && service.service === "Contact Sensor" && service.info.Manufacturer === "homebridge-alexa") {
95
+ // Skip the Alexa contact sensors made by the plugin
96
+ } else {
97
+ for (var index in service.characteristics) {
98
+ var hapEvents = service.characteristics[index].hapEvents;
99
+ if (Object.keys(hapEvents).length > 0) {
100
+ list = Object.assign(list, hapEvents);
101
+ // debug("hapEvents", hapEvents, Object.keys(hapEvents).length);
102
+ // debug("List", list);
103
+ }
100
104
  }
101
105
  }
102
106
  }
@@ -35,6 +35,7 @@ function Service(devices, context) {
35
35
  this.info = context.info;
36
36
  this.characteristics = [];
37
37
  this.linked = devices.linked;
38
+ this.name = context.name;
38
39
  var endpointReg = /[^\w|_|-|=|#|;|:|?|@|&]/g; // Invalid characters in endpointid
39
40
  this.endpointID = Buffer.from(this.id + "-" + context.homebridge + "-" + context.info.Manufacturer + "-" + context.info.Name + "-" + this.serviceType).toString('base64').replace(endpointReg, '#');
40
41
  // this.endpointID = new Buffer(this.id + "-" + context.homebridge + "-" + context.info.Manufacturer + "-" + context.info.Name + "-" + this.serviceType).toString('base64');
@@ -19,7 +19,8 @@ module.exports = {
19
19
  round: round,
20
20
  combine: combine,
21
21
  channel: channel,
22
- inputs: inputs
22
+ inputs: inputs,
23
+ checkEventDeviceList: checkEventDeviceList
23
24
  };
24
25
 
25
26
  function createMessageId() {
@@ -1414,3 +1415,37 @@ function _getThermoMode(mode) {
1414
1415
  return "AUTO";
1415
1416
  }
1416
1417
  }
1418
+
1419
+
1420
+ function checkEventDeviceList(endpoints) {
1421
+ if (this.deviceList && this.deviceList.length > 0 && ['allow', 'deny'].includes(this.deviceListHandling)) {
1422
+ debug(`INFO: DeviceList - The following devices are ${this.deviceListHandling} =>`, this.deviceList);
1423
+ var response = [];
1424
+ for (var key in endpoints) {
1425
+ var endpoint = endpoints[key];
1426
+ if (this.deviceListHandling === "allow") {
1427
+ if (verifyDeviceInList(this.deviceList, endpoint.friendlyName)) {
1428
+ response[key] = endpoint;
1429
+ debug("INFO: DeviceList - allow =>", endpoint.friendlyName);
1430
+ }
1431
+ } else if (this.deviceListHandling === "deny") {
1432
+ if (verifyDeviceInList(this.deviceList, endpoint.friendlyName)) {
1433
+ debug("INFO: DeviceList - deny =>", endpoint.friendlyName);
1434
+ } else {
1435
+ response[key] = endpoint;
1436
+ }
1437
+ }
1438
+ }
1439
+ return (response);
1440
+ } else {
1441
+ debug("INFO: DeviceList empty feature not enabled or config error in deviceListHandling");
1442
+ return endpoints;
1443
+ }
1444
+ }
1445
+
1446
+ function verifyDeviceInList(deviceList, deviceName) {
1447
+ for (var i = 0, len = deviceList.length; i < len; i++) {
1448
+ if (deviceName === deviceList[i] || deviceName.match(new RegExp(deviceList[i]))) return true;
1449
+ }
1450
+ return false;
1451
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-alexa",
3
- "version": "0.5.53",
3
+ "version": "0.5.59",
4
4
  "description": "Control your Homebridge devices with Amazon Alexa.",
5
5
  "main": "plugin.js",
6
6
  "scripts": {
@@ -41,7 +41,7 @@
41
41
  "debug": ">=4.3.3",
42
42
  "hap-node-client": ">=0.1.16",
43
43
  "is-my-json-valid": ">=2.20.6",
44
- "mqtt": "4.2.7"
44
+ "mqtt": "^4.3.4"
45
45
  },
46
46
  "author": "NorthernMan54",
47
47
  "license": "Apache-2.0",
package/plugin.js CHANGED
@@ -40,6 +40,14 @@ function alexaHome(log, config, api) {
40
40
  this.deviceList = config['deviceList'] || []; // Use ea
41
41
  this.door = config['door'] || false; // Use mode controller for Garage Doors
42
42
  this.name = config['name'] || "homebridgeAlexa";
43
+ this.LegacyCloudTransport = config['LegacyCloudTransport'] || false; // Default to new Transport
44
+ var mqttKeepalive = config['keepalive'] || 20; // MQTT Connection Keepalive
45
+
46
+ if (mqttKeepalive < 60) {
47
+ this.keepalive = mqttKeepalive * 60;
48
+ } else {
49
+ this.keepalive = mqttKeepalive;
50
+ }
43
51
 
44
52
  // Enable config based DEBUG logging enable
45
53
  this.debug = config['debug'] || false;
@@ -86,24 +94,26 @@ alexaHome.prototype = {
86
94
  };
87
95
 
88
96
  alexaHome.prototype.didFinishLaunching = function() {
89
- var host = 'alexa.homebridge.ca';
97
+ var host = (this.LegacyCloudTransport ? 'alexa.homebridge.ca' : 'www.homebridge.ca');
98
+ var reconnectPeriod = 65000; // Increased reconnect period to allow DDOS protection to reset
90
99
  if (this.beta) {
91
- host = 'alexabeta.homebridge.ca';
100
+ host = 'clone.homebridge.ca';
101
+ // reconnectPeriod = 10000;
92
102
  }
103
+
93
104
  options = {
94
105
  // Shared Options
95
106
  log: this.log,
96
107
  debug: this.debug,
97
- // MQTT Options
98
- username: this.username,
99
- password: this.password,
100
- servers: [{
101
- protocol: 'mqtt',
102
- host: host,
103
- port: 1883
104
- }],
105
- reconnectPeriod: 65000,
106
- keepalive: 1200, // Reduce client timeout to 20 minutes
108
+ mqttURL: (this.LegacyCloudTransport ? "mqtt://" + host + ":1883/" : "wss://" + host + "/ws"),
109
+ transport: (this.LegacyCloudTransport ? "mqtt" : "wss"),
110
+ mqttOptions: {
111
+ username: this.username,
112
+ password: this.password,
113
+ reconnectPeriod: reconnectPeriod, // Increased reconnect period to allow DDOS protection to reset
114
+ keepalive: (this.LegacyCloudTransport ? this.keepalive : 55), // Keep alive not required when using WSS Transport
115
+ rejectUnauthorized: false
116
+ },
107
117
  // HAP Node Client options
108
118
  pin: this.pin,
109
119
  refresh: this.refresh,
@@ -137,7 +147,13 @@ alexaHome.prototype.didFinishLaunching = function() {
137
147
  // Alexa mesages
138
148
 
139
149
  this.eventBus.on('System', function(message) {
140
- this.log.error("ERROR: ", message.directive.header.message);
150
+ this.log.error("ERROR:", message.directive.header.message);
151
+ }.bind(this));
152
+ this.eventBus.on('Warning', function(message) {
153
+ this.log.warn("Warning:", message.directive.header.message);
154
+ }.bind(this));
155
+ this.eventBus.on('Information', function(message) {
156
+ this.log("Info:", message.directive.header.message);
141
157
  }.bind(this));
142
158
  this.eventBus.on('Alexa', alexaActions.alexaMessage.bind(this));
143
159
  this.eventBus.on('Alexa.Discovery', alexaActions.alexaDiscovery.bind(this));