46 Commits

Author SHA1 Message Date
Khaos Tian
63ab1025e9 Update hap-nodejs to allow homebridge work with nodejs v4.x 2016-11-03 12:20:46 -07:00
Khaos Tian
dc43d0b7c4 Update hap-nodejs
This version requires node v5.10.0 or later.
2016-11-01 18:33:59 -07:00
Khaos Tian
7c3543ba61 Merge pull request #839 from rxseger/collision-name
Fix camera name in collision error message
2016-10-09 17:14:29 -07:00
rxseger
5adb5f3282 Fix camera name in collision error message 2016-10-09 23:36:53 +00:00
Khaos Tian
fedd341970 0.4.6 2016-10-01 16:48:05 -07:00
Khaos Tian
c7c9aa0150 Bump hap-nodejs version. 2016-10-01 16:48:01 -07:00
Khaos Tian
e3e08414f6 0.4.5 2016-09-28 17:11:01 -07:00
Khaos Tian
ea9df45d2d Add back the ability to designate the port homebridge is running. 2016-09-28 17:10:52 -07:00
Khaos Tian
7425f8beca 0.4.4 2016-09-28 12:40:35 -07:00
Khaos Tian
dbb7b89cf9 0.4.3 2016-09-27 17:01:08 -07:00
Khaos Tian
4f000485db Bump hap-nodejs again... 2016-09-27 17:01:00 -07:00
Khaos Tian
c0884f484e 0.4.2 2016-09-27 12:36:29 -07:00
Khaos Tian
363c997058 Bump hap-nodejs version 2016-09-27 12:36:23 -07:00
Khaos Tian
0ccd80c8e7 0.4.1 2016-09-26 20:32:06 -07:00
Khaos Tian
ef8fe5ced2 Update hap-nodejs version to fix side load problem 2016-09-26 20:31:55 -07:00
Khaos Tian
4a531ede5c Merge pull request #805 from nfarina/ip-cam
IP Camera support for homebridge
2016-09-26 14:34:35 -07:00
Khaos Tian
ff35ece65c 0.4.0 2016-09-26 14:22:22 -07:00
Khaos Tian
66ea6e640d Minor Tweak 2016-09-26 14:15:12 -07:00
Khaos Tian
ecd06d7239 Bump api version 2016-09-26 13:19:50 -07:00
Khaos Tian
c89ff97ac5 init design 2016-09-26 13:01:29 -07:00
Khaos Tian
ceec4c74fd Merge pull request #803 from nfarina/use-hap-0.4
Use hap-nodejs 0.4.0
2016-09-26 12:02:32 -07:00
Jon Maddox
925c1630c4 bump hap-nodejs to 0.4.0 2016-09-26 10:46:21 -04:00
Khaos Tian
4eabc4ad52 Merge pull request #593 from PatchworkBoy/patch-1
Ref #582
2016-09-18 21:37:49 -07:00
Khaos Tian
c0859a29d3 Merge pull request #764 from alessiodionisi/new-bridge-configs
New bridge configs
2016-09-18 21:37:18 -07:00
Khaos Tian
c15707e875 Merge pull request #778 from nrobinson2000/patch-1
Some changes to the README
2016-09-18 21:36:42 -07:00
Nathan Robinson
8c476b45a0 Update README.md 2016-09-18 21:13:38 -04:00
Nick Farina
f49229d73c Update README to reflect the new iOS 10 Home app. 2016-09-15 21:05:39 -07:00
Khaos Tian
fbccc031f4 Merge pull request #770 from kcjonson/patch-1
Update README.md
2016-09-15 14:57:11 -07:00
Kevin Jonson
d70fa741d8 Update README.md 2016-09-15 14:07:09 -07:00
Alessio Dionisi
4740bf1fc5 New bridge configs
"bridge": {
    "manufacturer": "Manufacturer here",
    "serialNumber": "Serial number here",
    "model": "Model here"
}
2016-09-13 13:54:37 +02:00
Khaos Tian
da57b29972 Merge pull request #758 from cflurin/master
Warning config.json not found
2016-09-06 08:28:36 -07:00
cflurin
5944365bc6 Warning config.json not found 2016-09-06 14:49:53 +02:00
Khaos Tian
a8908fd9b8 Merge pull request #714 from EdJoPaTo/platformLog
optimized logging of the SamplePlatform example
2016-07-30 18:41:01 -07:00
Khaos Tian
8ef7e62094 Merge pull request #715 from EdJoPaTo/multiAccessories
fixed SamplePlatform crashes
2016-07-30 18:40:35 -07:00
Edgar To
15c8eaaf29 use of the own log method instead of the general console.log(); added accessory.displayName to the log output if possible/ useful 2016-07-24 22:43:21 +02:00
Edgar To
e6648375c7 different add times will create different UUIDs -> no crash with the second add call 2016-07-24 22:38:05 +02:00
Khaos Tian
a52bc9e437 Merge pull request #642 from alexbain/patch-1
Add note about --unsafe-perm
2016-05-22 18:35:12 -07:00
Alex Bain
b78c081cd4 Add note about --unsafe-perm
I received the following error when trying to install homebridge on a RaspberryPi. Assuming I'm not the first or the last to see this error, I thought adding a note to README about the --unsafe-perm flag would aid others.
2016-05-22 18:01:32 -07:00
Khaos Tian
87050a2267 update hap-nodejs dependency for node v6 2016-04-29 10:23:15 -07:00
Khaos Tian
35dfaabc69 update hap-nodejs dependency 2016-04-08 23:51:03 -07:00
Khaos Tian
77ce39e157 0.3.3 2016-04-08 23:50:34 -07:00
Khaos Tian
0af8a43dc9 Expose platform accessory category to hap-nodejs
Fix an error in plugin config look up
2016-04-08 23:50:18 -07:00
Marci
f203a2ac6f Ref #582
Ref#582 Add ‘--unsafe-perm’ flag to npm install command to get round all the .gyp warns etc.
2016-03-31 15:50:50 +01:00
Khaos Tian
620c8473b8 #572 2016-03-20 22:12:47 -07:00
Khaos Tian
b2f476f833 0.3.2 2016-03-20 21:53:01 -07:00
Khaos Tian
c6d2f889fc Update hap-nodejs version to solve #575 2016-03-20 21:52:56 -07:00
8 changed files with 129 additions and 40 deletions

View File

@@ -29,7 +29,11 @@ You can also chat with us in our nascent [Slack instance](http://homebridge-slac
Homebridge is published through [NPM](https://www.npmjs.com/package/homebridge) and should be installed "globally" by typing: Homebridge is published through [NPM](https://www.npmjs.com/package/homebridge) and should be installed "globally" by typing:
sudo npm install -g homebridge sudo npm install -g --unsafe-perm homebridge
You may need to use the `--unsafe-perm` flag if you receive an error similar to this:
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/5.5.0"
Now you should be able to run Homebridge: Now you should be able to run Homebridge:
@@ -45,9 +49,9 @@ Once you've installed a Plugin or two, you can run Homebridge again:
However, Homebridge won't do anything until you've created a `config.json` file containing your accessories and/or platforms. You can start by copying and modifying the included `config-sample.json` file which includes declarations for some example accessories and platforms. Each Plugin will have its own expected configuration; the documentation for Plugins should give you some real-world examples for that plugin. However, Homebridge won't do anything until you've created a `config.json` file containing your accessories and/or platforms. You can start by copying and modifying the included `config-sample.json` file which includes declarations for some example accessories and platforms. Each Plugin will have its own expected configuration; the documentation for Plugins should give you some real-world examples for that plugin.
**NOTE**: Your `config.json` file MUST live in your home directory inside `.homebridge`. The full error message will contain the exact path where your config is expected to be found. **NOTE**: Your `config.json` file MUST be inside of `.homebridge`, which is inside of your home folder. On MacOS and Linux, the full path for your `config.json` would be `~/.homebridge/config.json`. Any error messages will contain the exact path where your config is expected to be found.
**REALLY IMPORTANT**: You must use a "plain text" editor to create or modify `config.json`. Do NOT use apps like TextEdit on Mac or Wordpad on Windows; these apps will corrupt the formatting of the file in hard-to-debug ways. I suggest using the free [Atom text editor](http://atom.io). **REALLY IMPORTANT**: You must use a "plain text" editor to create or modify `config.json`. Do NOT use apps like TextEdit on Mac or Wordpad on Windows. Apps like these will corrupt the formatting of the file in hard-to-debug ways, making improper `"` signs is an example. I suggest using the free [Atom text editor](http://atom.io).
Once you've added your config file, you should be able to run Homebridge again: Once you've added your config file, you should be able to run Homebridge again:
@@ -79,15 +83,11 @@ You can explore all available plugins at the NPM website by [searching for the k
# Adding Homebridge to iOS # Adding Homebridge to iOS
HomeKit is actually not an app; it's a "database" similar to HealthKit and PassKit. But where HealthKit has the companion _Health_ app and PassKit has _Passbook_, Apple has supplied no app for managing your HomeKit database (at least [not yet](http://9to5mac.com/2015/05/20/apples-planned-ios-9-home-app-uses-virtual-rooms-to-manage-homekit-accessories/)). However, the HomeKit API is open for developers to write their own apps for adding devices to HomeKit. HomeKit itself is actually not an app; it's a "database" similar to HealthKit and PassKit. Where HealthKit has the companion _Health_ app and PassKit has _Passbook_, HomeKit has the _Home_ app, introduced with iOS 10.
Fortunately, there are now a few apps in the App Store that can manage your HomeKit devices. The most comprehensive one I've used is [MyTouchHome](https://itunes.apple.com/us/app/mytouchhome/id965142360?mt=8&at=11lvmd&ct=mhweb) which costs $2. If you are a member of the iOS developer program, you might also find Apple's [HomeKit Catalog](https://developer.apple.com/library/ios/samplecode/HomeKitCatalog/Introduction/Intro.html) app to be useful, as it provides straightforward and comprehensive management of all HomeKit database "objects".
There are also some free apps that work OK. Try [Insteon+](https://itunes.apple.com/US/app/id919270334?mt=8) or [Lutron](https://itunes.apple.com/us/app/lutron-app-for-caseta-wireless/id886753021?mt=8) or a number of others. Using the Home app (or most other HomeKit apps), you should be able to add the single accessory "Homebridge", assuming that you're still running Homebridge and you're on the same Wifi network. Adding this accessory will automatically add all accessories and platforms defined in `config.json`.
If you are a member of the iOS developer program, I highly recommend Apple's [HomeKit Catalog](https://developer.apple.com/library/ios/samplecode/HomeKitCatalog/Introduction/Intro.html) app, as it is reliable and comprehensive and free (and open source).
Once you've gotten a HomeKit app running on your iOS device, it should "discover" the single accessory "Homebridge", assuming that you're still running Homebridge and you're on the same Wifi network. Adding this accessory will automatically add all accessories and platforms defined in `config.json`.
When you attempt to add Homebridge, it will ask for a "PIN code". The default code is `031-45-154` (but this can be changed, see `config-sample.json`). When you attempt to add Homebridge, it will ask for a "PIN code". The default code is `031-45-154` (but this can be changed, see `config-sample.json`).

View File

@@ -21,14 +21,15 @@ module.exports = function(homebridge) {
// config may be null // config may be null
// api may be null if launched from old homebridge version // api may be null if launched from old homebridge version
function SamplePlatform(log, config, api) { function SamplePlatform(log, config, api) {
console.log("SamplePlatform Init"); log("SamplePlatform Init");
var platform = this;
this.log = log; this.log = log;
this.config = config; this.config = config;
this.accessories = []; this.accessories = [];
this.requestServer = http.createServer(function(request, response) { this.requestServer = http.createServer(function(request, response) {
if (request.url === "/add") { if (request.url === "/add") {
this.addAccessory(); this.addAccessory(new Date().toISOString());
response.writeHead(204); response.writeHead(204);
response.end(); response.end();
} }
@@ -47,7 +48,7 @@ function SamplePlatform(log, config, api) {
}.bind(this)); }.bind(this));
this.requestServer.listen(18081, function() { this.requestServer.listen(18081, function() {
console.log("Server Listening..."); platform.log("Server Listening...");
}); });
if (api) { if (api) {
@@ -58,7 +59,7 @@ function SamplePlatform(log, config, api) {
// Platform Plugin should only register new accessory that doesn't exist in homebridge after this event. // Platform Plugin should only register new accessory that doesn't exist in homebridge after this event.
// Or start discover new accessories // Or start discover new accessories
this.api.on('didFinishLaunching', function() { this.api.on('didFinishLaunching', function() {
console.log("Plugin - DidFinishLaunching"); platform.log("DidFinishLaunching");
}.bind(this)); }.bind(this));
} }
} }
@@ -67,7 +68,8 @@ function SamplePlatform(log, config, api) {
// Developer can configure accessory at here (like setup event handler) // Developer can configure accessory at here (like setup event handler)
// Update current value // Update current value
SamplePlatform.prototype.configureAccessory = function(accessory) { SamplePlatform.prototype.configureAccessory = function(accessory) {
console.log("Plugin - Configure Accessory: " + accessory.displayName); this.log(accessory.displayName, "Configure Accessory");
var platform = this;
// set the accessory to reachable if plugin can currently process the accessory // set the accessory to reachable if plugin can currently process the accessory
// otherwise set to false and update the reachability later by invoking // otherwise set to false and update the reachability later by invoking
@@ -75,7 +77,7 @@ SamplePlatform.prototype.configureAccessory = function(accessory) {
accessory.reachable = true; accessory.reachable = true;
accessory.on('identify', function(paired, callback) { accessory.on('identify', function(paired, callback) {
console.log("Identify!!!"); platform.log(accessory.displayName, "Identify!!!");
callback(); callback();
}); });
@@ -83,7 +85,7 @@ SamplePlatform.prototype.configureAccessory = function(accessory) {
accessory.getService(Service.Lightbulb) accessory.getService(Service.Lightbulb)
.getCharacteristic(Characteristic.On) .getCharacteristic(Characteristic.On)
.on('set', function(value, callback) { .on('set', function(value, callback) {
console.log("Light -> " + value); platform.log(accessory.displayName, "Light -> " + value);
callback(); callback();
}); });
} }
@@ -94,8 +96,8 @@ SamplePlatform.prototype.configureAccessory = function(accessory) {
//Handler will be invoked when user try to config your plugin //Handler will be invoked when user try to config your plugin
//Callback can be cached and invoke when nessary //Callback can be cached and invoke when nessary
SamplePlatform.prototype.configurationRequestHandler = function(context, request, callback) { SamplePlatform.prototype.configurationRequestHandler = function(context, request, callback) {
console.log("Context: ", JSON.stringify(context)); this.log("Context: ", JSON.stringify(context));
console.log("Request: ", JSON.stringify(request)); this.log("Request: ", JSON.stringify(request));
// Check the request response // Check the request response
if (request && request.response && request.response.inputs && request.response.inputs.name) { if (request && request.response && request.response.inputs && request.response.inputs.name) {
@@ -173,18 +175,15 @@ SamplePlatform.prototype.configurationRequestHandler = function(context, request
// Sample function to show how developer can add accessory dynamically from outside event // Sample function to show how developer can add accessory dynamically from outside event
SamplePlatform.prototype.addAccessory = function(accessoryName) { SamplePlatform.prototype.addAccessory = function(accessoryName) {
console.log("Add Accessory"); this.log("Add Accessory");
var platform = this;
var uuid; var uuid;
if (!accessoryName) {
accessoryName = "Test Accessory"
}
uuid = UUIDGen.generate(accessoryName); uuid = UUIDGen.generate(accessoryName);
var newAccessory = new Accessory(accessoryName, uuid); var newAccessory = new Accessory(accessoryName, uuid);
newAccessory.on('identify', function(paired, callback) { newAccessory.on('identify', function(paired, callback) {
console.log("Identify!!!"); platform.log(accessory.displayName, "Identify!!!");
callback(); callback();
}); });
// Plugin can save context on accessory // Plugin can save context on accessory
@@ -194,7 +193,7 @@ SamplePlatform.prototype.addAccessory = function(accessoryName) {
newAccessory.addService(Service.Lightbulb, "Test Light") newAccessory.addService(Service.Lightbulb, "Test Light")
.getCharacteristic(Characteristic.On) .getCharacteristic(Characteristic.On)
.on('set', function(value, callback) { .on('set', function(value, callback) {
console.log("Light -> " + value); platform.log(accessory.displayName, "Light -> " + value);
callback(); callback();
}); });
@@ -203,7 +202,7 @@ SamplePlatform.prototype.addAccessory = function(accessoryName) {
} }
SamplePlatform.prototype.updateAccessoriesReachability = function() { SamplePlatform.prototype.updateAccessoriesReachability = function() {
console.log("Update Reachability"); this.log("Update Reachability");
for (var index in this.accessories) { for (var index in this.accessories) {
var accessory = this.accessories[index]; var accessory = this.accessories[index];
accessory.updateReachability(false); accessory.updateReachability(false);
@@ -212,8 +211,8 @@ SamplePlatform.prototype.updateAccessoriesReachability = function() {
// Sample function to show how developer can remove accessory dynamically from outside event // Sample function to show how developer can remove accessory dynamically from outside event
SamplePlatform.prototype.removeAccessory = function() { SamplePlatform.prototype.removeAccessory = function() {
console.log("Remove Accessory"); this.log("Remove Accessory");
this.api.unregisterPlatformAccessories("homebridge-samplePlatform", "SamplePlatform", this.accessories); this.api.unregisterPlatformAccessories("homebridge-samplePlatform", "SamplePlatform", this.accessories);
this.accessories = []; this.accessories = [];
} }

View File

@@ -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",

View File

@@ -67,7 +67,7 @@ Logger.prototype.log = function(level, msg) {
// prepend timestamp // prepend timestamp
var date = new Date(); var date = new Date();
msg = chalk.black("[" + date.toLocaleString() + "]") + " " + msg; msg = "[" + date.toLocaleString() + "]" + " " + msg;
func(msg); func(msg);
} }

View File

@@ -130,9 +130,23 @@ 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.reachable = this.reachable; this._associatedHAPAccessory.reachable = this.reachable;
this._associatedHAPAccessory.on('identify', function(paired, callback) { this._associatedHAPAccessory.on('identify', function(paired, callback) {
if (this.listeners('identify').length > 0) { if (this.listeners('identify').length > 0) {

View File

@@ -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));
@@ -87,16 +93,27 @@ Server.prototype.run = function() {
Server.prototype._publish = function() { Server.prototype._publish = function() {
// pull out our custom Bridge settings from config.json, if any // pull out our custom Bridge settings from config.json, if any
var bridgeConfig = this._config.bridge || {}; var bridgeConfig = this._config.bridge || {};
var info = this._bridge.getService(Service.AccessoryInformation);
if (bridgeConfig.manufacturer)
info.setCharacteristic(Characteristic.Manufacturer, bridgeConfig.manufacturer);
if (bridgeConfig.model)
info.setCharacteristic(Characteristic.Model, bridgeConfig.model);
if (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, port: bridgeConfig.port || 0,
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) {
@@ -150,12 +167,13 @@ Server.prototype._loadConfig = function() {
// Complain and exit if it doesn't exist yet // Complain and exit if it doesn't exist yet
if (!fs.existsSync(configPath)) { if (!fs.existsSync(configPath)) {
log.warn("config.json (%s) not found.", configPath);
var config = {}; var config = {};
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"
}; };
@@ -444,6 +462,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 " + accessory.displayName + " experienced an address collision.");
} 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 = [];
@@ -466,7 +512,7 @@ Server.prototype._handleNewConfig = function(type, name, replace, config) {
this._config.accessories.push(config); this._config.accessories.push(config);
} else { } else {
var targetName; var targetName;
if (name.indexOf('.') == -1) { if (name.indexOf('.') !== -1) {
targetName = name.split(".")[1]; targetName = name.split(".")[1];
} }
var found = false; var found = false;
@@ -498,7 +544,7 @@ Server.prototype._handleNewConfig = function(type, name, replace, config) {
this._config.platforms.push(config); this._config.platforms.push(config);
} else { } else {
var targetName; var targetName;
if (name.indexOf('.') == -1) { if (name.indexOf('.') !== -1) {
targetName = name.split(".")[1]; targetName = name.split(".")[1];
} }

18
lib/util/mac.js Normal file
View 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();
};

View File

@@ -1,7 +1,7 @@
{ {
"name": "homebridge", "name": "homebridge",
"description": "HomeKit support for the impatient", "description": "HomeKit support for the impatient",
"version": "0.3.1", "version": "0.4.8",
"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.2.7", "hap-nodejs": "0.4.13",
"semver": "5.0.3", "semver": "5.0.3",
"node-persist": "^0.0.8" "node-persist": "^0.0.8"
} }