Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. import HomeKit
  2.  
  3. extension HMService {
  4. class var serviceTypes: [String] {
  5. let services_10 = [
  6. HMServiceTypeLightbulb,
  7. HMServiceTypeSwitch,
  8. HMServiceTypeThermostat,
  9. HMServiceTypeGarageDoorOpener,
  10. HMServiceTypeAccessoryInformation,
  11. HMServiceTypeFan,
  12. HMServiceTypeOutlet,
  13. HMServiceTypeLockMechanism,
  14. HMServiceTypeLockManagement,
  15. HMServiceTypeAirQualitySensor,
  16. HMServiceTypeBattery,
  17. HMServiceTypeCarbonDioxideSensor,
  18. HMServiceTypeCarbonMonoxideSensor,
  19. HMServiceTypeContactSensor,
  20. HMServiceTypeDoor,
  21. HMServiceTypeDoorbell,
  22. HMServiceTypeHumiditySensor,
  23. HMServiceTypeLeakSensor,
  24. HMServiceTypeLightSensor,
  25. HMServiceTypeMotionSensor,
  26. HMServiceTypeOccupancySensor,
  27. HMServiceTypeSecuritySystem,
  28. HMServiceTypeStatefulProgrammableSwitch,
  29. HMServiceTypeStatelessProgrammableSwitch,
  30. HMServiceTypeSmokeSensor,
  31. HMServiceTypeTemperatureSensor,
  32. HMServiceTypeWindow,
  33. HMServiceTypeWindowCovering,
  34. HMServiceTypeCameraRTPStreamManagement,
  35. HMServiceTypeCameraControl,
  36. HMServiceTypeMicrophone,
  37. HMServiceTypeSpeaker]
  38.  
  39. if #available(iOS 10.2, *) {
  40. let services_10_2 = [
  41. HMServiceTypeAirPurifier,
  42. HMServiceTypeVentilationFan,
  43. HMServiceTypeFilterMaintenance,
  44. HMServiceTypeHeaterCooler,
  45. HMServiceTypeHumidifierDehumidifier,
  46. HMServiceTypeSlats
  47. ]
  48.  
  49. return services_10 + services_10_2
  50. } else {
  51. return services_10
  52. }
  53. }
  54.  
  55.  
  56. func validAssociatedServiceTypes(callback: @escaping (([String?]) -> Void)) {
  57. let initialAssociatedServiceType = self.associatedServiceType
  58.  
  59. var allTypes = HMService.serviceTypes
  60. var validTypes: [String?] = []
  61.  
  62. func checkValidType() {
  63. guard allTypes.isEmpty == false else {
  64. // restore initial type after all valid types were found
  65. self.updateAssociatedServiceType(initialAssociatedServiceType, completionHandler: { error in
  66. DispatchQueue.main.async {
  67. callback(validTypes)
  68. }
  69. })
  70.  
  71. return
  72. }
  73.  
  74. let type = allTypes.popLast()
  75.  
  76. // test if assigning the type results in an error
  77. self.updateAssociatedServiceType(type) { error in
  78. // append to valid types if no error was raised
  79. if error == nil {
  80. validTypes.append(type)
  81. }
  82.  
  83. checkValidType()
  84. }
  85. }
  86.  
  87. checkValidType()
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement