Skip to content

Commit

Permalink
Added public label to the HAP.Service
Browse files Browse the repository at this point in the history
Helps to distinguish services of the same type that are part of the same accessory
  • Loading branch information
TheMisfit68 committed Sep 21, 2023
1 parent 51e3505 commit 6d7371b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/HAP/Base/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ open class Service: NSObject, JSONSerializable {
var primary: Bool?
var hidden: Bool?

public var label:String?{
let nameCharacteristic:GenericCharacteristic<String>? = 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 }
Expand Down

0 comments on commit 6d7371b

Please sign in to comment.