mirror of
https://github.com/mtan93/homebridge.git
synced 2026-03-08 05:31:55 +00:00
Support AccessoryInformation service
This commit is contained in:
@@ -69,7 +69,20 @@ HttpAccessory.prototype = {
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
identify: function() {
|
||||||
|
this.log("Identify requested!");
|
||||||
|
},
|
||||||
|
|
||||||
getServices: function() {
|
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();
|
var lightbulbService = new Service.Lightbulb();
|
||||||
|
|
||||||
@@ -81,6 +94,6 @@ HttpAccessory.prototype = {
|
|||||||
.addCharacteristic(new Characteristic.Brightness())
|
.addCharacteristic(new Characteristic.Brightness())
|
||||||
.on('set', this.setBrightness.bind(this));
|
.on('set', this.setBrightness.bind(this));
|
||||||
|
|
||||||
return [lightbulbService];
|
return [informationService, lightbulbService];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
27
app.js
27
app.js
@@ -6,6 +6,7 @@ var uuid = require('HAP-NodeJS').uuid;
|
|||||||
var Bridge = require('HAP-NodeJS').Bridge;
|
var Bridge = require('HAP-NodeJS').Bridge;
|
||||||
var Accessory = require('HAP-NodeJS').Accessory;
|
var Accessory = require('HAP-NodeJS').Accessory;
|
||||||
var Service = require('HAP-NodeJS').Service;
|
var Service = require('HAP-NodeJS').Service;
|
||||||
|
var Characteristic = require('HAP-NodeJS').Characteristic;
|
||||||
var accessoryLoader = require('HAP-NodeJS').AccessoryLoader;
|
var accessoryLoader = require('HAP-NodeJS').AccessoryLoader;
|
||||||
|
|
||||||
console.log("Starting HomeBridge server...");
|
console.log("Starting HomeBridge server...");
|
||||||
@@ -160,7 +161,31 @@ function createAccessory(accessoryInstance, displayName) {
|
|||||||
var accessoryUUID = uuid.generate(accessoryInstance.constructor.name + ":" + displayName);
|
var accessoryUUID = uuid.generate(accessoryInstance.constructor.name + ":" + displayName);
|
||||||
|
|
||||||
var accessory = new Accessory(displayName, accessoryUUID);
|
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;
|
return accessory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
"carwingsjs": "0.0.x",
|
"carwingsjs": "0.0.x",
|
||||||
"color": "0.10.x",
|
"color": "0.10.x",
|
||||||
"elkington": "kevinohara80/elkington",
|
"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-client": "^1.1.4",
|
||||||
"harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git",
|
"harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git",
|
||||||
"mdns": "^2.2.4",
|
"mdns": "^2.2.4",
|
||||||
|
|||||||
Reference in New Issue
Block a user