mirror of
https://github.com/mtan93/homebridge.git
synced 2026-04-09 22:04:45 +01:00
Merge remote-tracking branch 'nfarina/master'
This commit is contained in:
14
lib/api.js
14
lib/api.js
@@ -20,7 +20,7 @@ function API() {
|
|||||||
this._dynamicPlatforms = {}; // this._dynamicPlatforms[pluginName.platformName] = platform constructor
|
this._dynamicPlatforms = {}; // this._dynamicPlatforms[pluginName.platformName] = platform constructor
|
||||||
|
|
||||||
// expose the homebridge API version
|
// expose the homebridge API version
|
||||||
this.version = 2.0;
|
this.version = 2.1;
|
||||||
|
|
||||||
// expose the User class methods to plugins to get paths. Example: homebridge.user.storagePath()
|
// expose the User class methods to plugins to get paths. Example: homebridge.user.storagePath()
|
||||||
this.user = User;
|
this.user = User;
|
||||||
@@ -85,6 +85,18 @@ API.prototype.registerAccessory = function(pluginName, accessoryName, constructo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
API.prototype.publishCameraAccessories = function(pluginName, accessories) {
|
||||||
|
for (var index in accessories) {
|
||||||
|
var accessory = accessories[index];
|
||||||
|
if (!(accessory instanceof PlatformAccessory)) {
|
||||||
|
throw new Error(pluginName + " attempt to register an accessory that isn\'t PlatformAccessory!");
|
||||||
|
}
|
||||||
|
accessory._associatedPlugin = pluginName;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.emit('publishCameraAccessories', accessories);
|
||||||
|
}
|
||||||
|
|
||||||
API.prototype.platform = function(name) {
|
API.prototype.platform = function(name) {
|
||||||
|
|
||||||
// if you passed the "short form" name like "Lockitron" instead of "homebridge-lockitron.Lockitron",
|
// if you passed the "short form" name like "Lockitron" instead of "homebridge-lockitron.Lockitron",
|
||||||
|
|||||||
@@ -130,8 +130,21 @@ PlatformAccessory.prototype.updateReachability = function(reachable) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlatformAccessory.prototype.configureCameraSource = function(cameraSource) {
|
||||||
|
this.cameraSource = cameraSource;
|
||||||
|
for (var index in cameraSource.services) {
|
||||||
|
var service = cameraSource.services[index];
|
||||||
|
this.addService(service);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PlatformAccessory.prototype._prepareAssociatedHAPAccessory = function () {
|
PlatformAccessory.prototype._prepareAssociatedHAPAccessory = function () {
|
||||||
this._associatedHAPAccessory = new Accessory(this.displayName, this.UUID);
|
this._associatedHAPAccessory = new Accessory(this.displayName, this.UUID);
|
||||||
|
|
||||||
|
if (this.cameraSource) {
|
||||||
|
this._associatedHAPAccessory.configureCameraSource(this.cameraSource);
|
||||||
|
}
|
||||||
|
|
||||||
this._associatedHAPAccessory._sideloadServices(this.services);
|
this._associatedHAPAccessory._sideloadServices(this.services);
|
||||||
this._associatedHAPAccessory.category = this.category;
|
this._associatedHAPAccessory.category = this.category;
|
||||||
this._associatedHAPAccessory.reachable = this.reachable;
|
this._associatedHAPAccessory.reachable = this.reachable;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ var PlatformAccessory = require("./platformAccessory").PlatformAccessory;
|
|||||||
var BridgeSetupManager = require("./bridgeSetupManager").BridgeSetupManager;
|
var BridgeSetupManager = require("./bridgeSetupManager").BridgeSetupManager;
|
||||||
var log = require("./logger")._system;
|
var log = require("./logger")._system;
|
||||||
var Logger = require('./logger').Logger;
|
var Logger = require('./logger').Logger;
|
||||||
|
var mac = require("./util/mac");
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@@ -40,6 +41,10 @@ function Server(insecureAccess) {
|
|||||||
this._handleUnregisterPlatformAccessories(accessories);
|
this._handleUnregisterPlatformAccessories(accessories);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
this._api.on('publishCameraAccessories', function(accessories) {
|
||||||
|
this._handlePublishCameraAccessories(accessories);
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
this._plugins = this._loadPlugins(); // plugins[name] = Plugin instance
|
this._plugins = this._loadPlugins(); // plugins[name] = Plugin instance
|
||||||
this._config = this._loadConfig();
|
this._config = this._loadConfig();
|
||||||
this._cachedPlatformAccessories = this._loadCachedPlatformAccessories();
|
this._cachedPlatformAccessories = this._loadCachedPlatformAccessories();
|
||||||
@@ -47,6 +52,7 @@ function Server(insecureAccess) {
|
|||||||
|
|
||||||
this._activeDynamicPlugins = {};
|
this._activeDynamicPlugins = {};
|
||||||
this._configurablePlatformPlugins = {};
|
this._configurablePlatformPlugins = {};
|
||||||
|
this._publishedCameras = {};
|
||||||
this._setupManager = new BridgeSetupManager();
|
this._setupManager = new BridgeSetupManager();
|
||||||
this._setupManager.on('newConfig', this._handleNewConfig.bind(this));
|
this._setupManager.on('newConfig', this._handleNewConfig.bind(this));
|
||||||
|
|
||||||
@@ -97,14 +103,16 @@ Server.prototype._publish = function() {
|
|||||||
info.setCharacteristic(Characteristic.SerialNumber, bridgeConfig.serialNumber);
|
info.setCharacteristic(Characteristic.SerialNumber, bridgeConfig.serialNumber);
|
||||||
|
|
||||||
this._printPin(bridgeConfig.pin);
|
this._printPin(bridgeConfig.pin);
|
||||||
|
|
||||||
|
this._bridge.on('listening', function(port) {
|
||||||
|
log.info("Homebridge is running on port %s.", port);
|
||||||
|
});
|
||||||
|
|
||||||
this._bridge.publish({
|
this._bridge.publish({
|
||||||
username: bridgeConfig.username || "CC:22:3D:E3:CE:30",
|
username: bridgeConfig.username || "CC:22:3D:E3:CE:30",
|
||||||
port: bridgeConfig.port || 51826,
|
|
||||||
pincode: bridgeConfig.pin || "031-45-154",
|
pincode: bridgeConfig.pin || "031-45-154",
|
||||||
category: Accessory.Categories.BRIDGE
|
category: Accessory.Categories.BRIDGE
|
||||||
}, this._allowInsecureAccess);
|
}, this._allowInsecureAccess);
|
||||||
|
|
||||||
log.info("Homebridge is running on port %s.", bridgeConfig.port || 51826);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Server.prototype._loadPlugins = function(accessories, platforms) {
|
Server.prototype._loadPlugins = function(accessories, platforms) {
|
||||||
@@ -165,7 +173,6 @@ Server.prototype._loadConfig = function() {
|
|||||||
config.bridge = {
|
config.bridge = {
|
||||||
"name": "Homebridge",
|
"name": "Homebridge",
|
||||||
"username": "CC:22:3D:E3:CE:30",
|
"username": "CC:22:3D:E3:CE:30",
|
||||||
"port": 51826,
|
|
||||||
"pin": "031-45-154"
|
"pin": "031-45-154"
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -454,6 +461,34 @@ Server.prototype._handleUnregisterPlatformAccessories = function(accessories) {
|
|||||||
this._updateCachedAccessories();
|
this._updateCachedAccessories();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Server.prototype._handlePublishCameraAccessories = function(accessories) {
|
||||||
|
var accessoryPin = (this._config.bridge || {}).pin || "031-45-154";
|
||||||
|
|
||||||
|
for (var index in accessories) {
|
||||||
|
var accessory = accessories[index];
|
||||||
|
|
||||||
|
accessory._prepareAssociatedHAPAccessory();
|
||||||
|
var hapAccessory = accessory._associatedHAPAccessory;
|
||||||
|
var advertiseAddress = mac.generate(accessory.UUID);
|
||||||
|
|
||||||
|
if (this._publishedCameras[advertiseAddress]) {
|
||||||
|
throw new Error("Camera accessory %s experienced an address collision.", accessory.displayName);
|
||||||
|
} else {
|
||||||
|
this._publishedCameras[advertiseAddress] = accessory;
|
||||||
|
}
|
||||||
|
|
||||||
|
hapAccessory.on('listening', function(port) {
|
||||||
|
log.info("%s is running on port %s.", accessory.displayName, port);
|
||||||
|
});
|
||||||
|
|
||||||
|
hapAccessory.publish({
|
||||||
|
username: advertiseAddress,
|
||||||
|
pincode: accessoryPin,
|
||||||
|
category: accessory.category
|
||||||
|
}, this._allowInsecureAccess);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Server.prototype._updateCachedAccessories = function() {
|
Server.prototype._updateCachedAccessories = function() {
|
||||||
var serializedAccessories = [];
|
var serializedAccessories = [];
|
||||||
|
|
||||||
|
|||||||
18
lib/util/mac.js
Normal file
18
lib/util/mac.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
var crypto = require('crypto');
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
generate: generate
|
||||||
|
}
|
||||||
|
|
||||||
|
function generate(data) {
|
||||||
|
var sha1sum = crypto.createHash('sha1');
|
||||||
|
sha1sum.update(data);
|
||||||
|
var s = sha1sum.digest('hex');
|
||||||
|
var i = -1;
|
||||||
|
return 'xx:xx:xx:xx:xx:xx'.replace(/[x]/g, function(c) {
|
||||||
|
i += 1;
|
||||||
|
return s[i];
|
||||||
|
}).toUpperCase();
|
||||||
|
};
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "homebridge",
|
"name": "homebridge",
|
||||||
"description": "HomeKit support for the impatient",
|
"description": "HomeKit support for the impatient",
|
||||||
"version": "0.3.4",
|
"version": "0.4.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "DEBUG=* ./bin/homebridge -D -P example-plugins/ || true"
|
"dev": "DEBUG=* ./bin/homebridge -D -P example-plugins/ || true"
|
||||||
},
|
},
|
||||||
@@ -20,13 +20,13 @@
|
|||||||
"homebridge": "bin/homebridge"
|
"homebridge": "bin/homebridge"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.12.0"
|
"node": ">=4.3.2"
|
||||||
},
|
},
|
||||||
"preferGlobal": true,
|
"preferGlobal": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^1.1.1",
|
"chalk": "^1.1.1",
|
||||||
"commander": "2.8.1",
|
"commander": "2.8.1",
|
||||||
"hap-nodejs": "0.3.2",
|
"hap-nodejs": "0.4.6",
|
||||||
"semver": "5.0.3",
|
"semver": "5.0.3",
|
||||||
"node-persist": "^0.0.8"
|
"node-persist": "^0.0.8"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user