From adf137d3bc04fb8052cd68040717c4d507a7c778 Mon Sep 17 00:00:00 2001 From: Jimmy Lu Date: Thu, 16 Feb 2017 12:58:06 -0800 Subject: [PATCH 1/2] update notification expected payload --- SleepModel/HEMShortcutService.m | 6 +++-- SleepModel/PushNotification.swift | 42 +++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/SleepModel/HEMShortcutService.m b/SleepModel/HEMShortcutService.m index 8d47cccc..7112c2eb 100644 --- a/SleepModel/HEMShortcutService.m +++ b/SleepModel/HEMShortcutService.m @@ -34,8 +34,10 @@ + (HEMShortcutAction)actionForNotification:(PushNotification*)notification { switch ([notification type]) { case PushTypeSleepScore: return HEMShortcutActionShowTimeline; - case PushTypeLowBattery: - return HEMShortcutActionShowDeviceSettings; + case PushTypeSystem: + return [notification isPillBattery] + ? HEMShortcutActionShowDeviceSettings + : HEMShortcutActionUnknown; case PushTypeUnknown: default: return HEMShortcutActionUnknown; diff --git a/SleepModel/PushNotification.swift b/SleepModel/PushNotification.swift index 998be2e5..6d5bab07 100644 --- a/SleepModel/PushNotification.swift +++ b/SleepModel/PushNotification.swift @@ -13,20 +13,21 @@ import Foundation fileprivate static let keyType = "hlo-type" fileprivate static let keyDetail = "hlo-detail" fileprivate static let typeSleepScore = "sleep_score" - fileprivate static let typeLowBattery = "pill_battery" + fileprivate static let typeSystem = "system" fileprivate static let typeNotRecognized = "not recognized" + fileprivate static let detailPillBattery = "pill_battery" @objc enum PushType: Int { case unknown = 0 case sleepScore - case lowBattery + case system static func fromType(type: String!) -> PushType { let lower = type?.lowercased() if lower == PushNotification.typeSleepScore { return .sleepScore - } else if lower == PushNotification.typeLowBattery { - return .lowBattery + } else if lower == PushNotification.typeSystem { + return .system } else { return .unknown } @@ -36,8 +37,8 @@ import Foundation switch self { case .sleepScore: return PushNotification.typeSleepScore - case .lowBattery: - return PushNotification.typeLowBattery + case .system: + return PushNotification.typeSystem case .unknown: fallthrough default: @@ -46,9 +47,24 @@ import Foundation } } + @objc enum SystemType: Int { + case unknown = 0 + case pillBattery + + static func from(detail: String?) -> SystemType { + let lower = detail?.lowercased() + if lower == PushNotification.detailPillBattery { + return .pillBattery + } else { + return .unknown + } + } + } + /// convenience constant for objective-c code to use namespacing @objc public static let sleepScore: PushType = .sleepScore - @objc public static let lowBattery: PushType = .lowBattery + @objc public static let system: PushType = .system + @objc public static let systemPillBattery: SystemType = .pillBattery @objc fileprivate(set) var type = PushType.unknown @objc fileprivate(set) var detail: Any? @@ -75,6 +91,11 @@ import Foundation return self.type.stringValue() } + @objc func isPillBattery() -> Bool { + let systemType = self.detail as? SystemType + return self.type == .system && systemType == SystemType.pillBattery + } + fileprivate func process(info: NSDictionary!) { let type = info[PushNotification.keyType] as? String self.type = PushType.fromType(type: type ?? "") @@ -83,15 +104,14 @@ import Foundation case PushType.sleepScore: let isoDate = info[PushNotification.keyDetail] as? String self.detail = Date.from(isoDateOnly: isoDate) - break - case PushType.lowBattery: - fallthrough // detail is not used + case PushType.system: + let systemDetail = info[PushNotification.keyDetail] as? String + self.detail = SystemType.from(detail: systemDetail) case PushType.unknown: fallthrough default: break; } - } } From e1d1e415ca051d9cf2c683b9820e97c8be17004d Mon Sep 17 00:00:00 2001 From: Jimmy Lu Date: Thu, 16 Feb 2017 12:59:08 -0800 Subject: [PATCH 2/2] bumping to 2.0.3.7 --- CHANGELOG.md | 6 ++++++ Extensions/RoomConditions/Info.plist | 2 +- SleepModel/Sense-Info.plist | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12b3a562..af670a9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 2.0.3.7 + +New: + +* Pill battery notification now expected system type and pill_battery detail + ## 2.0.3.6 Fixes: diff --git a/Extensions/RoomConditions/Info.plist b/Extensions/RoomConditions/Info.plist index e7daee75..01545be3 100644 --- a/Extensions/RoomConditions/Info.plist +++ b/Extensions/RoomConditions/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 2.0.3.6 + 2.0.3.7 NSExtension NSExtensionMainStoryboard diff --git a/SleepModel/Sense-Info.plist b/SleepModel/Sense-Info.plist index 3f2b7965..5e376279 100644 --- a/SleepModel/Sense-Info.plist +++ b/SleepModel/Sense-Info.plist @@ -35,7 +35,7 @@ CFBundleVersion - 2.0.3.6 + 2.0.3.7 FacebookAppID 372438546161587 FacebookDisplayName