From 6d7371b3f1778891d3393b51f438bf9da876904e Mon Sep 17 00:00:00 2001 From: TheMisfit68 Date: Thu, 21 Sep 2023 20:28:39 +0200 Subject: [PATCH] Added public label to the HAP.Service Helps to distinguish services of the same type that are part of the same accessory --- Sources/HAP/Base/Service.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sources/HAP/Base/Service.swift b/Sources/HAP/Base/Service.swift index 33932de0..e6d30e00 100644 --- a/Sources/HAP/Base/Service.swift +++ b/Sources/HAP/Base/Service.swift @@ -70,6 +70,15 @@ open class Service: NSObject, JSONSerializable { var primary: Bool? var hidden: Bool? + public var label:String?{ + let nameCharacteristic:GenericCharacteristic? = get(type: .name, characteristics: characteristics) + if let serviceName = nameCharacteristic?.value{ + return serviceName + }else{ + return String(describing: Swift.type(of: self)) + } + } + public init(type: ServiceType, characteristics: [AnyCharacteristic]) { self.type = type self.characteristics = characteristics.map { $0.wrapped }