mirror of
https://github.com/mtan93/homebridge.git
synced 2026-03-08 05:31:55 +00:00
new getServiceByUUIDAndSubtype(UUID, subtype) function
Some platforms may have accessories that contain more than one service of a given type, such as multiple lightbulbs.
This commit is contained in:
@@ -60,6 +60,12 @@ PlatformAccessory.prototype.addService = function(service) {
|
|||||||
return 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) {
|
PlatformAccessory.prototype.getService = function(name) {
|
||||||
for (var index in this.services) {
|
for (var index in this.services) {
|
||||||
var service = this.services[index];
|
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) {
|
PlatformAccessory.prototype.updateReachability = function(reachable) {
|
||||||
this.reachable = reachable;
|
this.reachable = reachable;
|
||||||
|
|
||||||
@@ -149,4 +174,4 @@ PlatformAccessory.prototype._configFromData = function(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.services = services;
|
this.services = services;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user