Add the ability to remove services/characteristics

This commit is contained in:
Khaos Tian
2016-02-17 13:18:25 -08:00
parent d3c77a4cda
commit 40266af8b2
4 changed files with 36 additions and 1 deletions

View File

@@ -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.