forked from NorthernMan54/homebridge-alexa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.js
More file actions
128 lines (109 loc) · 4.09 KB
/
Copy pathplugin.js
File metadata and controls
128 lines (109 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
"use strict";
// var debug = require('debug')('alexaPlugin');
var AlexaLocal = require('./lib/alexaLocal.js').alexaLocal;
var alexaActions = require('./lib/alexaActions.js');
var EventEmitter = require('events').EventEmitter;
// var debug = require('debug')('alexaPlugin');
const packageConfig = require('./package.json');
var options = {};
module.exports = function(homebridge) {
homebridge.registerPlatform("homebridge-alexa", "Alexa", alexaHome);
};
function alexaHome(log, config, api) {
this.log = log;
this.eventBus = new EventEmitter();
this.config = config;
this.pin = config['pin'] || "031-45-154";
this.username = config['username'] || false;
this.password = config['password'] || false;
this.filter = config['filter'];
this.beta = config['beta'] || false;
this.events = config['routines'] || false;
this.combine = config['combine'] || false;
this.oldParser = config['oldParser'] || false;
this.refresh = config['refresh'] || 60 * 15; // Value in seconds, default every 15 minute's
this.speakers = config['speakers'] || false; // Array of speaker devices
// Enable config based DEBUG logging enable
this.debug = config['debug'] || false;
if (this.debug) {
let debugEnable = require('debug');
let namespaces = debugEnable.disable();
// this.log("DEBUG-1", namespaces);
if (namespaces) {
namespaces = namespaces + ',alexa*';
} else {
namespaces = 'alexa*';
}
// this.log("DEBUG-2", namespaces);
debugEnable.enable(namespaces);
}
if (!this.username || !this.password) {
this.log.error("Missing username and password");
}
if (api) {
this.api = api;
this.api.on('didFinishLaunching', this.didFinishLaunching.bind(this));
}
this.log.info(
'%s v%s, node %s, homebridge v%s',
packageConfig.name, packageConfig.version, process.version, api.serverVersion
);
}
alexaHome.prototype = {
accessories: function(callback) {
this.log("accessories");
callback();
}
};
alexaHome.prototype.didFinishLaunching = function() {
var host = 'alexa.homebridge.ca';
if (this.beta) {
host = 'alexabeta.homebridge.ca';
}
options = {
eventBus: this.eventBus,
username: this.username,
password: this.password,
// clientId: this.username,
debug: this.debug,
events: this.events,
log: this.log,
pin: this.pin,
refresh: this.refresh,
oldParser: this.oldParser,
reconnectPeriod: 5000,
combine: this.combine,
speakers: this.speakers,
filter: this.filter,
servers: [{
protocol: 'mqtt',
host: host,
port: 1883
}]
};
// Initialize HAP Connections
alexaActions.hapDiscovery(options);
var alexa = new AlexaLocal(options);
// Homebridge HAP Node Events
this.eventBus.on('hapEvent', alexaActions.alexaEvent.bind(this));
// Alexa mesages
this.eventBus.on('System', function(message) {
this.log.error("ERROR: ", message.directive.header.message);
}.bind(this));
this.eventBus.on('Alexa', alexaActions.alexaMessage.bind(this));
this.eventBus.on('Alexa.Discovery', alexaActions.alexaDiscovery.bind(this));
this.eventBus.on('Alexa.PowerController', alexaActions.alexaPowerController.bind(this));
this.eventBus.on('Alexa.PowerLevelController', alexaActions.alexaPowerLevelController.bind(this));
this.eventBus.on('Alexa.ColorController', alexaActions.alexaColorController.bind(this));
this.eventBus.on('Alexa.ColorTemperatureController', alexaActions.alexaColorTemperatureController.bind(this));
this.eventBus.on('Alexa.PlaybackController', alexaActions.alexaPlaybackController.bind(this));
this.eventBus.on('Alexa.Speaker', alexaActions.alexaSpeaker.bind(this));
this.eventBus.on('Alexa.ThermostatController', alexaActions.alexaThermostatController.bind(this));
this.eventBus.on('Alexa.LockController', alexaActions.alexaLockController.bind(this));
this.eventBus.on('Alexa.ChannelController', alexaActions.alexaChannelController.bind(this));
this.eventBus.on('Alexa.StepSpeaker', alexaActions.alexaStepSpeaker.bind(this));
};
alexaHome.prototype.configureAccessory = function(accessory) {
this.log("configureAccessory");
// callback();
};