Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import HomeKit
- extension HMService {
- class var serviceTypes: [String] {
- let services_10 = [
- HMServiceTypeLightbulb,
- HMServiceTypeSwitch,
- HMServiceTypeThermostat,
- HMServiceTypeGarageDoorOpener,
- HMServiceTypeAccessoryInformation,
- HMServiceTypeFan,
- HMServiceTypeOutlet,
- HMServiceTypeLockMechanism,
- HMServiceTypeLockManagement,
- HMServiceTypeAirQualitySensor,
- HMServiceTypeBattery,
- HMServiceTypeCarbonDioxideSensor,
- HMServiceTypeCarbonMonoxideSensor,
- HMServiceTypeContactSensor,
- HMServiceTypeDoor,
- HMServiceTypeDoorbell,
- HMServiceTypeHumiditySensor,
- HMServiceTypeLeakSensor,
- HMServiceTypeLightSensor,
- HMServiceTypeMotionSensor,
- HMServiceTypeOccupancySensor,
- HMServiceTypeSecuritySystem,
- HMServiceTypeStatefulProgrammableSwitch,
- HMServiceTypeStatelessProgrammableSwitch,
- HMServiceTypeSmokeSensor,
- HMServiceTypeTemperatureSensor,
- HMServiceTypeWindow,
- HMServiceTypeWindowCovering,
- HMServiceTypeCameraRTPStreamManagement,
- HMServiceTypeCameraControl,
- HMServiceTypeMicrophone,
- HMServiceTypeSpeaker]
- if #available(iOS 10.2, *) {
- let services_10_2 = [
- HMServiceTypeAirPurifier,
- HMServiceTypeVentilationFan,
- HMServiceTypeFilterMaintenance,
- HMServiceTypeHeaterCooler,
- HMServiceTypeHumidifierDehumidifier,
- HMServiceTypeSlats
- ]
- return services_10 + services_10_2
- } else {
- return services_10
- }
- }
- func validAssociatedServiceTypes(callback: @escaping (([String?]) -> Void)) {
- let initialAssociatedServiceType = self.associatedServiceType
- var allTypes = HMService.serviceTypes
- var validTypes: [String?] = []
- func checkValidType() {
- guard allTypes.isEmpty == false else {
- // restore initial type after all valid types were found
- self.updateAssociatedServiceType(initialAssociatedServiceType, completionHandler: { error in
- DispatchQueue.main.async {
- callback(validTypes)
- }
- })
- return
- }
- let type = allTypes.popLast()
- // test if assigning the type results in an error
- self.updateAssociatedServiceType(type) { error in
- // append to valid types if no error was raised
- if error == nil {
- validTypes.append(type)
- }
- checkValidType()
- }
- }
- checkValidType()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement