homebridge-alexa 0.5.48
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/dependabot.yml +12 -0
- package/CHANGELOG.md +99 -0
- package/README.md +883 -0
- package/Roadmap.md +42 -0
- package/Troubleshooting.md +216 -0
- package/V1_README.md +63 -0
- package/alexaDiscovery.json +3938 -0
- package/config.schema.json +261 -0
- package/lib/alexaActions.js +1004 -0
- package/lib/alexaLocal.js +183 -0
- package/lib/alexaMessages.js +705 -0
- package/lib/alexa_smart_home_message_schema.json +5129 -0
- package/lib/parse/Accessory.js +189 -0
- package/lib/parse/Characteristic.js +324 -0
- package/lib/parse/Homebridge.js +225 -0
- package/lib/parse/Homebridges.js +130 -0
- package/lib/parse/Service.js +290 -0
- package/lib/parse/messages.js +1452 -0
- package/package.json +52 -0
- package/plugin.js +189 -0
|
@@ -0,0 +1,1452 @@
|
|
|
1
|
+
var debug = require('debug')('alexa:Messages');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
lookupCapabilities: lookupCapabilities, // Dup
|
|
5
|
+
normalizeName: normalizeName,
|
|
6
|
+
lookupDisplayCategory: lookupDisplayCategory, // Dup
|
|
7
|
+
reportState: reportState,
|
|
8
|
+
cookie: cookie,
|
|
9
|
+
cookieV: cookieV,
|
|
10
|
+
isAppleTV: isAppleTV,
|
|
11
|
+
isYamaha: isYamaha,
|
|
12
|
+
atvButton: atvButton,
|
|
13
|
+
playbackNameTranslate: playbackNameTranslate,
|
|
14
|
+
mergeCookies: mergeCookies,
|
|
15
|
+
mergeInputCookies: mergeInputCookies,
|
|
16
|
+
mergeCapabilities: mergeCapabilities,
|
|
17
|
+
stateToProperties: stateToProperties,
|
|
18
|
+
createMessageId: createMessageId,
|
|
19
|
+
round: round,
|
|
20
|
+
combine: combine,
|
|
21
|
+
channel: channel,
|
|
22
|
+
inputs: inputs,
|
|
23
|
+
checkEventDeviceList: checkEventDeviceList
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function createMessageId() {
|
|
27
|
+
var d = new Date().getTime();
|
|
28
|
+
|
|
29
|
+
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
|
|
30
|
+
function(c) {
|
|
31
|
+
var r = (d + Math.random() * 16) % 16 | 0;
|
|
32
|
+
d = Math.floor(d / 16);
|
|
33
|
+
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return uuid;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* statusObject {
|
|
40
|
+
body: '?id=101.10,101.11',
|
|
41
|
+
interface: 'Alexa.PowerController,Alexa.PowerLevelController',
|
|
42
|
+
deviceID: 'CC:22:3D:E3:CE:30',
|
|
43
|
+
spacer: ',',
|
|
44
|
+
elements: [{ interface: Alexa.PowerController, aid: 101, iid: 10}, {interface: Alexa.PowerLevelController, aid: 101, iid: 11}]
|
|
45
|
+
}
|
|
46
|
+
hbResponse [
|
|
47
|
+
{ aid: 101, iid: 11, value: 100 },
|
|
48
|
+
{ aid: 101, iid: 10, value: false }
|
|
49
|
+
]
|
|
50
|
+
*/
|
|
51
|
+
function stateToProperties(statusObject, hbResponse) {
|
|
52
|
+
var properties = [];
|
|
53
|
+
var now = new Date();
|
|
54
|
+
// debug("stateToProperties - hbResponse", hbResponse);
|
|
55
|
+
// Convert each individual HAP hbResponse to Alexa Format
|
|
56
|
+
statusObject.elements.forEach((element, i) => {
|
|
57
|
+
// debug("stateToProperties - element", element, i, hbResponse[i]);
|
|
58
|
+
switch (element.interface.toLowerCase()) {
|
|
59
|
+
case "alexa.speaker":
|
|
60
|
+
properties.push({
|
|
61
|
+
"namespace": "Alexa.Speaker",
|
|
62
|
+
"name": "volume",
|
|
63
|
+
"value": round(_getValue(element, hbResponse, i).value),
|
|
64
|
+
"timeOfSample": now.toISOString(),
|
|
65
|
+
"uncertaintyInMilliseconds": 500
|
|
66
|
+
});
|
|
67
|
+
properties.push({
|
|
68
|
+
"namespace": "Alexa.Speaker",
|
|
69
|
+
"name": "muted",
|
|
70
|
+
"value": false,
|
|
71
|
+
"timeOfSample": now.toISOString(),
|
|
72
|
+
"uncertaintyInMilliseconds": 500
|
|
73
|
+
});
|
|
74
|
+
break;
|
|
75
|
+
case "alexa.stepspeaker":
|
|
76
|
+
// No response needed
|
|
77
|
+
break;
|
|
78
|
+
case "alexa.powercontroller":
|
|
79
|
+
properties.push({
|
|
80
|
+
"namespace": "Alexa.PowerController",
|
|
81
|
+
"name": "powerState",
|
|
82
|
+
"value": _getValue(element, hbResponse, i).value ? "ON" : "OFF",
|
|
83
|
+
"timeOfSample": now.toISOString(),
|
|
84
|
+
"uncertaintyInMilliseconds": 500
|
|
85
|
+
});
|
|
86
|
+
break;
|
|
87
|
+
case "alexa.powerlevelcontroller":
|
|
88
|
+
properties.push({
|
|
89
|
+
"namespace": "Alexa.PowerLevelController",
|
|
90
|
+
"name": "powerLevel",
|
|
91
|
+
"value": round(_getValue(element, hbResponse, i).value),
|
|
92
|
+
"timeOfSample": now.toISOString(),
|
|
93
|
+
"uncertaintyInMilliseconds": 500
|
|
94
|
+
});
|
|
95
|
+
break;
|
|
96
|
+
case "alexa.rangecontroller":
|
|
97
|
+
properties.push({
|
|
98
|
+
"namespace": "Alexa.RangeController",
|
|
99
|
+
"name": "rangeValue",
|
|
100
|
+
"value": round(_getValue(element, hbResponse, i).value),
|
|
101
|
+
"timeOfSample": now.toISOString(),
|
|
102
|
+
"uncertaintyInMilliseconds": 500
|
|
103
|
+
});
|
|
104
|
+
break;
|
|
105
|
+
case "alexa.modecontroller":
|
|
106
|
+
properties.push({
|
|
107
|
+
"namespace": "Alexa.ModeController",
|
|
108
|
+
"instance": "GarageDoor.Position",
|
|
109
|
+
"name": "mode",
|
|
110
|
+
"value": _getValue(element, hbResponse, i).value ? "Position.Down" : "Position.Up",
|
|
111
|
+
"timeOfSample": now.toISOString(),
|
|
112
|
+
"uncertaintyInMilliseconds": 500
|
|
113
|
+
});
|
|
114
|
+
break;
|
|
115
|
+
case "alexa.colortemperaturecontroller":
|
|
116
|
+
properties.push({
|
|
117
|
+
"namespace": "Alexa.ColorTemperatureController",
|
|
118
|
+
"name": "colorTemperatureInKelvin",
|
|
119
|
+
"value": round(1000000 / _getValue(element, hbResponse, i).value),
|
|
120
|
+
"timeOfSample": now.toISOString(),
|
|
121
|
+
"uncertaintyInMilliseconds": 500
|
|
122
|
+
});
|
|
123
|
+
break;
|
|
124
|
+
case "alexa.colorcontroller":
|
|
125
|
+
properties.push({
|
|
126
|
+
"namespace": "Alexa.ColorController",
|
|
127
|
+
"name": "color",
|
|
128
|
+
"value": _getValue(element, hbResponse, i).value,
|
|
129
|
+
"timeOfSample": now.toISOString(),
|
|
130
|
+
"uncertaintyInMilliseconds": 500
|
|
131
|
+
});
|
|
132
|
+
i = i + 2; // Skip over the 3 color values
|
|
133
|
+
break;
|
|
134
|
+
case "alexa.temperaturesensor":
|
|
135
|
+
properties.push({
|
|
136
|
+
"namespace": "Alexa.TemperatureSensor",
|
|
137
|
+
"name": "temperature",
|
|
138
|
+
"value": {
|
|
139
|
+
"value": round(_getValue(element, hbResponse, i).value, 1),
|
|
140
|
+
"scale": "CELSIUS"
|
|
141
|
+
},
|
|
142
|
+
"timeOfSample": now.toISOString(),
|
|
143
|
+
"uncertaintyInMilliseconds": 500
|
|
144
|
+
});
|
|
145
|
+
break;
|
|
146
|
+
case "alexa.contactsensor":
|
|
147
|
+
properties.push({
|
|
148
|
+
"namespace": "Alexa.ContactSensor",
|
|
149
|
+
"name": "detectionState",
|
|
150
|
+
"value": _getValue(element, hbResponse, i).value ? "DETECTED" : "NOT_DETECTED",
|
|
151
|
+
"timeOfSample": now.toISOString(),
|
|
152
|
+
"uncertaintyInMilliseconds": 500
|
|
153
|
+
});
|
|
154
|
+
break;
|
|
155
|
+
case "alexa.motionsensor":
|
|
156
|
+
properties.push({
|
|
157
|
+
"namespace": "Alexa.MotionSensor",
|
|
158
|
+
"name": "detectionState",
|
|
159
|
+
"value": _getValue(element, hbResponse, i).value ? "DETECTED" : "NOT_DETECTED",
|
|
160
|
+
"timeOfSample": now.toISOString(),
|
|
161
|
+
"uncertaintyInMilliseconds": 500
|
|
162
|
+
});
|
|
163
|
+
break;
|
|
164
|
+
case "alexa.doorbelleventsource":
|
|
165
|
+
properties.push({
|
|
166
|
+
"namespace": "Alexa.DoorbellEventSource",
|
|
167
|
+
"name": "detectionState",
|
|
168
|
+
"value": _getValue(element, hbResponse, i).value ? "DETECTED" : "NOT_DETECTED",
|
|
169
|
+
"timeOfSample": now.toISOString(),
|
|
170
|
+
"uncertaintyInMilliseconds": 500
|
|
171
|
+
});
|
|
172
|
+
break;
|
|
173
|
+
// Characteristic.LockCurrentState.UNSECURED = 0;
|
|
174
|
+
// Characteristic.LockCurrentState.SECURED = 1;
|
|
175
|
+
// Characteristic.LockCurrentState.JAMMED = 2;
|
|
176
|
+
// Characteristic.LockCurrentState.UNKNOWN = 3;
|
|
177
|
+
case "alexa.lockcontroller":
|
|
178
|
+
properties.push({
|
|
179
|
+
"namespace": "Alexa.LockController",
|
|
180
|
+
"name": "lockState",
|
|
181
|
+
"value": _lockState(_getValue(element, hbResponse, i).value),
|
|
182
|
+
"timeOfSample": now.toISOString(),
|
|
183
|
+
"uncertaintyInMilliseconds": 500
|
|
184
|
+
});
|
|
185
|
+
break;
|
|
186
|
+
case "alexa.thermostatcontrollertargetsetpoint":
|
|
187
|
+
properties.push({
|
|
188
|
+
namespace: "Alexa.ThermostatController",
|
|
189
|
+
name: "targetSetpoint",
|
|
190
|
+
value: {
|
|
191
|
+
value: _getValue(element, hbResponse, i).value,
|
|
192
|
+
scale: "CELSIUS"
|
|
193
|
+
},
|
|
194
|
+
timeOfSample: now.toISOString(),
|
|
195
|
+
uncertaintyInMilliseconds: 500
|
|
196
|
+
});
|
|
197
|
+
break;
|
|
198
|
+
case "alexa.thermostatcontrollerlowersetpoint":
|
|
199
|
+
properties.push({
|
|
200
|
+
"namespace": "Alexa.ThermostatController",
|
|
201
|
+
"name": "lowerSetpoint",
|
|
202
|
+
"value": {
|
|
203
|
+
"value": _getValue(element, hbResponse, i).value,
|
|
204
|
+
"scale": "CELSIUS"
|
|
205
|
+
},
|
|
206
|
+
"timeOfSample": now.toISOString(),
|
|
207
|
+
"uncertaintyInMilliseconds": 500
|
|
208
|
+
});
|
|
209
|
+
break;
|
|
210
|
+
case "alexa.thermostatcontrolleruppersetpoint":
|
|
211
|
+
properties.push({
|
|
212
|
+
"namespace": "Alexa.ThermostatController",
|
|
213
|
+
"name": "upperSetpoint",
|
|
214
|
+
"value": {
|
|
215
|
+
"value": _getValue(element, hbResponse, i).value,
|
|
216
|
+
"scale": "CELSIUS"
|
|
217
|
+
},
|
|
218
|
+
"timeOfSample": now.toISOString(),
|
|
219
|
+
"uncertaintyInMilliseconds": 500
|
|
220
|
+
});
|
|
221
|
+
break;
|
|
222
|
+
case "alexa.thermostatcontrollerthermostatmode":
|
|
223
|
+
properties.push({
|
|
224
|
+
"namespace": "Alexa.ThermostatController",
|
|
225
|
+
"name": "thermostatMode",
|
|
226
|
+
"value": _getThermoMode(_getValue(element, hbResponse, i).value),
|
|
227
|
+
"timeOfSample": now.toISOString(),
|
|
228
|
+
"uncertaintyInMilliseconds": 500
|
|
229
|
+
});
|
|
230
|
+
break;
|
|
231
|
+
default:
|
|
232
|
+
debug("ERROR: statusReport unknown/handled device", element, reportState);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
return properties;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function mergeCookies(into, from) {
|
|
240
|
+
// debug("into", into);
|
|
241
|
+
for (var cookie in from) {
|
|
242
|
+
switch (cookie) {
|
|
243
|
+
case "SetMute":
|
|
244
|
+
case "AdjustVolume":
|
|
245
|
+
case "SetVolume":
|
|
246
|
+
// debug("merge cookie %s = %s into %s", cookie, from[cookie], JSON.stringify(into));
|
|
247
|
+
into[cookie] = from[cookie];
|
|
248
|
+
// debug("after", JSON.stringify(into));
|
|
249
|
+
// into = into.push({cookie: from[cookie]});
|
|
250
|
+
break;
|
|
251
|
+
case "ReportState":
|
|
252
|
+
// debug("merge cookie %s = %s into %s", cookie, from[cookie], into[cookie]);
|
|
253
|
+
var temp = [];
|
|
254
|
+
temp = JSON.parse(into[cookie]).concat(JSON.parse(from[cookie]));
|
|
255
|
+
into[cookie] = JSON.stringify(temp);
|
|
256
|
+
break;
|
|
257
|
+
default:
|
|
258
|
+
// debug("Not merging cookie", cookie);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function mergeInputCookies(into, from) {
|
|
264
|
+
// debug("into", JSON.parse(into['Active Identifier']).iid);
|
|
265
|
+
var inputs = {};
|
|
266
|
+
var activeIdentifier = JSON.parse(into['Active Identifier']).iid;
|
|
267
|
+
for (var cookie in from) {
|
|
268
|
+
// debug("mergeInputCookies", cookie, from[cookie]);
|
|
269
|
+
switch (cookie) {
|
|
270
|
+
case "Channel":
|
|
271
|
+
case "ReportState":
|
|
272
|
+
break;
|
|
273
|
+
default:
|
|
274
|
+
var input = JSON.parse(from[cookie]);
|
|
275
|
+
input["iid"] = activeIdentifier;
|
|
276
|
+
if (cookie.substring(0, 10) === "Station - ") {
|
|
277
|
+
into[cookie.substring(10)] = JSON.stringify(input);
|
|
278
|
+
} else {
|
|
279
|
+
into[cookie] = JSON.stringify(input);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
}
|
|
284
|
+
return inputs;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function mergeCapabilities(into, from) {
|
|
288
|
+
for (var capability in from) {
|
|
289
|
+
switch (from[capability].interface) {
|
|
290
|
+
case "Alexa.Speaker":
|
|
291
|
+
case "Alexa.StepSpeaker":
|
|
292
|
+
case "Alexa.InputController":
|
|
293
|
+
case "Alexa.ChannelController":
|
|
294
|
+
// debug("merge capability %s = %s into %s", from[capability].interface, JSON.stringify(from[capability]), JSON.stringify(into));
|
|
295
|
+
// into[capability] = from[capability];
|
|
296
|
+
into.push(from[capability]);
|
|
297
|
+
// debug("after", JSON.stringify(into));
|
|
298
|
+
break;
|
|
299
|
+
default:
|
|
300
|
+
// debug("Not merging capability", from[capability].interface);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function lookupCapabilities(capability, options, operations, devices) {
|
|
306
|
+
var response = [];
|
|
307
|
+
switch (capability) {
|
|
308
|
+
case "PlaybackController":
|
|
309
|
+
// debug("operations", Object.keys(operations));
|
|
310
|
+
var supported = Object.keys(operations);
|
|
311
|
+
supported = supported.filter(function(item) {
|
|
312
|
+
return item !== 'ReportState';
|
|
313
|
+
});
|
|
314
|
+
// debug("supported", supported);
|
|
315
|
+
response.push({
|
|
316
|
+
type: "AlexaInterface",
|
|
317
|
+
interface: "Alexa.PlaybackController",
|
|
318
|
+
version: "3",
|
|
319
|
+
supportedOperations: supported
|
|
320
|
+
});
|
|
321
|
+
break;
|
|
322
|
+
case "ChannelController":
|
|
323
|
+
response.push({
|
|
324
|
+
type: "AlexaInterface",
|
|
325
|
+
interface: "Alexa.ChannelController",
|
|
326
|
+
version: "3",
|
|
327
|
+
properties: {
|
|
328
|
+
supported: [{
|
|
329
|
+
name: "channel"
|
|
330
|
+
}],
|
|
331
|
+
proactivelyReported: false,
|
|
332
|
+
retrievable: true
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
break;
|
|
336
|
+
case "Input Source":
|
|
337
|
+
var supported = Object.keys(operations);
|
|
338
|
+
supported = supported.filter(function(item) {
|
|
339
|
+
return item.substring(0, 10) !== 'Station - ';
|
|
340
|
+
});
|
|
341
|
+
var inputs = [];
|
|
342
|
+
supported.forEach((item, i) => {
|
|
343
|
+
inputs.push({
|
|
344
|
+
name: item
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
response.push({
|
|
349
|
+
type: "AlexaInterface",
|
|
350
|
+
interface: "Alexa.InputController",
|
|
351
|
+
version: "3",
|
|
352
|
+
properties: {
|
|
353
|
+
supported: [{
|
|
354
|
+
name: "input"
|
|
355
|
+
}],
|
|
356
|
+
proactivelyReported: false,
|
|
357
|
+
retrievable: true
|
|
358
|
+
},
|
|
359
|
+
inputs: inputs
|
|
360
|
+
});
|
|
361
|
+
break;
|
|
362
|
+
case "ThermostatController":
|
|
363
|
+
// debug("operations", Object.keys(operations));
|
|
364
|
+
var ops = Object.keys(operations);
|
|
365
|
+
// debug("Supp", ops);
|
|
366
|
+
var supported = [];
|
|
367
|
+
ops.forEach(function(key) {
|
|
368
|
+
if (key === "thermostatModeOFF" || key === "upperSetpoint" || key === "lowerSetpoint" || key === "targetSetpoint") {
|
|
369
|
+
if (key.substring(0, 14) === "thermostatMode") {
|
|
370
|
+
key = "thermostatMode";
|
|
371
|
+
}
|
|
372
|
+
supported.push({
|
|
373
|
+
"name": key
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
// debug("supported", supported);
|
|
378
|
+
response.push({
|
|
379
|
+
"type": "AlexaInterface",
|
|
380
|
+
"interface": "Alexa.ThermostatController",
|
|
381
|
+
"version": "3",
|
|
382
|
+
"properties": {
|
|
383
|
+
"supported": supported,
|
|
384
|
+
"proactivelyReported": false,
|
|
385
|
+
"retrievable": true
|
|
386
|
+
},
|
|
387
|
+
"configuration": {
|
|
388
|
+
"supportsScheduling": false,
|
|
389
|
+
"supportedModes": [
|
|
390
|
+
"HEAT",
|
|
391
|
+
"COOL",
|
|
392
|
+
"AUTO",
|
|
393
|
+
"OFF"
|
|
394
|
+
]
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
break;
|
|
398
|
+
case "Volume":
|
|
399
|
+
response.push({
|
|
400
|
+
"type": "AlexaInterface",
|
|
401
|
+
"interface": "Alexa.Speaker",
|
|
402
|
+
"version": "3",
|
|
403
|
+
"properties": {
|
|
404
|
+
"supported": [{
|
|
405
|
+
"name": "volume"
|
|
406
|
+
}],
|
|
407
|
+
"proactivelyReported": false,
|
|
408
|
+
"retrievable": true
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
break;
|
|
412
|
+
case "Volume Selector":
|
|
413
|
+
response.push({
|
|
414
|
+
"type": "AlexaInterface",
|
|
415
|
+
"interface": "Alexa.StepSpeaker",
|
|
416
|
+
"version": "3"
|
|
417
|
+
});
|
|
418
|
+
break;
|
|
419
|
+
case "Color Temperature":
|
|
420
|
+
response.push({
|
|
421
|
+
"type": "AlexaInterface",
|
|
422
|
+
"interface": "Alexa.ColorTemperatureController",
|
|
423
|
+
"version": "3",
|
|
424
|
+
"properties": {
|
|
425
|
+
"supported": [{
|
|
426
|
+
"name": "colorTemperatureInKelvin"
|
|
427
|
+
}],
|
|
428
|
+
"proactivelyReported": false,
|
|
429
|
+
"retrievable": true
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
break;
|
|
433
|
+
case "ColorController":
|
|
434
|
+
response.push({
|
|
435
|
+
"type": "AlexaInterface",
|
|
436
|
+
"interface": "Alexa.ColorController",
|
|
437
|
+
"version": "3",
|
|
438
|
+
"properties": {
|
|
439
|
+
"supported": [{
|
|
440
|
+
"name": "color"
|
|
441
|
+
}],
|
|
442
|
+
"proactivelyReported": false,
|
|
443
|
+
"retrievable": true
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
break;
|
|
447
|
+
case "Rotation Speed": // RotationSpeed
|
|
448
|
+
case "Brightness": // Brightness
|
|
449
|
+
response.push({
|
|
450
|
+
"type": "AlexaInterface",
|
|
451
|
+
"interface": "Alexa.PowerLevelController",
|
|
452
|
+
"version": "3",
|
|
453
|
+
"properties": {
|
|
454
|
+
"supported": [{
|
|
455
|
+
"name": "powerLevel"
|
|
456
|
+
}],
|
|
457
|
+
"proactivelyReported": false,
|
|
458
|
+
"retrievable": true
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
break;
|
|
462
|
+
case "Target Position":
|
|
463
|
+
if (options.blind) {
|
|
464
|
+
// Range Controller version
|
|
465
|
+
debug("Target Position", devices);
|
|
466
|
+
if (!devices) {
|
|
467
|
+
devices = {};
|
|
468
|
+
}
|
|
469
|
+
if (!devices.maxValue) {
|
|
470
|
+
devices.maxValue = 100;
|
|
471
|
+
}
|
|
472
|
+
if (!devices.minValue) {
|
|
473
|
+
devices.minValue = 0;
|
|
474
|
+
}
|
|
475
|
+
response.push({
|
|
476
|
+
"type": "AlexaInterface",
|
|
477
|
+
"interface": "Alexa.RangeController",
|
|
478
|
+
"instance": "Blind.Lift",
|
|
479
|
+
"version": "3",
|
|
480
|
+
"properties": {
|
|
481
|
+
"supported": [{
|
|
482
|
+
"name": "rangeValue"
|
|
483
|
+
}],
|
|
484
|
+
"proactivelyReported": false,
|
|
485
|
+
"retrievable": true
|
|
486
|
+
},
|
|
487
|
+
"capabilityResources": {
|
|
488
|
+
"friendlyNames": [{
|
|
489
|
+
"@type": "asset",
|
|
490
|
+
"value": {
|
|
491
|
+
"assetId": "Alexa.Setting.Opening"
|
|
492
|
+
}
|
|
493
|
+
}]
|
|
494
|
+
},
|
|
495
|
+
"configuration": {
|
|
496
|
+
"supportedRange": {
|
|
497
|
+
"minimumValue": devices.minValue,
|
|
498
|
+
"maximumValue": devices.maxValue,
|
|
499
|
+
"precision": 1
|
|
500
|
+
},
|
|
501
|
+
"unitOfMeasure": "Alexa.Unit.Percent"
|
|
502
|
+
},
|
|
503
|
+
"semantics": {
|
|
504
|
+
"actionMappings": [{
|
|
505
|
+
"@type": "ActionsToDirective",
|
|
506
|
+
"actions": ["Alexa.Actions.Close"],
|
|
507
|
+
"directive": {
|
|
508
|
+
"name": "SetRangeValue",
|
|
509
|
+
"payload": {
|
|
510
|
+
"rangeValue": 0
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
"@type": "ActionsToDirective",
|
|
516
|
+
"actions": ["Alexa.Actions.Open"],
|
|
517
|
+
"directive": {
|
|
518
|
+
"name": "SetRangeValue",
|
|
519
|
+
"payload": {
|
|
520
|
+
"rangeValue": devices.maxValue
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
"@type": "ActionsToDirective",
|
|
526
|
+
"actions": ["Alexa.Actions.Lower"],
|
|
527
|
+
"directive": {
|
|
528
|
+
"name": "AdjustRangeValue",
|
|
529
|
+
"payload": {
|
|
530
|
+
"rangeValueDelta": -10,
|
|
531
|
+
"rangeValueDeltaDefault": false
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
"@type": "ActionsToDirective",
|
|
537
|
+
"actions": ["Alexa.Actions.Raise"],
|
|
538
|
+
"directive": {
|
|
539
|
+
"name": "AdjustRangeValue",
|
|
540
|
+
"payload": {
|
|
541
|
+
"rangeValueDelta": 10,
|
|
542
|
+
"rangeValueDeltaDefault": false
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
],
|
|
547
|
+
"stateMappings": [{
|
|
548
|
+
"@type": "StatesToValue",
|
|
549
|
+
"states": ["Alexa.States.Closed"],
|
|
550
|
+
"value": devices.minValue
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
"@type": "StatesToRange",
|
|
554
|
+
"states": ["Alexa.States.Open"],
|
|
555
|
+
"range": {
|
|
556
|
+
"minimumValue": 1,
|
|
557
|
+
"maximumValue": devices.maxValue
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
]
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
} else {
|
|
564
|
+
// Original logic
|
|
565
|
+
response.push({
|
|
566
|
+
"type": "AlexaInterface",
|
|
567
|
+
"interface": "Alexa.PowerController",
|
|
568
|
+
"version": "3",
|
|
569
|
+
"properties": {
|
|
570
|
+
"supported": [{
|
|
571
|
+
"name": "powerState"
|
|
572
|
+
}],
|
|
573
|
+
"proactivelyReported": false,
|
|
574
|
+
"retrievable": true
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
response.push({
|
|
578
|
+
"type": "AlexaInterface",
|
|
579
|
+
"interface": "Alexa.PowerLevelController",
|
|
580
|
+
"version": "3",
|
|
581
|
+
"properties": {
|
|
582
|
+
"supported": [{
|
|
583
|
+
"name": "powerLevel"
|
|
584
|
+
}],
|
|
585
|
+
"proactivelyReported": false,
|
|
586
|
+
"retrievable": true
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
break;
|
|
592
|
+
case "Target Door State":
|
|
593
|
+
if (options.door) {
|
|
594
|
+
// Mode Controller version
|
|
595
|
+
response.push({
|
|
596
|
+
"type": "AlexaInterface",
|
|
597
|
+
"interface": "Alexa.ModeController",
|
|
598
|
+
"instance": "GarageDoor.Position",
|
|
599
|
+
"version": "3",
|
|
600
|
+
"properties": {
|
|
601
|
+
"supported": [{
|
|
602
|
+
"name": "mode"
|
|
603
|
+
}],
|
|
604
|
+
"retrievable": true,
|
|
605
|
+
"proactivelyReported": false
|
|
606
|
+
},
|
|
607
|
+
"capabilityResources": {
|
|
608
|
+
"friendlyNames": [{
|
|
609
|
+
"@type": "asset",
|
|
610
|
+
"value": {
|
|
611
|
+
"assetId": "Alexa.Setting.Mode"
|
|
612
|
+
}
|
|
613
|
+
}]
|
|
614
|
+
},
|
|
615
|
+
"configuration": {
|
|
616
|
+
"ordered": false,
|
|
617
|
+
"supportedModes": [{
|
|
618
|
+
"value": "Position.Up",
|
|
619
|
+
"modeResources": {
|
|
620
|
+
"friendlyNames": [{
|
|
621
|
+
"@type": "asset",
|
|
622
|
+
"value": {
|
|
623
|
+
"assetId": "Alexa.Value.Open"
|
|
624
|
+
}
|
|
625
|
+
}]
|
|
626
|
+
}
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
"value": "Position.Down",
|
|
630
|
+
"modeResources": {
|
|
631
|
+
"friendlyNames": [{
|
|
632
|
+
"@type": "asset",
|
|
633
|
+
"value": {
|
|
634
|
+
"assetId": "Alexa.Value.Close"
|
|
635
|
+
}
|
|
636
|
+
}]
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
]
|
|
640
|
+
},
|
|
641
|
+
"semantics": {
|
|
642
|
+
"actionMappings": [{
|
|
643
|
+
"@type": "ActionsToDirective",
|
|
644
|
+
"actions": ["Alexa.Actions.Close", "Alexa.Actions.Lower"],
|
|
645
|
+
"directive": {
|
|
646
|
+
"name": "SetMode",
|
|
647
|
+
"payload": {
|
|
648
|
+
"mode": "Position.Down"
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
"@type": "ActionsToDirective",
|
|
654
|
+
"actions": ["Alexa.Actions.Open", "Alexa.Actions.Raise"],
|
|
655
|
+
"directive": {
|
|
656
|
+
"name": "SetMode",
|
|
657
|
+
"payload": {
|
|
658
|
+
"mode": "Position.Up"
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
],
|
|
663
|
+
"stateMappings": [{
|
|
664
|
+
"@type": "StatesToValue",
|
|
665
|
+
"states": ["Alexa.States.Closed"],
|
|
666
|
+
"value": "Position.Down"
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
"@type": "StatesToValue",
|
|
670
|
+
"states": ["Alexa.States.Open"],
|
|
671
|
+
"value": "Position.Up"
|
|
672
|
+
}
|
|
673
|
+
]
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
} else {
|
|
677
|
+
// Original version
|
|
678
|
+
response.push({
|
|
679
|
+
"type": "AlexaInterface",
|
|
680
|
+
"interface": "Alexa.PowerController",
|
|
681
|
+
"version": "3",
|
|
682
|
+
"properties": {
|
|
683
|
+
"supported": [{
|
|
684
|
+
"name": "powerState"
|
|
685
|
+
}],
|
|
686
|
+
"proactivelyReported": false,
|
|
687
|
+
"retrievable": true
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
break;
|
|
692
|
+
case "Active": // Active on a Fan 2 aka Dyson or Valve
|
|
693
|
+
case "On":
|
|
694
|
+
response.push({
|
|
695
|
+
"type": "AlexaInterface",
|
|
696
|
+
"interface": "Alexa.PowerController",
|
|
697
|
+
"version": "3",
|
|
698
|
+
"properties": {
|
|
699
|
+
"supported": [{
|
|
700
|
+
"name": "powerState"
|
|
701
|
+
}],
|
|
702
|
+
"proactivelyReported": false,
|
|
703
|
+
"retrievable": true
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
break;
|
|
707
|
+
case "Lock Target State":
|
|
708
|
+
response.push({
|
|
709
|
+
"type": "AlexaInterface",
|
|
710
|
+
"interface": "Alexa.LockController",
|
|
711
|
+
"version": "3",
|
|
712
|
+
"properties": {
|
|
713
|
+
"supported": [{
|
|
714
|
+
"name": "lockState"
|
|
715
|
+
}],
|
|
716
|
+
"proactivelyReported": false,
|
|
717
|
+
"retrievable": true
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
break;
|
|
721
|
+
case "Current Temperature":
|
|
722
|
+
response.push({
|
|
723
|
+
"type": "AlexaInterface",
|
|
724
|
+
"interface": "Alexa.TemperatureSensor",
|
|
725
|
+
"version": "3",
|
|
726
|
+
"properties": {
|
|
727
|
+
"supported": [{
|
|
728
|
+
"name": "temperature"
|
|
729
|
+
}],
|
|
730
|
+
"proactivelyReported": false,
|
|
731
|
+
"retrievable": true
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
break;
|
|
735
|
+
case "Preset":
|
|
736
|
+
response.push({
|
|
737
|
+
"type": "AlexaInterface",
|
|
738
|
+
"interface": "Alexa.ChannelController",
|
|
739
|
+
"version": "3",
|
|
740
|
+
"properties": {
|
|
741
|
+
"supported": [{
|
|
742
|
+
"name": "channel"
|
|
743
|
+
}],
|
|
744
|
+
"proactivelyReported": false,
|
|
745
|
+
"retrievable": true
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
break;
|
|
749
|
+
case "Motion Detected":
|
|
750
|
+
response.push({
|
|
751
|
+
"type": "AlexaInterface",
|
|
752
|
+
"interface": "Alexa.MotionSensor",
|
|
753
|
+
"version": "3",
|
|
754
|
+
"properties": {
|
|
755
|
+
"supported": [{
|
|
756
|
+
"name": "detectionState"
|
|
757
|
+
}],
|
|
758
|
+
"proactivelyReported": options.events,
|
|
759
|
+
"retrievable": true
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
break;
|
|
763
|
+
case "Contact Sensor State": // Contact Sensor State
|
|
764
|
+
case "Current Position":
|
|
765
|
+
case "Current Door State": // Current Door state
|
|
766
|
+
case "Occupancy Detected": // Occupancy Sensor
|
|
767
|
+
response.push({
|
|
768
|
+
"type": "AlexaInterface",
|
|
769
|
+
"interface": "Alexa.ContactSensor",
|
|
770
|
+
"version": "3",
|
|
771
|
+
"properties": {
|
|
772
|
+
"supported": [{
|
|
773
|
+
"name": "detectionState"
|
|
774
|
+
}],
|
|
775
|
+
"proactivelyReported": options.events,
|
|
776
|
+
"retrievable": true
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
break;
|
|
780
|
+
case "Programmable Switch Event": // Doorbell
|
|
781
|
+
response.push({
|
|
782
|
+
"type": "AlexaInterface",
|
|
783
|
+
"interface": "Alexa.DoorbellEventSource",
|
|
784
|
+
"version": "3",
|
|
785
|
+
"proactivelyReported": true
|
|
786
|
+
});
|
|
787
|
+
break;
|
|
788
|
+
case "Remote Key": // Current Door state
|
|
789
|
+
response.push({
|
|
790
|
+
"type": "AlexaInterface",
|
|
791
|
+
"interface": "Alexa.PlaybackController",
|
|
792
|
+
"version": "3",
|
|
793
|
+
"supportedOperations": ["Play", "Pause", "Stop", "Next", "Rewind"]
|
|
794
|
+
});
|
|
795
|
+
break;
|
|
796
|
+
default:
|
|
797
|
+
// Missing capabilities
|
|
798
|
+
// debug("ERROR: Missing capability", capability);
|
|
799
|
+
break;
|
|
800
|
+
}
|
|
801
|
+
// debug("lookupCapabilities", response);
|
|
802
|
+
return response;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
function normalizeName(id) {
|
|
806
|
+
switch (id) {
|
|
807
|
+
case "0000003E":
|
|
808
|
+
return ("Accessory Information");
|
|
809
|
+
case "000000BB":
|
|
810
|
+
return ("Air Purifier");
|
|
811
|
+
case "0000008D":
|
|
812
|
+
return ("Air Quality Sensor");
|
|
813
|
+
case "00000096":
|
|
814
|
+
return ("Battery Service");
|
|
815
|
+
case "00000097":
|
|
816
|
+
return ("Carbon Dioxide Sensor");
|
|
817
|
+
case "0000007F":
|
|
818
|
+
return ("Carbon Monoxide Sensor");
|
|
819
|
+
case "00000080":
|
|
820
|
+
return ("Contact Sensor");
|
|
821
|
+
case "00000081":
|
|
822
|
+
return ("Door");
|
|
823
|
+
case "00000121":
|
|
824
|
+
return ("Doorbell");
|
|
825
|
+
case "00000040":
|
|
826
|
+
return ("Fan");
|
|
827
|
+
case "000000B7":
|
|
828
|
+
return ("Fan v2");
|
|
829
|
+
case "000000BA":
|
|
830
|
+
return ("Filter Maintenance");
|
|
831
|
+
case "000000D7":
|
|
832
|
+
return ("Faucet");
|
|
833
|
+
case "00000041":
|
|
834
|
+
return ("Garage Door Opener");
|
|
835
|
+
case "000000BC":
|
|
836
|
+
return ("Heater Cooler");
|
|
837
|
+
case "000000BD":
|
|
838
|
+
return ("Humidifier Dehumidifier");
|
|
839
|
+
case "00000082":
|
|
840
|
+
return ("Humidity Sensor");
|
|
841
|
+
case "000000CF":
|
|
842
|
+
return ("Irrigation System");
|
|
843
|
+
case "00000083":
|
|
844
|
+
return ("Leak Sensor");
|
|
845
|
+
case "00000084":
|
|
846
|
+
return ("Light Sensor");
|
|
847
|
+
case "00000043":
|
|
848
|
+
return ("Lightbulb");
|
|
849
|
+
case "00000044":
|
|
850
|
+
return ("Lock Management");
|
|
851
|
+
case "00000045":
|
|
852
|
+
return ("Lock Mechanism");
|
|
853
|
+
case "00000112":
|
|
854
|
+
return ("Microphone");
|
|
855
|
+
case "00000085":
|
|
856
|
+
return ("Motion Sensor");
|
|
857
|
+
case "00000086":
|
|
858
|
+
return ("Occupancy Sensor");
|
|
859
|
+
case "00000047":
|
|
860
|
+
return ("Outlet");
|
|
861
|
+
case "0000007E":
|
|
862
|
+
return ("Security System");
|
|
863
|
+
case "000000CC":
|
|
864
|
+
return ("Service Label");
|
|
865
|
+
case "000000B9":
|
|
866
|
+
return ("Slat");
|
|
867
|
+
case "00000087":
|
|
868
|
+
return ("Smoke Sensor");
|
|
869
|
+
case "00000113": // Speaker Service
|
|
870
|
+
return ("Speaker");
|
|
871
|
+
case "00000089":
|
|
872
|
+
return ("Stateless Programmable Switch");
|
|
873
|
+
case "00000049":
|
|
874
|
+
return ("Switch");
|
|
875
|
+
case "0000008A":
|
|
876
|
+
return ("Temperature Sensor");
|
|
877
|
+
case "0000004A":
|
|
878
|
+
return ("Thermostat");
|
|
879
|
+
case "000000D0":
|
|
880
|
+
return ("Valve");
|
|
881
|
+
case "0000008B":
|
|
882
|
+
return ("Window");
|
|
883
|
+
case "0000008C":
|
|
884
|
+
return ("Window Covering");
|
|
885
|
+
case "00000111":
|
|
886
|
+
return ("Camera");
|
|
887
|
+
case "00000098": // Apple TV
|
|
888
|
+
return ("Apple TV");
|
|
889
|
+
case "000000D8": // Service Television
|
|
890
|
+
return ("Television");
|
|
891
|
+
case "000000D9": // Service "Input Source"
|
|
892
|
+
return ("Input Source");
|
|
893
|
+
default:
|
|
894
|
+
// debug("Missing HB Type", id);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
function lookupDisplayCategory(service) {
|
|
899
|
+
var category;
|
|
900
|
+
switch (service.substr(0, 8)) {
|
|
901
|
+
case "00000113": // SPEAKER
|
|
902
|
+
category = ["SPEAKER"];
|
|
903
|
+
break;
|
|
904
|
+
case "000000D8": // Service "Television"
|
|
905
|
+
case "00000098": // TV
|
|
906
|
+
category = ["TV"];
|
|
907
|
+
break;
|
|
908
|
+
case "00000043": // lightbulb
|
|
909
|
+
category = ["LIGHT"];
|
|
910
|
+
break;
|
|
911
|
+
case "0000008C": // Window Covering
|
|
912
|
+
category = ["INTERIOR_BLIND"];
|
|
913
|
+
break;
|
|
914
|
+
case "000000D0": // Valve / Sprinkler
|
|
915
|
+
category = ["OTHER"];
|
|
916
|
+
break;
|
|
917
|
+
case "00000041": // Garage Door
|
|
918
|
+
category = ["GARAGE_DOOR"];
|
|
919
|
+
break;
|
|
920
|
+
case "00000045": // Garage Door
|
|
921
|
+
category = ["SMARTLOCK"];
|
|
922
|
+
break;
|
|
923
|
+
case "00000047":
|
|
924
|
+
// Outlet
|
|
925
|
+
category = ["SMARTPLUG"];
|
|
926
|
+
break;
|
|
927
|
+
case "00000049":
|
|
928
|
+
case "000000BB": // Air purifier
|
|
929
|
+
case "000000BD": // Humidifier Dehumidifier
|
|
930
|
+
// Switch
|
|
931
|
+
category = ["SWITCH"];
|
|
932
|
+
break;
|
|
933
|
+
case "00000040": // Fan
|
|
934
|
+
case "000000B7": // Fan2
|
|
935
|
+
category = ["FAN"];
|
|
936
|
+
break;
|
|
937
|
+
case "0000008A":
|
|
938
|
+
category = ["TEMPERATURE_SENSOR"];
|
|
939
|
+
break;
|
|
940
|
+
case "00000080":
|
|
941
|
+
case "00000086": // Occupancy Sensor
|
|
942
|
+
category = ["CONTACT_SENSOR"];
|
|
943
|
+
break;
|
|
944
|
+
case "00000121": // Doorbell
|
|
945
|
+
category = ["DOORBELL"];
|
|
946
|
+
break;
|
|
947
|
+
case "00000085":
|
|
948
|
+
category = ["MOTION_SENSOR"];
|
|
949
|
+
break;
|
|
950
|
+
case "0000004A":
|
|
951
|
+
case "000000BC":
|
|
952
|
+
category = ["THERMOSTAT"];
|
|
953
|
+
break;
|
|
954
|
+
default:
|
|
955
|
+
// No mapping exists
|
|
956
|
+
// debug("No display category for %s using other", service.substr(0, 8));
|
|
957
|
+
category = ["OTHER"];
|
|
958
|
+
break;
|
|
959
|
+
}
|
|
960
|
+
return category;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
function reportState(_interface, context) {
|
|
964
|
+
return {
|
|
965
|
+
"interface": _interface,
|
|
966
|
+
"deviceID": context.deviceID,
|
|
967
|
+
|
|
968
|
+
"aid": context.aid,
|
|
969
|
+
"iid": context.liid
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
function cookie(context) {
|
|
974
|
+
return JSON.stringify({
|
|
975
|
+
"deviceID": context.deviceID,
|
|
976
|
+
|
|
977
|
+
"aid": context.aid,
|
|
978
|
+
"iid": context.liid
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
function cookieV(_value, context) {
|
|
983
|
+
return JSON.stringify({
|
|
984
|
+
"deviceID": context.deviceID,
|
|
985
|
+
|
|
986
|
+
"aid": context.aid,
|
|
987
|
+
"iid": context.liid,
|
|
988
|
+
"value": _value
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
function isAppleTV(device) {
|
|
993
|
+
if (device.info.Manufacturer === "Apple" && device.info.Model === "Apple TV" && atvButton(device.name)) {
|
|
994
|
+
return true;
|
|
995
|
+
} else {
|
|
996
|
+
return false;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
function isYamaha(device) {
|
|
1001
|
+
// debug("DEVICE", device);
|
|
1002
|
+
if (device.info.Manufacturer === "yamaha-home" && device.info.Name.substr(0, device.info.Name.indexOf(" ")) === "Spotify" && _yamahaButton(device.name)) {
|
|
1003
|
+
return true;
|
|
1004
|
+
} else {
|
|
1005
|
+
return false;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
function _yamahaButton(name) {
|
|
1010
|
+
switch (name.substr(0, name.lastIndexOf(" "))) {
|
|
1011
|
+
// case "Pair":
|
|
1012
|
+
case "Skip Fwd":
|
|
1013
|
+
case "Skip Rev":
|
|
1014
|
+
case "Play":
|
|
1015
|
+
case "Pause":
|
|
1016
|
+
case "Spotify":
|
|
1017
|
+
return true;
|
|
1018
|
+
default:
|
|
1019
|
+
return false;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
function atvButton(name) {
|
|
1024
|
+
// debug('atvButton', name);
|
|
1025
|
+
try {
|
|
1026
|
+
switch (name.substr(0, name.indexOf('(')).trim()) {
|
|
1027
|
+
// case "Pair":
|
|
1028
|
+
case "Menu":
|
|
1029
|
+
case "TV/Home":
|
|
1030
|
+
case "Mic/Siri":
|
|
1031
|
+
case "Play":
|
|
1032
|
+
case "Pause":
|
|
1033
|
+
case "Up":
|
|
1034
|
+
case "Down":
|
|
1035
|
+
case "Left":
|
|
1036
|
+
case "Right":
|
|
1037
|
+
case "Select":
|
|
1038
|
+
case "Sleep":
|
|
1039
|
+
return true;
|
|
1040
|
+
default:
|
|
1041
|
+
return false;
|
|
1042
|
+
}
|
|
1043
|
+
} catch (err) {
|
|
1044
|
+
debug('ERROR: atvButton()', name);
|
|
1045
|
+
return false;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
function playbackNameTranslate(name) {
|
|
1050
|
+
// debug("split", name.substring(0, name.lastIndexOf(" ")));
|
|
1051
|
+
switch (name.substr(0, name.indexOf('(')).trim()) {
|
|
1052
|
+
case "Menu": // Apple TV
|
|
1053
|
+
return "Stop";
|
|
1054
|
+
case "Skip Fwd": // Yamaha
|
|
1055
|
+
case "Right": // Apple-TV-Remote
|
|
1056
|
+
return "Next";
|
|
1057
|
+
case "Skip Rev": // Yamaha
|
|
1058
|
+
case "Left": // Apple-TV-Remote
|
|
1059
|
+
return "Rewind";
|
|
1060
|
+
default:
|
|
1061
|
+
return name.substr(0, name.indexOf('(')).trim();
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
function round(value, precision) {
|
|
1066
|
+
var multiplier = Math.pow(10, precision || 0);
|
|
1067
|
+
return Math.round(value * multiplier) / multiplier;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
function inputs(options, accessories) {
|
|
1071
|
+
// Create input controller Object
|
|
1072
|
+
|
|
1073
|
+
options.inputs.forEach(function(input) {
|
|
1074
|
+
// debug("Input", input);
|
|
1075
|
+
var inputs = [];
|
|
1076
|
+
var cookies = {};
|
|
1077
|
+
|
|
1078
|
+
// Find endpoint that should be part of the input
|
|
1079
|
+
|
|
1080
|
+
input.devices.forEach(function(device) {
|
|
1081
|
+
// debug("Device", device);
|
|
1082
|
+
|
|
1083
|
+
cookies = Object.assign(cookies, _getCookie(device, accessories));
|
|
1084
|
+
|
|
1085
|
+
inputs.push({
|
|
1086
|
+
name: device.alexaName
|
|
1087
|
+
});
|
|
1088
|
+
});
|
|
1089
|
+
|
|
1090
|
+
accessories = _insertInputCapability(input, inputs, cookies, accessories);
|
|
1091
|
+
});
|
|
1092
|
+
|
|
1093
|
+
return (accessories);
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
function channel(options, accessories) {
|
|
1097
|
+
// Create input controller Object
|
|
1098
|
+
|
|
1099
|
+
options.channel.forEach(function(input) {
|
|
1100
|
+
// debug("Input", input);
|
|
1101
|
+
// var inputs = [];
|
|
1102
|
+
var cookies = {};
|
|
1103
|
+
|
|
1104
|
+
input.alexaName = "ChangeChannel";
|
|
1105
|
+
// debug("Input", input);
|
|
1106
|
+
cookies = Object.assign(cookies, _getChannelCookie(input, accessories));
|
|
1107
|
+
// debug("cookies", cookies);
|
|
1108
|
+
accessories = _insertChannelCapability(input, cookies, accessories);
|
|
1109
|
+
});
|
|
1110
|
+
|
|
1111
|
+
return (accessories);
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
function combine(options, accessories) {
|
|
1115
|
+
var cleanup = [];
|
|
1116
|
+
var combine = [];
|
|
1117
|
+
// debug("Combine", Array.isArray(options.combine), options.combine);
|
|
1118
|
+
if (!Array.isArray(options.combine)) {
|
|
1119
|
+
combine.push(options.combine);
|
|
1120
|
+
} else {
|
|
1121
|
+
combine = options.combine;
|
|
1122
|
+
}
|
|
1123
|
+
debug("Combine-2", Array.isArray(combine), combine);
|
|
1124
|
+
combine.forEach(function(combine) {
|
|
1125
|
+
var from = [];
|
|
1126
|
+
var target;
|
|
1127
|
+
|
|
1128
|
+
debug("combine", combine);
|
|
1129
|
+
for (var endpoint in accessories.event.payload.endpoints) {
|
|
1130
|
+
// debug(endpoint);
|
|
1131
|
+
// debug("endpoints", combine, accessories.event.payload.endpoints[endpoint].friendlyName);
|
|
1132
|
+
if (combine.into === accessories.event.payload.endpoints[endpoint].friendlyName) {
|
|
1133
|
+
target = endpoint;
|
|
1134
|
+
}
|
|
1135
|
+
combine.from.forEach(function(unit) {
|
|
1136
|
+
// debug("unit", unit);
|
|
1137
|
+
if (unit === accessories.event.payload.endpoints[endpoint].friendlyName) {
|
|
1138
|
+
from.push(accessories.event.payload.endpoints[endpoint]);
|
|
1139
|
+
cleanup.push(endpoint);
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
if (from && accessories.event.payload.endpoints[target]) {
|
|
1145
|
+
// debug("Combine", accessories.event.payload.endpoints[target], from);
|
|
1146
|
+
_combineAlexaDevices(accessories.event.payload.endpoints[target], from);
|
|
1147
|
+
// console.log('\n', JSON.stringify(accessories));
|
|
1148
|
+
} else {
|
|
1149
|
+
// issue #388 - Better debugging
|
|
1150
|
+
if (!target) debug('ERROR: Missing combine into device \'%s\'', combine.into);
|
|
1151
|
+
if (from.length < 1) debug('ERROR: Missing combine from devices \'%s\'', combine.from);
|
|
1152
|
+
}
|
|
1153
|
+
// } else {
|
|
1154
|
+
// console.log("ERROR: combine settings problem");
|
|
1155
|
+
});
|
|
1156
|
+
if (cleanup.length > 0) {
|
|
1157
|
+
cleanup.forEach(function(endpoint) {
|
|
1158
|
+
delete accessories.event.payload.endpoints[endpoint];
|
|
1159
|
+
});
|
|
1160
|
+
// debug(JSON.stringify(accessories.event.payload.endpoints));
|
|
1161
|
+
accessories.event.payload.endpoints = accessories.event.payload.endpoints.filter(function(e) {
|
|
1162
|
+
return e;
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
// debug("Combine complete");
|
|
1166
|
+
return (accessories);
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
function _insertChannelCapability(input, cookies, accessories) {
|
|
1170
|
+
//
|
|
1171
|
+
// debug("Accessories", accessories);
|
|
1172
|
+
for (var endpoint in accessories.event.payload.endpoints) {
|
|
1173
|
+
if (input.into === accessories.event.payload.endpoints[endpoint].friendlyName) {
|
|
1174
|
+
accessories.event.payload.endpoints[endpoint].capabilities.push({
|
|
1175
|
+
"type": "AlexaInterface",
|
|
1176
|
+
"interface": "Alexa.ChannelController",
|
|
1177
|
+
"version": "3",
|
|
1178
|
+
"properties": {
|
|
1179
|
+
"supported": [{
|
|
1180
|
+
"name": "channel"
|
|
1181
|
+
}],
|
|
1182
|
+
"proactivelyReported": false,
|
|
1183
|
+
"retrievable": true
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
|
|
1187
|
+
accessories.event.payload.endpoints[endpoint].cookie =
|
|
1188
|
+
Object.assign({}, accessories.event.payload.endpoints[endpoint].cookie, cookies);
|
|
1189
|
+
// debug("Cookies", accessories.event.payload.endpoints[endpoint].cookie);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
return (accessories);
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
function _insertInputCapability(input, inputs, cookies, accessories) {
|
|
1197
|
+
//
|
|
1198
|
+
for (var endpoint in accessories.event.payload.endpoints) {
|
|
1199
|
+
if (input.into === accessories.event.payload.endpoints[endpoint].friendlyName) {
|
|
1200
|
+
accessories.event.payload.endpoints[endpoint].capabilities.push({
|
|
1201
|
+
type: "AlexaInterface",
|
|
1202
|
+
interface: "Alexa.InputController",
|
|
1203
|
+
version: "3",
|
|
1204
|
+
properties: {
|
|
1205
|
+
supported: [{
|
|
1206
|
+
name: "input"
|
|
1207
|
+
}],
|
|
1208
|
+
proactivelyReported: false,
|
|
1209
|
+
retrievable: true
|
|
1210
|
+
},
|
|
1211
|
+
inputs: inputs
|
|
1212
|
+
});
|
|
1213
|
+
// debug("Cookies", cookies);
|
|
1214
|
+
accessories.event.payload.endpoints[endpoint].cookie =
|
|
1215
|
+
Object.assign({}, accessories.event.payload.endpoints[endpoint].cookie, cookies);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
return (accessories);
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
function _getCookie(device, accessories) {
|
|
1223
|
+
var cookie = {};
|
|
1224
|
+
for (var endpoint in accessories.event.payload.endpoints) {
|
|
1225
|
+
if (device.name === accessories.event.payload.endpoints[endpoint].friendlyName &&
|
|
1226
|
+
device.manufacturer === accessories.event.payload.endpoints[endpoint].manufacturerName) {
|
|
1227
|
+
// debug(accessories.event.payload.endpoints[endpoint].cookie);
|
|
1228
|
+
if (accessories.event.payload.endpoints[endpoint].cookie.TurnOn) {
|
|
1229
|
+
cookie[device.alexaName] = accessories.event.payload.endpoints[endpoint].cookie.TurnOn;
|
|
1230
|
+
return (cookie);
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
function _getChannelCookie(device, accessories) {
|
|
1237
|
+
var cookie = {};
|
|
1238
|
+
for (var endpoint in accessories.event.payload.endpoints) {
|
|
1239
|
+
if (device.name === accessories.event.payload.endpoints[endpoint].friendlyName &&
|
|
1240
|
+
device.manufacturer === accessories.event.payload.endpoints[endpoint].manufacturerName) {
|
|
1241
|
+
// debug(accessories.event.payload.endpoints[endpoint].cookie);
|
|
1242
|
+
if (accessories.event.payload.endpoints[endpoint].cookie.Channel) {
|
|
1243
|
+
cookie[device.alexaName] = accessories.event.payload.endpoints[endpoint].cookie.Channel;
|
|
1244
|
+
return (cookie);
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
// Original Version
|
|
1251
|
+
//
|
|
1252
|
+
// { interface: "alexa.colorcontroller",
|
|
1253
|
+
// aid: 101,
|
|
1254
|
+
// iid: 10 }
|
|
1255
|
+
|
|
1256
|
+
function _getValue(element, hbResponse) {
|
|
1257
|
+
var value;
|
|
1258
|
+
if (element.interface.toLowerCase() === "alexa.colorcontroller") {
|
|
1259
|
+
value = {
|
|
1260
|
+
hue: _round(_getHBValue(element.hue, hbResponse).value, 1),
|
|
1261
|
+
saturation: _round(_getHBValue(element.saturation, hbResponse).value / 100, 4),
|
|
1262
|
+
brightness: _round(_getHBValue(element.brightness, hbResponse).value / 100, 4)
|
|
1263
|
+
};
|
|
1264
|
+
debug("Color Value", value);
|
|
1265
|
+
return {
|
|
1266
|
+
value: value,
|
|
1267
|
+
status: 0
|
|
1268
|
+
};
|
|
1269
|
+
} else {
|
|
1270
|
+
return _getHBValue(element, hbResponse);
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
function _getHBValue(element, hbResponse) {
|
|
1275
|
+
debug("_getHBValue", element, hbResponse);
|
|
1276
|
+
var value, status;
|
|
1277
|
+
for (var i in hbResponse) {
|
|
1278
|
+
if (hbResponse[i].aid === element.aid && hbResponse[i].iid === element.iid) {
|
|
1279
|
+
value = hbResponse[i].value;
|
|
1280
|
+
status = hbResponse[i].status;
|
|
1281
|
+
break;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
return {
|
|
1285
|
+
value: value,
|
|
1286
|
+
status: status
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
function _round(value, precision) {
|
|
1291
|
+
var multiplier = Math.pow(10, precision || 0);
|
|
1292
|
+
return Math.round(value * multiplier) / multiplier;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
// New version
|
|
1296
|
+
|
|
1297
|
+
/* statusObject {
|
|
1298
|
+
body: '?id=101.10,101.11',
|
|
1299
|
+
interface: 'Alexa.PowerController,Alexa.PowerLevelController',
|
|
1300
|
+
deviceID: 'CC:22:3D:E3:CE:30',
|
|
1301
|
+
spacer: ','
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
element Alexa.PowerController
|
|
1305
|
+
hbResponse [
|
|
1306
|
+
{ aid: 101, iid: 11, value: 100 },
|
|
1307
|
+
{ aid: 101, iid: 10, value: false }
|
|
1308
|
+
]
|
|
1309
|
+
*/
|
|
1310
|
+
|
|
1311
|
+
/*
|
|
1312
|
+
function _getValue(element, hbResponse, i) {
|
|
1313
|
+
var value;
|
|
1314
|
+
if (element.toLowerCase() === "alexa.colorcontroller") {
|
|
1315
|
+
value = {
|
|
1316
|
+
"hue": round(hbResponse[i].value, 1),
|
|
1317
|
+
"saturation": round(hbResponse[i + 1].value / 100, 4),
|
|
1318
|
+
"brightness": round(hbResponse[i + 2].value / 100, 4)
|
|
1319
|
+
};
|
|
1320
|
+
debug("Color Value", value);
|
|
1321
|
+
return {
|
|
1322
|
+
"value": value,
|
|
1323
|
+
"status": 0
|
|
1324
|
+
};
|
|
1325
|
+
} else {
|
|
1326
|
+
return {
|
|
1327
|
+
"value": hbResponse[i].value,
|
|
1328
|
+
"status": hbResponse[i].status
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
*/
|
|
1333
|
+
|
|
1334
|
+
function _combineAlexaDevices(into, from) {
|
|
1335
|
+
from.forEach(function(device) {
|
|
1336
|
+
// debug('\nFrom', device.friendlyName);
|
|
1337
|
+
// Combine Cookies
|
|
1338
|
+
for (var cookie in device.cookie) {
|
|
1339
|
+
if (!into.cookie[cookie] && cookie !== 'ReportState') {
|
|
1340
|
+
// debug('Combining', device.friendlyName, cookie);
|
|
1341
|
+
into.cookie[cookie] = device.cookie[cookie];
|
|
1342
|
+
} else if (cookie === 'ReportState') {
|
|
1343
|
+
debug('Combining ReportState', device.friendlyName, into.cookie, device.cookie[cookie]);
|
|
1344
|
+
var cookieReportState = JSON.parse(device.cookie[cookie]);
|
|
1345
|
+
|
|
1346
|
+
debug("into.cookie[cookie]", into.cookie[cookie]);
|
|
1347
|
+
if (into.cookie[cookie]) {
|
|
1348
|
+
var before = JSON.parse(into.cookie[cookie]);
|
|
1349
|
+
} else {
|
|
1350
|
+
var before = [];
|
|
1351
|
+
}
|
|
1352
|
+
// debug('Report state before', before);
|
|
1353
|
+
for (var reportState in cookieReportState) {
|
|
1354
|
+
debug('Combining Cookie', device.friendlyName, cookie, cookieReportState[reportState].interface);
|
|
1355
|
+
if (!_existingCapability(before, cookieReportState[reportState])) {
|
|
1356
|
+
before.push(cookieReportState[reportState]);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
into.cookie[cookie] = JSON.stringify(before);
|
|
1360
|
+
} else {
|
|
1361
|
+
// debug('ERROR: duplicate cookie', device.friendlyName, cookie);
|
|
1362
|
+
}
|
|
1363
|
+
} // Finshed combining cookies, now need to combine capabilities
|
|
1364
|
+
// Combine capabilities
|
|
1365
|
+
device.capabilities.forEach(function(capability) {
|
|
1366
|
+
if (capability.interface !== 'Alexa') {
|
|
1367
|
+
debug('Combining capability', device.friendlyName, capability.interface);
|
|
1368
|
+
if (!_existingCapability(into.capabilities, capability)) {
|
|
1369
|
+
into.capabilities.push(capability);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
});
|
|
1373
|
+
});
|
|
1374
|
+
// debug('\nAfter', JSON.stringify(into, null, 4));
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
function _existingCapability(into, from) {
|
|
1378
|
+
var found = false;
|
|
1379
|
+
into.forEach((item, i) => {
|
|
1380
|
+
if (item.interface === from.interface) {
|
|
1381
|
+
debug("%s === %s", item.interface, from.interface);
|
|
1382
|
+
found = true;
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
return found;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
function _lockState(state) {
|
|
1389
|
+
// Characteristic.LockCurrentState.UNSECURED = 0;
|
|
1390
|
+
// Characteristic.LockCurrentState.SECURED = 1;
|
|
1391
|
+
// Characteristic.LockCurrentState.JAMMED = 2;
|
|
1392
|
+
// Characteristic.LockCurrentState.UNKNOWN = 3;
|
|
1393
|
+
switch (state) {
|
|
1394
|
+
case 0:
|
|
1395
|
+
return "UNLOCKED";
|
|
1396
|
+
case 1:
|
|
1397
|
+
return "LOCKED";
|
|
1398
|
+
default:
|
|
1399
|
+
return "JAMMED";
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
function _getThermoMode(mode) {
|
|
1404
|
+
// Characteristic.CurrentHeatingCoolingState.OFF = 0;
|
|
1405
|
+
// Characteristic.CurrentHeatingCoolingState.HEAT = 1;
|
|
1406
|
+
// Characteristic.CurrentHeatingCoolingState.COOL = 2;
|
|
1407
|
+
switch (mode) {
|
|
1408
|
+
case 0:
|
|
1409
|
+
return "OFF";
|
|
1410
|
+
case 1:
|
|
1411
|
+
return "HEAT";
|
|
1412
|
+
case 2:
|
|
1413
|
+
return "COOL";
|
|
1414
|
+
case 3:
|
|
1415
|
+
return "AUTO";
|
|
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
|
+
// endpoints.forEach((endpoint) => {
|
|
1425
|
+
for (var key in endpoints) {
|
|
1426
|
+
var endpoint = endpoints[key];
|
|
1427
|
+
if (this.deviceListHandling === "allow") {
|
|
1428
|
+
if (verifyDeviceInList(this.deviceList, endpoint.friendlyName)) {
|
|
1429
|
+
response.push(endpoint);
|
|
1430
|
+
debug("INFO: DeviceList - allow =>", endpoint.friendlyName);
|
|
1431
|
+
}
|
|
1432
|
+
} else if (this.deviceListHandling === "deny") {
|
|
1433
|
+
if (verifyDeviceInList(this.deviceList, endpoint.friendlyName)) {
|
|
1434
|
+
debug("INFO: DeviceList - deny =>", endpoint.friendlyName);
|
|
1435
|
+
} else {
|
|
1436
|
+
response[key] = endpoint;
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
return (response);
|
|
1441
|
+
} else {
|
|
1442
|
+
// this.log("INFO: DeviceList empty feature not enabled or config error in deviceListHandling");
|
|
1443
|
+
return endpoints;
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
function verifyDeviceInList(deviceList, deviceName) {
|
|
1448
|
+
for (var i = 0, len = deviceList.length; i < len; i++) {
|
|
1449
|
+
if (deviceName === deviceList[i] || deviceName.match(new RegExp(deviceList[i]))) return true;
|
|
1450
|
+
}
|
|
1451
|
+
return false;
|
|
1452
|
+
}
|