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/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "homebridge-alexa",
3
+ "version": "0.5.48",
4
+ "description": "Control your Homebridge devices with Amazon Alexa.",
5
+ "main": "plugin.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "api": "documentation build plugin.js lib/alexaActions.js lib/alexaLocal.js lib/alexaMessages.js lib/alexaTranslator.js -f md --config docs/documentation.yml > docs/API.md",
9
+ "document": "./gh-md-toc --insert README.md;./gh-md-toc --insert Troubleshooting.md",
10
+ "watch": "nodemon"
11
+ },
12
+ "nodemonConfig": {
13
+ "watch": [],
14
+ "ext": "js",
15
+ "ignore": [],
16
+ "exec": "~/npm/bin/homebridge -D -R -P ~/Code",
17
+ "signal": "SIGTERM",
18
+ "env": {
19
+ "NODE_OPTIONS": "--trace-warnings"
20
+ }
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/NorthernMan54/homebridge-alexa.git"
25
+ },
26
+ "keywords": [
27
+ "alexa",
28
+ "homebridge-plugin"
29
+ ],
30
+ "engines": {
31
+ "node": ">=4.4.5",
32
+ "homebridge": ">=0.4.16"
33
+ },
34
+ "devDependencies": {
35
+ "documentation": "^13.0.2",
36
+ "nodemon": "^2.0.4"
37
+ },
38
+ "dependencies": {
39
+ "@oznu/hap-client": "^1.7.2",
40
+ "bottleneck": ">=2.18.0",
41
+ "debug": ">2.6.9",
42
+ "hap-node-client": ">=0.1.16",
43
+ "is-my-json-valid": ">=2.19.0",
44
+ "mqtt": ">=2.18.8"
45
+ },
46
+ "author": "NorthernMan54",
47
+ "license": "Apache-2.0",
48
+ "bugs": {
49
+ "url": "https://github.com/NorthernMan54/homebridge-alexa/issues"
50
+ },
51
+ "homepage": "https://github.com/NorthernMan54/homebridge-alexa#readme"
52
+ }
package/plugin.js ADDED
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ // var debug = require('debug')('alexaPlugin');
3
+
4
+ var AlexaLocal = require('./lib/alexaLocal.js').alexaLocal;
5
+ var alexaActions = require('./lib/alexaActions.js');
6
+ var EventEmitter = require('events').EventEmitter;
7
+ var os = require("os");
8
+
9
+ const packageConfig = require('./package.json');
10
+ let Service, Characteristic;
11
+
12
+ var options = {};
13
+ var alexaService;
14
+
15
+ module.exports = function(homebridge) {
16
+ Service = homebridge.hap.Service;
17
+ Characteristic = homebridge.hap.Characteristic;
18
+
19
+ homebridge.registerPlatform("homebridge-alexa", "Alexa", alexaHome);
20
+ };
21
+
22
+ function alexaHome(log, config, api) {
23
+ this.log = log;
24
+ this.eventBus = new EventEmitter();
25
+ this.config = config;
26
+ this.pin = config['pin'] || "031-45-154";
27
+ this.username = config['username'] || false;
28
+ this.password = config['password'] || false;
29
+ this.filter = config['filter'];
30
+ this.beta = config['beta'] || false;
31
+ this.events = config['routines'] || false;
32
+ this.combine = config['combine'] || false;
33
+ this.oldParser = config['oldParser'] || false;
34
+ this.refresh = config['refresh'] || 60 * 15; // Value in seconds, default every 15 minute's
35
+ this.speakers = config['speakers'] || false; // Array of speaker devices
36
+ this.inputs = config['inputs'] || false; // Array of input devices
37
+ this.channel = config['channel'] || false; // Array of input devices
38
+ this.blind = config['blind'] || false; // Use range controller for Blinds
39
+ this.deviceListHandling = config['deviceListHandling'] || []; // Use ea
40
+ this.deviceList = config['deviceList'] || []; // Use ea
41
+ this.door = config['door'] || false; // Use mode controller for Garage Doors
42
+ this.name = config['name'] || "homebridgeAlexa";
43
+ this.keepalive = config['keepalive'] || 1200; // MQTT Connection Keepalive
44
+
45
+ // Enable config based DEBUG logging enable
46
+ this.debug = config['debug'] || false;
47
+ if (this.debug) {
48
+ let debugEnable = require('debug');
49
+ let namespaces = debugEnable.disable();
50
+
51
+ // this.log("DEBUG-1", namespaces);
52
+ if (namespaces) {
53
+ namespaces = namespaces + ',alexa*';
54
+ } else {
55
+ namespaces = 'alexa*';
56
+ }
57
+ // this.log("DEBUG-2", namespaces);
58
+ debugEnable.enable(namespaces);
59
+ }
60
+
61
+ if (!this.username || !this.password) {
62
+ this.log.error("Missing username and password");
63
+ }
64
+
65
+ if (this.oldParser) {
66
+ this.log.error("ERROR: oldParser was deprecated with version 0.5.0, defaulting to new Parser.");
67
+ }
68
+
69
+ if (api) {
70
+ this.api = api;
71
+ this.api.on('didFinishLaunching', this.didFinishLaunching.bind(this));
72
+ }
73
+
74
+ this.log.info(
75
+ '%s v%s, node %s, homebridge v%s',
76
+ packageConfig.name, packageConfig.version, process.version, api.serverVersion
77
+ );
78
+ }
79
+
80
+ alexaHome.prototype = {
81
+ accessories: function(callback) {
82
+ // this.log("Accessories");
83
+ var accessories = [];
84
+ accessories.push(new AlexaService(this.name, this.log));
85
+ callback(accessories);
86
+ }
87
+ };
88
+
89
+ alexaHome.prototype.didFinishLaunching = function() {
90
+ var host = 'alexa.homebridge.ca';
91
+ if (this.beta) {
92
+ host = 'alexabeta.homebridge.ca';
93
+ }
94
+ options = {
95
+ // Shared Options
96
+ log: this.log,
97
+ debug: this.debug,
98
+ // MQTT Options
99
+ username: this.username,
100
+ password: this.password,
101
+ servers: [{
102
+ protocol: 'mqtt',
103
+ host: host,
104
+ port: 1883
105
+ }],
106
+ reconnectPeriod: 65000,
107
+ keepalive: this.keepalive, // Reduce client timeout to 10 minutes
108
+ // HAP Node Client options
109
+ pin: this.pin,
110
+ refresh: this.refresh,
111
+ eventBus: this.eventBus,
112
+ // HB Parser options
113
+ oldParser: this.oldParser,
114
+ combine: this.combine,
115
+ speakers: this.speakers,
116
+ filter: this.filter,
117
+ alexaService: alexaService,
118
+ Characteristic: Characteristic,
119
+ inputs: this.inputs,
120
+ channel: this.channel,
121
+ blind: this.blind,
122
+ deviceListHandling: this.deviceListHandling,
123
+ deviceList: this.deviceList,
124
+ door: this.door,
125
+ // Other Options
126
+ events: this.events
127
+ };
128
+
129
+ // Initialize HAP Connections
130
+ alexaActions.hapDiscovery(options);
131
+
132
+ var alexa = new AlexaLocal(options);
133
+
134
+ // Homebridge HAP Node Events
135
+
136
+ this.eventBus.on('hapEvent', alexaActions.alexaEvent.bind(this));
137
+
138
+ // Alexa mesages
139
+
140
+ this.eventBus.on('System', function(message) {
141
+ this.log.error("ERROR: ", message.directive.header.message);
142
+ }.bind(this));
143
+ this.eventBus.on('Alexa', alexaActions.alexaMessage.bind(this));
144
+ this.eventBus.on('Alexa.Discovery', alexaActions.alexaDiscovery.bind(this));
145
+ this.eventBus.on('Alexa.PowerController', alexaActions.alexaPowerController.bind(this));
146
+ this.eventBus.on('Alexa.PowerLevelController', alexaActions.alexaPowerLevelController.bind(this));
147
+ this.eventBus.on('Alexa.ColorController', alexaActions.alexaColorController.bind(this));
148
+ this.eventBus.on('Alexa.ColorTemperatureController', alexaActions.alexaColorTemperatureController.bind(this));
149
+ this.eventBus.on('Alexa.PlaybackController', alexaActions.alexaPlaybackController.bind(this));
150
+ this.eventBus.on('Alexa.Speaker', alexaActions.alexaSpeaker.bind(this));
151
+ this.eventBus.on('Alexa.ThermostatController', alexaActions.alexaThermostatController.bind(this));
152
+ this.eventBus.on('Alexa.LockController', alexaActions.alexaLockController.bind(this));
153
+ this.eventBus.on('Alexa.ChannelController', alexaActions.alexaChannelController.bind(this));
154
+ this.eventBus.on('Alexa.StepSpeaker', alexaActions.alexaStepSpeaker.bind(this));
155
+ this.eventBus.on('Alexa.InputController', alexaActions.alexaInputController.bind(this));
156
+ this.eventBus.on('Alexa.ModeController', alexaActions.alexaModeController.bind(this));
157
+ this.eventBus.on('Alexa.RangeController', alexaActions.alexaRangeController.bind(this));
158
+ };
159
+
160
+ /*
161
+ alexaHome.prototype.configureAccessory = function(accessory) {
162
+ this.log("configureAccessory");
163
+ // callback();
164
+ };
165
+ */
166
+
167
+ function AlexaService(name, log) {
168
+ this.name = name;
169
+ this.log = log;
170
+ }
171
+
172
+ AlexaService.prototype = {
173
+ getServices: function() {
174
+ // this.log("getServices", this.name);
175
+ // Information Service
176
+ var informationService = new Service.AccessoryInformation();
177
+ var hostname = os.hostname();
178
+
179
+ informationService
180
+ .setCharacteristic(Characteristic.Manufacturer, "homebridge-alexa")
181
+ .setCharacteristic(Characteristic.SerialNumber, hostname)
182
+ .setCharacteristic(Characteristic.FirmwareRevision, require('./package.json').version);
183
+ // Thermostat Service
184
+
185
+ alexaService = new Service.ContactSensor(this.name);
186
+
187
+ return [informationService, alexaService];
188
+ }
189
+ };