forked from G-On-dev/homebridge-g-on-alice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.js
96 lines (78 loc) · 2.39 KB
/
plugin.js
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
"use strict";
var AliceLocal = require('./lib/aliceLocal.js').aliceLocal;
var aliceActions = require('./lib/aliceActions.js');
var EventEmitter = require('events').EventEmitter;
// var debug = require('debug')('alicePlugin');
const packageConfig = require('./package.json');
var options = {};
module.exports = function(homebridge) {
homebridge.registerPlatform("homebridge-g-on-alice", "G-On Alice", aliceHome);
};
function aliceHome(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;
// 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 + ',g-on-alice*';
} else {
namespaces = 'g-on-alice*';
}
// 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
);
}
aliceHome.prototype = {
accessories: function(callback) {
this.log("accessories");
callback();
}
};
aliceHome.prototype.didFinishLaunching = function() {
var host = 'homebridge.g-on.io';
// var host = 'localhost';
options = {
eventBus: this.eventBus,
username: this.username,
password: this.password,
clientId: this.username,
debug: this.debug,
log: this.log,
pin: this.pin,
servers: [{
protocol: 'mqtt',
host: host,
port: 1883
}]
};
// Initialize HAP Connections
aliceActions.hapDiscovery(options);
var alice = new AliceLocal(options);
// Alice mesages
this.eventBus.on('discovery', aliceActions.aliceDiscovery.bind(this));
this.eventBus.on('action', aliceActions.aliceAction.bind(this));
this.eventBus.on('query', aliceActions.aliceQuery.bind(this));
};
aliceHome.prototype.configureAccessory = function(accessory) {
this.log("configureAccessory");
// callback();
};