mirror of
https://github.com/mtan93/homebridge.git
synced 2026-03-08 05:31:55 +00:00
Add the ability to remove services/characteristics
This commit is contained in:
@@ -143,6 +143,10 @@ API.prototype.registerPlatformAccessories = function(pluginName, platformName, a
|
||||
this.emit('registerPlatformAccessories', accessories);
|
||||
}
|
||||
|
||||
API.prototype.updatePlatformAccessories = function(accessories) {
|
||||
this.emit('updatePlatformAccessories', accessories);
|
||||
}
|
||||
|
||||
API.prototype.unregisterPlatformAccessories = function(pluginName, platformName, accessories) {
|
||||
for (var index in accessories) {
|
||||
var accessory = accessories[index];
|
||||
|
||||
@@ -60,6 +60,28 @@ PlatformAccessory.prototype.addService = function(service) {
|
||||
return service;
|
||||
}
|
||||
|
||||
PlatformAccessory.prototype.removeService = function(service) {
|
||||
var targetServiceIndex;
|
||||
|
||||
for (var index in this.services) {
|
||||
var existingService = this.services[index];
|
||||
|
||||
if (existingService === service) {
|
||||
targetServiceIndex = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetServiceIndex) {
|
||||
this.services.splice(targetServiceIndex, 1);
|
||||
service.removeAllListeners();
|
||||
|
||||
if (this._associatedHAPAccessory) {
|
||||
this._associatedHAPAccessory.removeService(service);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* searchs for a Service in the services collection and returns the first Service object that matches.
|
||||
* If multiple services of the same type are present in one accessory, use getServiceByUUIDAndSubType instead.
|
||||
|
||||
@@ -32,6 +32,10 @@ function Server(insecureAccess) {
|
||||
this._handleRegisterPlatformAccessories(accessories);
|
||||
}.bind(this));
|
||||
|
||||
this._api.on('updatePlatformAccessories', function(accessories) {
|
||||
this._handleUpdatePlatformAccessories(accessories);
|
||||
}.bind(this));
|
||||
|
||||
this._api.on('unregisterPlatformAccessories', function(accessories) {
|
||||
this._handleUnregisterPlatformAccessories(accessories);
|
||||
}.bind(this));
|
||||
@@ -408,6 +412,11 @@ Server.prototype._handleRegisterPlatformAccessories = function(accessories) {
|
||||
this._updateCachedAccessories();
|
||||
}
|
||||
|
||||
Server.prototype._handleUpdatePlatformAccessories = function(accessories) {
|
||||
// Update persisted accessories
|
||||
this._updateCachedAccessories();
|
||||
}
|
||||
|
||||
Server.prototype._handleUnregisterPlatformAccessories = function(accessories) {
|
||||
var hapAccessories = [];
|
||||
for (var index in accessories) {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
"dependencies": {
|
||||
"chalk": "^1.1.1",
|
||||
"commander": "2.8.1",
|
||||
"hap-nodejs": "0.2.3",
|
||||
"hap-nodejs": "0.2.4",
|
||||
"semver": "5.0.3",
|
||||
"node-persist": "^0.0.8"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user