diff --git a/accessories/Http.js b/accessories/Http.js index f1b15ce..0967be7 100644 --- a/accessories/Http.js +++ b/accessories/Http.js @@ -69,7 +69,20 @@ HttpAccessory.prototype = { }.bind(this)); }, + identify: function() { + this.log("Identify requested!"); + }, + getServices: function() { + + // you can OPTIONALLY create an information service if you wish to override + // the default values for things like serial number, model, etc. + var informationService = new Service.AccessoryInformation(); + + informationService + .setCharacteristic(Characteristic.Manufacturer, "HTTP Manufacturer") + .setCharacteristic(Characteristic.Model, "HTTP Model") + .setCharacteristic(Characteristic.SerialNumber, "HTTP Serial Number"); var lightbulbService = new Service.Lightbulb(); @@ -81,6 +94,6 @@ HttpAccessory.prototype = { .addCharacteristic(new Characteristic.Brightness()) .on('set', this.setBrightness.bind(this)); - return [lightbulbService]; + return [informationService, lightbulbService]; } }; diff --git a/app.js b/app.js index e678fb9..3f0c275 100644 --- a/app.js +++ b/app.js @@ -6,6 +6,7 @@ var uuid = require('HAP-NodeJS').uuid; var Bridge = require('HAP-NodeJS').Bridge; var Accessory = require('HAP-NodeJS').Accessory; var Service = require('HAP-NodeJS').Service; +var Characteristic = require('HAP-NodeJS').Characteristic; var accessoryLoader = require('HAP-NodeJS').AccessoryLoader; console.log("Starting HomeBridge server..."); @@ -160,7 +161,31 @@ function createAccessory(accessoryInstance, displayName) { var accessoryUUID = uuid.generate(accessoryInstance.constructor.name + ":" + displayName); var accessory = new Accessory(displayName, accessoryUUID); - services.forEach(function(service) { accessory.addService(service); }); + + // listen for the identify event if the accessory instance has defined an identify() method + if (accessoryInstance.identify) + accessory.on('identify', function(paired, callback) { accessoryInstance.identify(callback); }); + + services.forEach(function(service) { + + // if you returned an AccessoryInformation service, merge its values with ours + if (service instanceof Service.AccessoryInformation) { + var existingService = accessory.getService(Service.AccessoryInformation); + + // pull out any values you may have defined + var manufacturer = service.getCharacteristic(Characteristic.Manufacturer).value; + var model = service.getCharacteristic(Characteristic.Model).value; + var serialNumber = service.getCharacteristic(Characteristic.SerialNumber).value; + + if (manufacturer) existingService.setCharacteristic(Characteristic.Manufacturer, manufacturer); + if (model) existingService.setCharacteristic(Characteristic.Model, model); + if (serialNumber) existingService.setCharacteristic(Characteristic.SerialNumber, serialNumber); + } + else { + accessory.addService(service); + } + }); + return accessory; } } diff --git a/package.json b/package.json index 2814343..5604b0f 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "carwingsjs": "0.0.x", "color": "0.10.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/KhaosT/HAP-NodeJS#187174846dc4b8970efba74b9eb2968b35f15d87", + "hap-nodejs": "git+https://github.com/KhaosT/HAP-NodeJS#46ba0597eb339983a14d98c53764a58a5516fcd2", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4",