mirror of
https://github.com/mtan93/homebridge.git
synced 2026-03-08 21:02:38 +00:00
init design
This commit is contained in:
@@ -15,6 +15,7 @@ var PlatformAccessory = require("./platformAccessory").PlatformAccessory;
|
||||
var BridgeSetupManager = require("./bridgeSetupManager").BridgeSetupManager;
|
||||
var log = require("./logger")._system;
|
||||
var Logger = require('./logger').Logger;
|
||||
var mac = require("./util/mac");
|
||||
|
||||
'use strict';
|
||||
|
||||
@@ -40,6 +41,10 @@ function Server(insecureAccess) {
|
||||
this._handleUnregisterPlatformAccessories(accessories);
|
||||
}.bind(this));
|
||||
|
||||
this._api.on('publishCameraAccessories', function(accessories) {
|
||||
this._handlePublishCameraAccessories(accessories);
|
||||
}.bind(this));
|
||||
|
||||
this._plugins = this._loadPlugins(); // plugins[name] = Plugin instance
|
||||
this._config = this._loadConfig();
|
||||
this._cachedPlatformAccessories = this._loadCachedPlatformAccessories();
|
||||
@@ -97,14 +102,16 @@ Server.prototype._publish = function() {
|
||||
info.setCharacteristic(Characteristic.SerialNumber, bridgeConfig.serialNumber);
|
||||
|
||||
this._printPin(bridgeConfig.pin);
|
||||
|
||||
this._bridge.on('listening', function(port) {
|
||||
log.info("Homebridge is running on port %s.", port);
|
||||
});
|
||||
|
||||
this._bridge.publish({
|
||||
username: bridgeConfig.username || "CC:22:3D:E3:CE:30",
|
||||
port: bridgeConfig.port || 51826,
|
||||
pincode: bridgeConfig.pin || "031-45-154",
|
||||
category: Accessory.Categories.BRIDGE
|
||||
}, this._allowInsecureAccess);
|
||||
|
||||
log.info("Homebridge is running on port %s.", bridgeConfig.port || 51826);
|
||||
}
|
||||
|
||||
Server.prototype._loadPlugins = function(accessories, platforms) {
|
||||
@@ -165,7 +172,6 @@ Server.prototype._loadConfig = function() {
|
||||
config.bridge = {
|
||||
"name": "Homebridge",
|
||||
"username": "CC:22:3D:E3:CE:30",
|
||||
"port": 51826,
|
||||
"pin": "031-45-154"
|
||||
};
|
||||
|
||||
@@ -454,6 +460,21 @@ Server.prototype._handleUnregisterPlatformAccessories = function(accessories) {
|
||||
this._updateCachedAccessories();
|
||||
}
|
||||
|
||||
Server.prototype._handlePublishCameraAccessories = function(accessories) {
|
||||
for (var index in accessories) {
|
||||
var accessory = accessories[index];
|
||||
|
||||
accessory._prepareAssociatedHAPAccessory();
|
||||
var hapAccessory = accessory._associatedHAPAccessory;
|
||||
|
||||
hapAccessory.publish({
|
||||
username: mac.generate(accessory.uuid),
|
||||
pincode: bridgeConfig.pin || "031-45-154",
|
||||
category: accessory.category
|
||||
}, this._allowInsecureAccess);
|
||||
}
|
||||
}
|
||||
|
||||
Server.prototype._updateCachedAccessories = function() {
|
||||
var serializedAccessories = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user