From 925c1630c4df8a8308fed3cc5185fbfddfe0cc77 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Mon, 26 Sep 2016 10:46:21 -0400 Subject: [PATCH 1/7] bump hap-nodejs to 0.4.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e26965e..4c7b2ef 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "homebridge", "description": "HomeKit support for the impatient", - "version": "0.3.4", + "version": "0.3.5", "scripts": { "dev": "DEBUG=* ./bin/homebridge -D -P example-plugins/ || true" }, @@ -26,7 +26,7 @@ "dependencies": { "chalk": "^1.1.1", "commander": "2.8.1", - "hap-nodejs": "0.3.2", + "hap-nodejs": "0.4.0", "semver": "5.0.3", "node-persist": "^0.0.8" } From c89ff97ac5f655f4745e164fd694937d5f256ddd Mon Sep 17 00:00:00 2001 From: Khaos Tian Date: Mon, 26 Sep 2016 13:01:29 -0700 Subject: [PATCH 2/7] init design --- lib/api.js | 12 ++++++++++++ lib/platformAccessory.js | 8 ++++++++ lib/server.js | 29 +++++++++++++++++++++++++---- lib/util/mac.js | 18 ++++++++++++++++++ package.json | 4 ++-- 5 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 lib/util/mac.js diff --git a/lib/api.js b/lib/api.js index d2aa1b3..41aea23 100644 --- a/lib/api.js +++ b/lib/api.js @@ -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) { // if you passed the "short form" name like "Lockitron" instead of "homebridge-lockitron.Lockitron", diff --git a/lib/platformAccessory.js b/lib/platformAccessory.js index 1680823..0084c69 100644 --- a/lib/platformAccessory.js +++ b/lib/platformAccessory.js @@ -130,6 +130,14 @@ 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 () { this._associatedHAPAccessory = new Accessory(this.displayName, this.UUID); this._associatedHAPAccessory._sideloadServices(this.services); diff --git a/lib/server.js b/lib/server.js index 2bf84c1..2e3013f 100644 --- a/lib/server.js +++ b/lib/server.js @@ -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 = []; diff --git a/lib/util/mac.js b/lib/util/mac.js new file mode 100644 index 0000000..89eee74 --- /dev/null +++ b/lib/util/mac.js @@ -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(); +}; \ No newline at end of file diff --git a/package.json b/package.json index 4c7b2ef..154e1fe 100644 --- a/package.json +++ b/package.json @@ -20,13 +20,13 @@ "homebridge": "bin/homebridge" }, "engines": { - "node": ">=0.12.0" + "node": ">=4.3.2" }, "preferGlobal": true, "dependencies": { "chalk": "^1.1.1", "commander": "2.8.1", - "hap-nodejs": "0.4.0", + "hap-nodejs": "0.4.4", "semver": "5.0.3", "node-persist": "^0.0.8" } From ecd06d72394215e437ea928c66f8a6852f740a99 Mon Sep 17 00:00:00 2001 From: Khaos Tian Date: Mon, 26 Sep 2016 13:19:50 -0700 Subject: [PATCH 3/7] Bump api version --- lib/api.js | 2 +- lib/server.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/api.js b/lib/api.js index 41aea23..738de79 100644 --- a/lib/api.js +++ b/lib/api.js @@ -20,7 +20,7 @@ function API() { this._dynamicPlatforms = {}; // this._dynamicPlatforms[pluginName.platformName] = platform constructor // 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() this.user = User; diff --git a/lib/server.js b/lib/server.js index 2e3013f..5a0b612 100644 --- a/lib/server.js +++ b/lib/server.js @@ -52,6 +52,7 @@ function Server(insecureAccess) { this._activeDynamicPlugins = {}; this._configurablePlatformPlugins = {}; + this._publishedCameras = {}; this._setupManager = new BridgeSetupManager(); this._setupManager.on('newConfig', this._handleNewConfig.bind(this)); @@ -466,9 +467,16 @@ Server.prototype._handlePublishCameraAccessories = function(accessories) { 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.publish({ - username: mac.generate(accessory.uuid), + username: advertiseAddress, pincode: bridgeConfig.pin || "031-45-154", category: accessory.category }, this._allowInsecureAccess); From 66ea6e640da9da38ac11216b24309ea713d4f5cc Mon Sep 17 00:00:00 2001 From: Khaos Tian Date: Mon, 26 Sep 2016 14:15:12 -0700 Subject: [PATCH 4/7] Minor Tweak --- lib/platformAccessory.js | 5 +++++ lib/server.js | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/platformAccessory.js b/lib/platformAccessory.js index 0084c69..382ef0d 100644 --- a/lib/platformAccessory.js +++ b/lib/platformAccessory.js @@ -140,6 +140,11 @@ PlatformAccessory.prototype.configureCameraSource = function(cameraSource) { PlatformAccessory.prototype._prepareAssociatedHAPAccessory = function () { this._associatedHAPAccessory = new Accessory(this.displayName, this.UUID); + + if (this.cameraSource) { + this._associatedHAPAccessory.configureCameraSource(this.cameraSource); + } + this._associatedHAPAccessory._sideloadServices(this.services); this._associatedHAPAccessory.category = this.category; this._associatedHAPAccessory.reachable = this.reachable; diff --git a/lib/server.js b/lib/server.js index 5a0b612..5e98e3c 100644 --- a/lib/server.js +++ b/lib/server.js @@ -462,12 +462,14 @@ Server.prototype._handleUnregisterPlatformAccessories = function(accessories) { } 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); + var advertiseAddress = mac.generate(accessory.UUID); if (this._publishedCameras[advertiseAddress]) { throw new Error("Camera accessory %s experienced an address collision.", accessory.displayName); @@ -475,9 +477,13 @@ Server.prototype._handlePublishCameraAccessories = function(accessories) { 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: bridgeConfig.pin || "031-45-154", + pincode: accessoryPin, category: accessory.category }, this._allowInsecureAccess); } From ff35ece65c205af2b053302a2b02c7bda522b466 Mon Sep 17 00:00:00 2001 From: Khaos Tian Date: Mon, 26 Sep 2016 14:22:22 -0700 Subject: [PATCH 5/7] 0.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 154e1fe..5c163a6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "homebridge", "description": "HomeKit support for the impatient", - "version": "0.3.5", + "version": "0.4.0", "scripts": { "dev": "DEBUG=* ./bin/homebridge -D -P example-plugins/ || true" }, From ef8fe5ced2d13a684d660c5d9090de5876690b7c Mon Sep 17 00:00:00 2001 From: Khaos Tian Date: Mon, 26 Sep 2016 20:31:55 -0700 Subject: [PATCH 6/7] Update hap-nodejs version to fix side load problem --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5c163a6..281fc23 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "dependencies": { "chalk": "^1.1.1", "commander": "2.8.1", - "hap-nodejs": "0.4.4", + "hap-nodejs": "0.4.6", "semver": "5.0.3", "node-persist": "^0.0.8" } From 0ccd80c8e7925d23547479c501b45c8e016ca4cf Mon Sep 17 00:00:00 2001 From: Khaos Tian Date: Mon, 26 Sep 2016 20:32:06 -0700 Subject: [PATCH 7/7] 0.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 281fc23..0597a3d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "homebridge", "description": "HomeKit support for the impatient", - "version": "0.4.0", + "version": "0.4.1", "scripts": { "dev": "DEBUG=* ./bin/homebridge -D -P example-plugins/ || true" },