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.
@@ -0,0 +1,225 @@
1
+ var debug = require('debug')('alexa:Homebridge');
2
+ var Accessory = require('./Accessory.js').Accessory;
3
+ var messages = require('./messages.js');
4
+
5
+ module.exports = {
6
+ Homebridge: Homebridge
7
+ };
8
+
9
+ /*
10
+ * Homebridges -> Homebridge -> Accessory -> Service -> Characteristic
11
+ */
12
+
13
+ function Homebridge(devices, context) {
14
+ // debug("Homebridge", devices);
15
+ this.accessories = [];
16
+ this.homebridge = devices.instance.txt.md;
17
+ this.deviceID = devices.deviceID;
18
+ this.id = devices.instance.txt.id;
19
+ this.options = {
20
+ events: context.events,
21
+ speakers: context.speakers,
22
+ blind: context.blind,
23
+ door: context.door
24
+ };
25
+ this.playback = {};
26
+ devices.accessories.accessories.forEach(function(element) {
27
+ var accessory = new Accessory(element, this);
28
+ if (this.accessories[accessory.name + accessory.aid]) {
29
+ debug("Duplicate", accessory.name);
30
+ } else {
31
+ // debug("Adding", accessory.name)
32
+ }
33
+ this.accessories.push(accessory);
34
+ // debug("playback", accessory.name, accessory.playback);
35
+ if (accessory.playback) {
36
+ var playback = (accessory.name.split("(")[1] ? accessory.name.split("(")[1].split(")")[0] : undefined);
37
+ // debug("ATVName", playback);
38
+ if (playback && accessory.name.substr(0, accessory.name.indexOf(" ")) !== "Pair") {
39
+ this.playback[playback] = playback;
40
+ }
41
+ }
42
+ }.bind(this));
43
+ }
44
+
45
+ Homebridge.prototype.toList = function(opt) {
46
+ var list = [];
47
+ for (var index in this.accessories) {
48
+ var accessory = this.accessories[index];
49
+ list = list.concat(accessory.toList({
50
+ deviceID: this.deviceID,
51
+ homebridge: this.homebridge,
52
+ id: this.id,
53
+ opt: opt
54
+ }));
55
+ // list.push(accessory.toList());
56
+ }
57
+ // debug("opt",opt,list.length);
58
+ return (list);
59
+ };
60
+
61
+ Homebridge.prototype.toAlexa = function(opt) {
62
+ var list = [];
63
+
64
+ // Alexa devices made up of multiple homekit accessories in a single homebridge instance
65
+ // Devices include Apple TV and Yamaha Stereo Playback controls
66
+
67
+ if (this.playback) { // Homebridge instance contains appleTV's
68
+ for (var playback in this.playback) {
69
+ var cookie = {};
70
+ var service = "00000098";
71
+ for (var index in this.accessories) {
72
+ // debug("Checking", index);
73
+ var accessory = this.accessories[index];
74
+ // debug("Checking", accessory);
75
+ if (accessory.playback && messages.isYamaha(accessory)) {
76
+ // debug("Yamaha", accessory);
77
+ service = "00000113";
78
+ // accessory.services.forEach(function(service) {
79
+ for (var index in accessory.services) {
80
+ var device = accessory.services[index];
81
+
82
+ cookie[messages.playbackNameTranslate(device.name)] = device.toCookie("On", {
83
+ deviceID: this.deviceID,
84
+ homebridge: this.homebridge,
85
+ aid: device.aid,
86
+ id: this.id,
87
+ opt: opt
88
+ });
89
+ if (messages.playbackNameTranslate(device.name) === "Pause") {
90
+ cookie["Stop"] = device.toCookie("On", {
91
+ deviceID: this.deviceID,
92
+ homebridge: this.homebridge,
93
+ aid: device.aid,
94
+ id: this.id,
95
+ opt: opt
96
+ });
97
+ }
98
+ cookie["ReportState"] = JSON.stringify([device.toCookie("On", {
99
+ deviceID: this.deviceID,
100
+ homebridge: this.homebridge,
101
+ id: this.id,
102
+ aid: device.aid,
103
+ opt: opt
104
+ })]);
105
+ }
106
+ }
107
+ // debug("Name", accessory.name);
108
+ if (accessory.name === "Play (" + playback + ")" || accessory.name === "Pause (" + playback + ")" || accessory.name === "Menu (" + playback + ")") {
109
+ service = "00000098";
110
+ cookie[messages.playbackNameTranslate(accessory.name)] = accessory.toCookie("On", {
111
+ deviceID: this.deviceID,
112
+
113
+ homebridge: this.homebridge,
114
+ id: this.id,
115
+ opt: opt
116
+ });
117
+ cookie["ReportState"] = JSON.stringify([accessory.toCookie("ReportState", {
118
+ deviceID: this.deviceID,
119
+
120
+ homebridge: this.homebridge,
121
+ id: this.id,
122
+ opt: opt
123
+ })]);
124
+ } else {
125
+ if (!accessory.playback) {
126
+ // debug("not Atv", accessory.name);
127
+ } else {
128
+ // Apple TV Remote Plugin
129
+ service = "00000098";
130
+ for (var index in accessory.services) {
131
+ var device = accessory.services[index];
132
+
133
+ // debug("name", device.name, playback);
134
+ if (device.name === "Play (" + playback + ")" || device.name === "Pause (" + playback + ")" || device.name === "Right (" + playback + ")" || device.name === "Left (" + playback + ")") {
135
+ // debug('cookie', messages.playbackNameTranslate(device.name), cookie.Pause, cookie.Play);
136
+ cookie[messages.playbackNameTranslate(device.name)] = device.toCookie("On", {
137
+ deviceID: this.deviceID,
138
+
139
+ homebridge: this.homebridge,
140
+ aid: device.aid,
141
+ id: this.id,
142
+ opt: opt
143
+ });
144
+ if (messages.playbackNameTranslate(device.name) === "Play" && ! cookie.Pause) {
145
+ // No need for fake pause button, the Play button is a pause/play toggle
146
+ // debug('Fake pause', this.id, opt);
147
+ cookie["Pause"] = device.toCookie("On", {
148
+ deviceID: this.deviceID,
149
+
150
+ homebridge: this.homebridge,
151
+ aid: device.aid,
152
+ id: this.id,
153
+ opt: opt
154
+ }, 0);
155
+ }
156
+ if (messages.playbackNameTranslate(device.name) === "Pause") {
157
+ cookie["Stop"] = device.toCookie("On", {
158
+ deviceID: this.deviceID,
159
+
160
+ homebridge: this.homebridge,
161
+ aid: device.aid,
162
+ id: this.id,
163
+ opt: opt
164
+ });
165
+ }
166
+ /*
167
+ cookie["ReportState"] = JSON.stringify([device.toCookie("ReportState", {
168
+ deviceID: this.deviceID,
169
+
170
+ homebridge: this.homebridge,
171
+ id: this.id,
172
+ aid: device.aid,
173
+ opt: opt
174
+ })]);
175
+ */
176
+ }
177
+ }
178
+ }
179
+ }
180
+ }
181
+
182
+ // Add an endpoint for each playback Device
183
+
184
+ var capabilities = [];
185
+ capabilities = capabilities.concat({
186
+ "type": "AlexaInterface",
187
+ "interface": "Alexa",
188
+ "version": "3"
189
+ });
190
+ capabilities = capabilities.concat(messages.lookupCapabilities("PlaybackController", false, cookie));
191
+ // debug("Acc", accessory);
192
+ // endpointId: new Buffer(this.id + "-" + this.homebridge + "-" + accessory.info.Manufacturer + "-" + playback + "-00000049-0000-1000-8000-0026BB765291").toString('base64'),
193
+ list = list.concat({
194
+ endpointId: Buffer.from(this.id + "-" + this.homebridge + "-" + accessory.info.Manufacturer + "-" + playback + "-00000049-0000-1000-8000-0026BB765291").toString('base64').replace('/', ''),
195
+ friendlyName: playback,
196
+ description: this.homebridge + " " + playback + " " + messages.normalizeName(service),
197
+ manufacturerName: accessory.info.Manufacturer,
198
+ displayCategories: messages.lookupDisplayCategory(service),
199
+ cookie: cookie,
200
+ capabilities: capabilities
201
+ });
202
+ }
203
+ }
204
+
205
+ // Get all the remaining devices
206
+
207
+ for (var index in this.accessories) {
208
+ var accessory = this.accessories[index];
209
+ if (accessory.playback) {
210
+ // debug("Media device", accessory.name);
211
+ }
212
+ var alexa = accessory.toAlexa({
213
+ deviceID: this.deviceID,
214
+
215
+ homebridge: this.homebridge,
216
+ id: this.id,
217
+ opt: opt
218
+ });
219
+ // debug("Alexa", alexa);
220
+ if (alexa) {
221
+ list = list.concat(alexa);
222
+ }
223
+ }
224
+ return (list);
225
+ };
@@ -0,0 +1,130 @@
1
+ var debug = require('debug')('alexa:Homebridges');
2
+ var Homebridge = require('./Homebridge.js').Homebridge;
3
+ // var messageUtil = require('../util/messageUtil');
4
+ var messages = require('./messages');
5
+
6
+ module.exports = {
7
+ Homebridges: Homebridges
8
+ };
9
+
10
+ /*
11
+ * Homebridges -> Homebridge -> Accessory -> Service -> Characteristic
12
+ */
13
+
14
+ function Homebridges(devices, context) {
15
+ // debug("Homebridges", devices);
16
+ this.homebridges = [];
17
+ devices.forEach(function(element) {
18
+ var homebridge = new Homebridge(element, context);
19
+ this.homebridges.push(homebridge);
20
+ }.bind(this));
21
+ }
22
+
23
+ /**
24
+ * Homebridges.toList - description
25
+ *
26
+ * @param {type} opt description
27
+ * @return {type} description
28
+ */
29
+
30
+ Homebridges.prototype.toList = function(opt) {
31
+ var list = [];
32
+ for (var index in this.homebridges) {
33
+ var homebridge = this.homebridges[index];
34
+ // list.push(homebridge.toList());
35
+ list = list.concat(homebridge.toList(opt));
36
+ }
37
+
38
+ list.sort((a, b) => (a.sortName > b.sortName) ? 1 : ((b.sortName > a.sortName) ? -1 : 0));
39
+ // debug("opt",opt,list.length);
40
+ return (list);
41
+ };
42
+
43
+ Homebridges.prototype.toAlexa = function(opt, message) {
44
+ var list = [];
45
+ for (var index in this.homebridges) {
46
+ var homebridge = this.homebridges[index];
47
+ // list.push(homebridge.toList());
48
+ list = list.concat(homebridge.toAlexa(opt));
49
+ }
50
+
51
+ list.sort((a, b) => (a.endpointId > b.endpointId) ? 1 : ((b.endpointId > a.endpointId) ? -1 : 0));
52
+ // debug("opt",opt,list.length);
53
+ // debug("MESSAGE", message);
54
+ var messageId = (message ? message.directive.header.messageId : '');
55
+ var response = {
56
+ "event": {
57
+ "header": {
58
+ "namespace": "Alexa.Discovery",
59
+ "name": "Discover.Response",
60
+ "payloadVersion": "3",
61
+ "messageId": messageId
62
+ },
63
+ "payload": {
64
+ "endpoints": list
65
+ }
66
+ }
67
+ };
68
+ // debug("PreCombine", JSON.stringify(list, null, 2));
69
+ if (opt.inputs) {
70
+ response = messages.inputs(opt, response);
71
+ }
72
+ if (opt.channel) {
73
+ response = messages.channel(opt, response);
74
+ }
75
+ if (opt.combine) {
76
+ response = messages.combine(opt, response);
77
+ }
78
+ // debug("toAlexa - Done");
79
+ return (response);
80
+ };
81
+
82
+ Homebridges.prototype.toEvents = function(endpoint) {
83
+ // debug("toEvents");
84
+ var list = [];
85
+ this.homebridges.forEach(function(homebridge) {
86
+ // debug("accessories", homebridge.accessories.length);
87
+ for (var index in homebridge.accessories) {
88
+ var accessory = homebridge.accessories[index];
89
+ // debug("services", accessory.services.length);
90
+ // accessory.services.forEach(function(service) {
91
+ for (var index in accessory.services) {
92
+ var service = accessory.services[index];
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);
100
+ }
101
+ }
102
+ }
103
+ }
104
+ });
105
+ if (endpoint) {
106
+ // debug("toEvents", endpoint, list[endpoint]);
107
+ return list[endpoint];
108
+ } else {
109
+ return (list);
110
+ }
111
+ };
112
+
113
+ /* {
114
+ "characteristics": [{
115
+ "aid": endpoint.aid,
116
+ "iid": endpoint.iid,
117
+ "ev": true
118
+ }]
119
+ };
120
+ */
121
+
122
+ Homebridges.prototype.findDevice = function(node) {
123
+ var list = [];
124
+ for (var index in this.homebridges) {
125
+ var homebridge = this.homebridges[index];
126
+ // list.push(homebridge.toList());
127
+ list = list.concat(homebridge.toList());
128
+ }
129
+ return (list.find(x => x.uniqueId === node));
130
+ };
@@ -0,0 +1,290 @@
1
+ var debug = require('debug')('Alexa:Service');
2
+ var Characteristic = require('./Characteristic.js').Characteristic;
3
+ var messages = require('./messages.js');
4
+
5
+ module.exports = {
6
+ Service: Service
7
+ };
8
+
9
+ /*
10
+ * Homebridges -> Homebridge -> Accessory -> Service -> Characteristic
11
+ */
12
+
13
+ function Service(devices, context) {
14
+ // debug("Service", context.info.Manufacturer, context.info.Name);
15
+ // context.speakers.some(function(element) {
16
+ // return (element.manufacturer === context.info.Manufacturer && element.name === context.info.Name);
17
+ // });
18
+ this.iid = devices.iid;
19
+ // Pre parser for Service overrides for services HomeKit doesn't support natively
20
+ if (context.options.speakers && context.options.speakers.some(function(element) {
21
+ return (element.manufacturer === context.info.Manufacturer && element.name === context.info.Name);
22
+ })) {
23
+ this.type = "00000113"; // HomeKit Speaker service
24
+ } else {
25
+ this.type = devices.type.substring(0, 8);
26
+ }
27
+ // debug("this.type", this.type);
28
+ this.serviceType = devices.type;
29
+ this.service = messages.normalizeName(this.type);
30
+ this.aid = context.aid;
31
+ this.deviceID = context.deviceID;
32
+ this.homebridge = context.homebridge;
33
+ this.id = context.id;
34
+ this.options = context.options;
35
+ this.info = context.info;
36
+ this.characteristics = [];
37
+ this.linked = devices.linked;
38
+ this.name = context.name;
39
+ var endpointReg = /[^\w|_|-|=|#|;|:|?|@|&]/g; // Invalid characters in endpointid
40
+ this.endpointID = Buffer.from(this.id + "-" + context.homebridge + "-" + context.info.Manufacturer + "-" + context.info.Name + "-" + this.serviceType).toString('base64').replace(endpointReg, '#');
41
+ // this.endpointID = new Buffer(this.id + "-" + context.homebridge + "-" + context.info.Manufacturer + "-" + context.info.Name + "-" + this.serviceType).toString('base64');
42
+ // debug("First EP", this.id + "-" + context.homebridge + "-" + context.info.Manufacturer + "-" + context.info.Name + "-" + this.serviceType);
43
+
44
+ switch (this.serviceType.substring(0, 8)) {
45
+ case "00000111": // Ignore camera services
46
+ case "00000110":
47
+ break;
48
+ default:
49
+ // First pass to grab service names
50
+ devices.characteristics.forEach(function(element) {
51
+ if (element.type.substring(0, 8) === '00000023' && element.description === "Name") {
52
+ // debug("context.info.Manufacturer %s -> %s -> %s", context.info.Manufacturer, context.name, element.value);
53
+
54
+ // Fix for issue #218 - Nest devices with duplicate's
55
+ if (element.value) {
56
+ this.name = element.value;
57
+ } else {
58
+ this.name = context.info.Name;
59
+ }
60
+ this.EPname = this.name;
61
+ if (context.info.Manufacturer === "Nest") {
62
+ this.name = context.name + " " + element.value;
63
+ this.EPname = context.name + " " + element.value;
64
+ } else if (context.info.Manufacturer === "LG Electronics Inc.") {
65
+ // Fix for issue #284 - LG TV's with duplicate's
66
+ // debug("Issue #284 Name %s - %s", element.value, context.info.Name);
67
+ // debug("issue #284 Manufacturer %s -> %s -> %s", context.info.Manufacturer, context.name, element.value);
68
+ this.EPname = context.name + " " + element.value;
69
+ }
70
+
71
+ this.endpointID = Buffer.from(this.id + "-" + context.homebridge + "-" + context.info.Manufacturer + "-" + this.EPname + "-" + this.serviceType).toString('base64').replace(endpointReg, '#');
72
+ }
73
+ }.bind(this));
74
+ // second pass to grab service names
75
+ devices.characteristics.forEach(function(element) {
76
+ if (element.type.substring(0, 8) === '00000023' && element.description === "Name") {
77
+ // second pass, no need to grab names
78
+ } else {
79
+ var service = new Characteristic(element, this);
80
+ if (this.characteristics[service.description]) {
81
+ // debug("Duplicate", this.name, this.serviceType, service.description);
82
+ } else {
83
+ // debug("Adding", this.name, this.serviceType, service.iid, service);
84
+ this.characteristics[service.description] = service;
85
+ }
86
+ }
87
+ }.bind(this));
88
+ }
89
+ if (messages.isAppleTV(this) || messages.isYamaha(this)) {
90
+ this.playback = true;
91
+ } else {
92
+ this.playback = false;
93
+ }
94
+ }
95
+
96
+ Service.prototype.toList = function(context) {
97
+ var descriptions;
98
+ var getCharacteristics;
99
+ var putCharacteristics = [];
100
+ var eventRegisters = [];
101
+ var characteristics = {};
102
+
103
+ if (this.name) {
104
+ context.name = this.name;
105
+ }
106
+ for (var index in this.characteristics) {
107
+ var characteristic = this.characteristics[index];
108
+ // debug("characteristic", characteristic)
109
+ // debug("perms", context.opt);
110
+ // debug("perms", (context.opt ? "perms" + context.opt.perms + characteristic.perms.includes(context.opt.perms) : "noperms"));
111
+ if (characteristic.type !== '00000023' && (context.opt ? characteristic.perms.includes(context.opt.perms) : true)) {
112
+ // debug("Yes", context.name, characteristic.description, characteristic.perms);
113
+ descriptions = (descriptions ? descriptions + ',' : '') + characteristic.description;
114
+ getCharacteristics = (getCharacteristics ? getCharacteristics + ',' : '') + characteristic.getCharacteristic;
115
+ // characteristics = (characteristics ? characteristics + ',' : '') + characteristic.characteristic;
116
+ characteristics = Object.assign(characteristics, characteristic.characteristic);
117
+ putCharacteristics = putCharacteristics.concat(characteristic.putCharacteristic);
118
+ eventRegisters = eventRegisters.concat(characteristic.eventRegister);
119
+ } else {
120
+ // debug("No", context.name, characteristic.description, characteristic.perms);
121
+ }
122
+ }
123
+ if (this.service && descriptions) {
124
+ return ({
125
+ homebridge: context.homebridge,
126
+ deviceID: context.deviceID,
127
+ id: context.id,
128
+ manufacturer: context.manufacturer,
129
+ aid: this.aid,
130
+ type: this.type,
131
+ name: context.name,
132
+ service: this.service,
133
+ fullName: context.name + ' - ' + this.service,
134
+ sortName: context.name + ':' + this.service,
135
+ uniqueId: context.homebridge + this.id + context.manufacturer + context.name + this.type,
136
+ descriptions: descriptions,
137
+ characteristics: characteristics,
138
+ getCharacteristics: getCharacteristics,
139
+ eventRegisters: eventRegisters
140
+ });
141
+ }
142
+ };
143
+
144
+ Service.prototype.toCookie = function(characteristic, context, value) {
145
+ // debug("toCookie", this.characteristics[characteristic], characteristic, context);
146
+ // var iid = this.characteristics[characteristic].iid;
147
+ if (value === undefined) value = 1;
148
+ switch (characteristic) {
149
+ /*
150
+ case "ReportState":
151
+ return (messages.reportState("Alexa.PlaybackController", {
152
+ "deviceID": context.deviceID,
153
+ "aid": context.aid,
154
+ "liid": this.characteristics["On"].iid
155
+ }));
156
+ */
157
+ default:
158
+ return (messages.cookieV(value, {
159
+ "deviceID": context.deviceID,
160
+ "aid": context.aid,
161
+ "liid": this.characteristics[characteristic].iid
162
+ }));
163
+ }
164
+ };
165
+
166
+ Service.prototype.toAlexa = function(context) {
167
+ var cookie = {};
168
+ var capabilities = [];
169
+ var reportState = [];
170
+
171
+ if (this.name) {
172
+ context.name = this.name;
173
+ }
174
+
175
+ if (this.playback) {
176
+ // debug("Skipping Media Control Button", context.name);
177
+ } else {
178
+ for (var index in this.characteristics) {
179
+ var characteristic = this.characteristics[index];
180
+ if (characteristic.type !== '00000023' && characteristic.capabilities) {
181
+ // debug("Yes", context.name, characteristic.aid, characteristic.iid);
182
+ cookie = Object.assign(cookie, characteristic.cookie);
183
+ capabilities = capabilities.concat(characteristic.capabilities);
184
+ reportState = reportState.concat(characteristic.reportState);
185
+ } else {
186
+ // debug("No", context.name, characteristic.description, characteristic.perms);
187
+ }
188
+ }
189
+ }
190
+
191
+ // Special devices that span mulitple getCharacteristics
192
+ // debug("Service", this.service);
193
+ try {
194
+ switch (this.service) {
195
+ case "Lightbulb":
196
+ // If a lightbulb has a Hue characteristic, it is a color bulb
197
+ if (this.characteristics["Hue"]) {
198
+ reportState.push({
199
+ "interface": "Alexa.ColorController",
200
+ "deviceID": this.deviceID,
201
+
202
+ "hue": this.characteristics["Hue"].getCharacteristic,
203
+ "saturation": this.characteristics["Saturation"].getCharacteristic,
204
+ "brightness": this.characteristics["Brightness"].getCharacteristic,
205
+ "on": this.characteristics["On"].getCharacteristic
206
+ });
207
+ cookie["SetColor"] = JSON.stringify({
208
+ "deviceID": this.deviceID,
209
+
210
+ "hue": this.characteristics["Hue"].getCharacteristic,
211
+ "saturation": this.characteristics["Saturation"].getCharacteristic,
212
+ "brightness": this.characteristics["Brightness"].getCharacteristic,
213
+ "on": this.characteristics["On"].getCharacteristic
214
+ });
215
+ capabilities = capabilities.concat(messages.lookupCapabilities("ColorController", context.events));
216
+ }
217
+ break;
218
+ case "Heater Cooler":
219
+ case "Thermostat":
220
+ /*
221
+ reportState.push({
222
+ "interface": "Alexa.ThermostatController",
223
+ "host": this.host,
224
+
225
+ "aid": this.aid
226
+ });
227
+ */
228
+ capabilities = capabilities.concat(messages.lookupCapabilities("ThermostatController", context.events, cookie));
229
+ break;
230
+ case "Temperature Sensor":
231
+ // Fix for issue #237
232
+ // "friendlyName": "Dyson Pure Cool Link",
233
+ // "description": "parseTest Dyson Pure Cool Link Temperature Sensor",
234
+ // "manufacturerName": "Dyson",
235
+ if (context.manufacturer === "Dyson") {
236
+ context.name = context.name + " " + this.service;
237
+ }
238
+ break;
239
+ case "Input Source":
240
+ // debug("Input Source", this.characteristics);
241
+ cookie[normalizeInput(this.characteristics["Configured Name"].value)] = messages.cookieV(this.characteristics["Identifier"].value, context);
242
+ capabilities = capabilities.concat(messages.lookupCapabilities("Input Source", context.events, cookie));
243
+ break;
244
+ }
245
+ } catch (err) {
246
+ debug("Warning: Accessory parsing error: %s -> %s", context.name, context.manufacturer);
247
+ }
248
+
249
+ cookie["ReportState"] = JSON.stringify(reportState);
250
+ if (capabilities.length > 0) {
251
+ capabilities.unshift({
252
+ "type": "AlexaInterface",
253
+ "interface": "Alexa",
254
+ "version": "3"
255
+ });
256
+ // debug("Final EP", this.id + "-" + context.homebridge + "-" + context.manufacturer + "-" + context.name + "-" + this.serviceType);
257
+ // debug('context:', context);
258
+ if (!context.name || context.name.trim() === "") {
259
+ console.log("ERROR: Empty accessory name, parsing failed.", context);
260
+ }
261
+ return ({
262
+ endpointId: this.endpointID,
263
+ friendlyName: context.name,
264
+ description: context.homebridge + " " + context.name + " " + this.service,
265
+ manufacturerName: context.manufacturer,
266
+ displayCategories: messages.lookupDisplayCategory(this.type),
267
+ cookie: cookie,
268
+ capabilities: capabilities
269
+ });
270
+ } else if (this.service === "Input Source") {
271
+ return ("Input");
272
+ }
273
+ };
274
+
275
+ function normalizeInput(input) {
276
+ var response = input;
277
+ switch (input) {
278
+ case "HDMI1":
279
+ case "HDMI2":
280
+ case "HDMI3":
281
+ case "HDMI4":
282
+ response = "HDMI " + input.substring(4, 5);
283
+ break;
284
+ case "Netflix":
285
+ case "TV NETFLIX":
286
+ response = "HDMI 9";
287
+ break;
288
+ }
289
+ return response;
290
+ }