mirror of
https://github.com/mtan93/homebridge.git
synced 2026-03-08 05:31:55 +00:00
Merge pull request #513 from snowdd1/patch-1
new getServiceByUUIDAndSubtype(UUID, subtype) function
This commit is contained in:
@@ -60,6 +60,12 @@ PlatformAccessory.prototype.addService = function(service) {
|
||||
return 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.
|
||||
* @param {ServiceConstructor|string} name
|
||||
* @returns Service
|
||||
*/
|
||||
PlatformAccessory.prototype.getService = function(name) {
|
||||
for (var index in this.services) {
|
||||
var service = this.services[index];
|
||||
@@ -71,6 +77,25 @@ PlatformAccessory.prototype.getService = function(name) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param {string} UUID Can be an UUID, a service.displayName, or a constructor of a Service
|
||||
* @param {string} subtype A subtype string to match
|
||||
* @returns Service
|
||||
*/
|
||||
PlatformAccessory.prototype.getServiceByUUIDAndSubType = function(UUID, subtype) {
|
||||
for (var index in this.services) {
|
||||
var service = this.services[index];
|
||||
|
||||
if (typeof UUID === 'string' && (service.displayName === UUID || service.name === UUID) && service.subtype === subtype )
|
||||
return service;
|
||||
else if (typeof name === 'function' && ((service instanceof name) || (name.UUID === service.UUID)) && service.subtype === subtype)
|
||||
return service;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PlatformAccessory.prototype.updateReachability = function(reachable) {
|
||||
this.reachable = reachable;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user