Skip to content

Commit

Permalink
Merge pull request #899 from hello/jimmy/pill
Browse files Browse the repository at this point in the history
pill battery notification payload expectation change
  • Loading branch information
jimmymlu authored Feb 16, 2017
2 parents 91bd224 + e1d1e41 commit a8ea07f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Extensions/RoomConditions/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2.0.3.6</string>
<string>2.0.3.7</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>
Expand Down
6 changes: 4 additions & 2 deletions SleepModel/HEMShortcutService.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 31 additions & 11 deletions SleepModel/PushNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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:
Expand All @@ -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?
Expand All @@ -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 ?? "")
Expand All @@ -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;
}

}

}
2 changes: 1 addition & 1 deletion SleepModel/Sense-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>2.0.3.6</string>
<string>2.0.3.7</string>
<key>FacebookAppID</key>
<string>372438546161587</string>
<key>FacebookDisplayName</key>
Expand Down

0 comments on commit a8ea07f

Please sign in to comment.