Skip to content

Commit e01d4b2

Browse files
authored
Merge pull request #469 from LoopKit/get-loop-status
Rethink the API for clients to read loop status; other cleanup.
2 parents e8dc095 + a93487b commit e01d4b2

14 files changed

+831
-695
lines changed

Common/Extensions/NSTimeInterval.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import Foundation
1010

1111

1212
extension TimeInterval {
13+
static func minutes(_ minutes: Double) -> TimeInterval {
14+
return TimeInterval(minutes: minutes)
15+
}
16+
17+
static func hours(_ hours: Double) -> TimeInterval {
18+
return TimeInterval(hours: hours)
19+
}
20+
1321
init(minutes: Double) {
1422
self.init(minutes * 60)
1523
}

Common/Extensions/NumberFormatter.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,26 @@ extension NumberFormatter {
2020
return numberFormatter
2121
}
2222

23-
func describingGlucose(_ value: Double, for unit: HKUnit) -> String? {
24-
guard let stringValue = string(from: NSNumber(value: value)) else {
23+
func string(from number: Double, unit: String) -> String? {
24+
guard let stringValue = string(from: NSNumber(value: number)) else {
2525
return nil
2626
}
2727

2828
return String(
29-
format: NSLocalizedString("GLUCOSE_VALUE_AND_UNIT",
30-
value: "%1$@ %2$@",
31-
comment: "Format string for combining localized glucose value and unit. (1: glucose value)(2: unit)"
29+
format: NSLocalizedString(
30+
"QUANTITY_VALUE_AND_UNIT",
31+
value: "%1$@ %2$@",
32+
comment: "Format string for combining localized numeric value and unit. (1: numeric value)(2: unit)"
3233
),
3334
stringValue,
34-
unit.glucoseUnitDisplayString
35+
unit
3536
)
3637
}
3738

39+
func describingGlucose(_ value: Double, for unit: HKUnit) -> String? {
40+
return string(from: value, unit: unit.glucoseUnitDisplayString)
41+
}
42+
3843
@nonobjc func describingGlucose(_ value: HKQuantity, for unit: HKUnit) -> String? {
3944
return describingGlucose(value.doubleValue(for: unit), for: unit)
4045
}

Loop.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
439BED2A1E76093C00B0AED5 /* CGMManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 439BED291E76093C00B0AED5 /* CGMManager.swift */; };
7676
439BED2C1E760A7A00B0AED5 /* DexCGMManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 439BED2B1E760A7A00B0AED5 /* DexCGMManager.swift */; };
7777
439BED2E1E760BC600B0AED5 /* EnliteCGMManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 439BED2D1E760BC600B0AED5 /* EnliteCGMManager.swift */; };
78+
43A51E211EB6DBDD000736CC /* ChartsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43A51E201EB6DBDD000736CC /* ChartsTableViewController.swift */; };
7879
43A567691C94880B00334FAC /* LoopDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43A567681C94880B00334FAC /* LoopDataManager.swift */; };
7980
43A5676B1C96155700334FAC /* SwitchTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43A5676A1C96155700334FAC /* SwitchTableViewCell.swift */; };
8081
43A943761B926B7B0051FA24 /* Interface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 43A943741B926B7B0051FA24 /* Interface.storyboard */; };
@@ -429,6 +430,7 @@
429430
439BED291E76093C00B0AED5 /* CGMManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGMManager.swift; sourceTree = "<group>"; };
430431
439BED2B1E760A7A00B0AED5 /* DexCGMManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DexCGMManager.swift; sourceTree = "<group>"; };
431432
439BED2D1E760BC600B0AED5 /* EnliteCGMManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnliteCGMManager.swift; sourceTree = "<group>"; };
433+
43A51E201EB6DBDD000736CC /* ChartsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartsTableViewController.swift; sourceTree = "<group>"; };
432434
43A567681C94880B00334FAC /* LoopDataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = LoopDataManager.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
433435
43A5676A1C96155700334FAC /* SwitchTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwitchTableViewCell.swift; sourceTree = "<group>"; };
434436
43A943721B926B7B0051FA24 /* WatchApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WatchApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -853,6 +855,7 @@
853855
43DBF04B1C93B8D700B3C386 /* BolusViewController.swift */,
854856
4315D2861CA5CC3B00589052 /* CarbEntryEditTableViewController.swift */,
855857
43DBF0581C93F73800B3C386 /* CarbEntryTableViewController.swift */,
858+
43A51E201EB6DBDD000736CC /* ChartsTableViewController.swift */,
856859
433EA4C31D9F71C800CD78FB /* CommandResponseViewController.swift */,
857860
C178249F1E19CF9800D9D25C /* GlucoseThresholdTableViewController.swift */,
858861
4302F4E21D4EA54200F0FCAF /* InsulinDeliveryTableViewController.swift */,
@@ -1508,6 +1511,7 @@
15081511
4F70C2101DE8FAC5006380B7 /* StatusExtensionDataManager.swift in Sources */,
15091512
436FACEE1D0BA636004E2427 /* InsulinDataSource.swift in Sources */,
15101513
439897371CD2F80600223065 /* AnalyticsManager.swift in Sources */,
1514+
43A51E211EB6DBDD000736CC /* ChartsTableViewController.swift in Sources */,
15111515
4346D1F61C78501000ABAFE3 /* ChartPoint+Loop.swift in Sources */,
15121516
438849EE1D2A1EBB003B3F23 /* MLabService.swift in Sources */,
15131517
43D848B21E7DF42500DADCBC /* LoopSettings.swift in Sources */,

Loop/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
2727

2828
if let navVC = window?.rootViewController as? UINavigationController,
2929
let statusVC = navVC.viewControllers.first as? StatusTableViewController {
30-
statusVC.dataManager = deviceManager
30+
statusVC.deviceManager = deviceManager
3131
}
3232

3333
return true

Loop/Extensions/NSUserDefaults.swift

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,45 @@ import HealthKit
1414
extension UserDefaults {
1515

1616
private enum Key: String {
17-
case BasalRateSchedule = "com.loudnate.Naterade.BasalRateSchedule"
17+
case basalRateSchedule = "com.loudnate.Naterade.BasalRateSchedule"
18+
case batteryChemistry = "com.loopkit.Loop.BatteryChemistry"
1819
case cgmSettings = "com.loopkit.Loop.cgmSettings"
19-
case CarbRatioSchedule = "com.loudnate.Naterade.CarbRatioSchedule"
20-
case ConnectedPeripheralIDs = "com.loudnate.Naterade.ConnectedPeripheralIDs"
20+
case carbRatioSchedule = "com.loudnate.Naterade.CarbRatioSchedule"
21+
case connectedPeripheralIDs = "com.loudnate.Naterade.ConnectedPeripheralIDs"
2122
case loopSettings = "com.loopkit.Loop.loopSettings"
22-
case InsulinActionDuration = "com.loudnate.Naterade.InsulinActionDuration"
23-
case InsulinSensitivitySchedule = "com.loudnate.Naterade.InsulinSensitivitySchedule"
24-
case PreferredInsulinDataSource = "com.loudnate.Loop.PreferredInsulinDataSource"
25-
case PumpID = "com.loudnate.Naterade.PumpID"
26-
case PumpModelNumber = "com.loudnate.Naterade.PumpModelNumber"
27-
case PumpRegion = "com.loopkit.Loop.PumpRegion"
28-
case PumpTimeZone = "com.loudnate.Naterade.PumpTimeZone"
29-
case BatteryChemistry = "com.loopkit.Loop.BatteryChemistry"
23+
case insulinActionDuration = "com.loudnate.Naterade.InsulinActionDuration"
24+
case insulinCounteractionEffects = "com.loopkit.Loop.insulinCounteractionEffects"
25+
case insulinSensitivitySchedule = "com.loudnate.Naterade.InsulinSensitivitySchedule"
26+
case preferredInsulinDataSource = "com.loudnate.Loop.PreferredInsulinDataSource"
27+
case pumpID = "com.loudnate.Naterade.PumpID"
28+
case pumpModelNumber = "com.loudnate.Naterade.PumpModelNumber"
29+
case pumpRegion = "com.loopkit.Loop.PumpRegion"
30+
case pumpTimeZone = "com.loudnate.Naterade.PumpTimeZone"
3031
}
3132

3233
var basalRateSchedule: BasalRateSchedule? {
3334
get {
34-
if let rawValue = dictionary(forKey: Key.BasalRateSchedule.rawValue) {
35+
if let rawValue = dictionary(forKey: Key.basalRateSchedule.rawValue) {
3536
return BasalRateSchedule(rawValue: rawValue)
3637
} else {
3738
return nil
3839
}
3940
}
4041
set {
41-
set(newValue?.rawValue, forKey: Key.BasalRateSchedule.rawValue)
42+
set(newValue?.rawValue, forKey: Key.basalRateSchedule.rawValue)
4243
}
4344
}
4445

4546
var carbRatioSchedule: CarbRatioSchedule? {
4647
get {
47-
if let rawValue = dictionary(forKey: Key.CarbRatioSchedule.rawValue) {
48+
if let rawValue = dictionary(forKey: Key.carbRatioSchedule.rawValue) {
4849
return CarbRatioSchedule(rawValue: rawValue)
4950
} else {
5051
return nil
5152
}
5253
}
5354
set {
54-
set(newValue?.rawValue, forKey: Key.CarbRatioSchedule.rawValue)
55+
set(newValue?.rawValue, forKey: Key.carbRatioSchedule.rawValue)
5556
}
5657
}
5758

@@ -93,10 +94,10 @@ extension UserDefaults {
9394

9495
var connectedPeripheralIDs: [String] {
9596
get {
96-
return array(forKey: Key.ConnectedPeripheralIDs.rawValue) as? [String] ?? []
97+
return array(forKey: Key.connectedPeripheralIDs.rawValue) as? [String] ?? []
9798
}
9899
set {
99-
set(newValue, forKey: Key.ConnectedPeripheralIDs.rawValue)
100+
set(newValue, forKey: Key.connectedPeripheralIDs.rawValue)
100101
}
101102
}
102103

@@ -159,98 +160,98 @@ extension UserDefaults {
159160

160161
var insulinActionDuration: TimeInterval? {
161162
get {
162-
let value = double(forKey: Key.InsulinActionDuration.rawValue)
163+
let value = double(forKey: Key.insulinActionDuration.rawValue)
163164

164165
return value > 0 ? value : nil
165166
}
166167
set {
167168
if let insulinActionDuration = newValue {
168-
set(insulinActionDuration, forKey: Key.InsulinActionDuration.rawValue)
169+
set(insulinActionDuration, forKey: Key.insulinActionDuration.rawValue)
169170
} else {
170-
removeObject(forKey: Key.InsulinActionDuration.rawValue)
171+
removeObject(forKey: Key.insulinActionDuration.rawValue)
171172
}
172173
}
173174
}
174175

175176
var insulinSensitivitySchedule: InsulinSensitivitySchedule? {
176177
get {
177-
if let rawValue = dictionary(forKey: Key.InsulinSensitivitySchedule.rawValue) {
178+
if let rawValue = dictionary(forKey: Key.insulinSensitivitySchedule.rawValue) {
178179
return InsulinSensitivitySchedule(rawValue: rawValue)
179180
} else {
180181
return nil
181182
}
182183
}
183184
set {
184-
set(newValue?.rawValue, forKey: Key.InsulinSensitivitySchedule.rawValue)
185+
set(newValue?.rawValue, forKey: Key.insulinSensitivitySchedule.rawValue)
185186
}
186187
}
187188

188189
var preferredInsulinDataSource: InsulinDataSource? {
189190
get {
190-
return InsulinDataSource(rawValue: integer(forKey: Key.PreferredInsulinDataSource.rawValue))
191+
return InsulinDataSource(rawValue: integer(forKey: Key.preferredInsulinDataSource.rawValue))
191192
}
192193
set {
193194
if let preferredInsulinDataSource = newValue {
194-
set(preferredInsulinDataSource.rawValue, forKey: Key.PreferredInsulinDataSource.rawValue)
195+
set(preferredInsulinDataSource.rawValue, forKey: Key.preferredInsulinDataSource.rawValue)
195196
} else {
196-
removeObject(forKey: Key.PreferredInsulinDataSource.rawValue)
197+
removeObject(forKey: Key.preferredInsulinDataSource.rawValue)
197198
}
198199
}
199200
}
200201

201202
var pumpID: String? {
202203
get {
203-
return string(forKey: Key.PumpID.rawValue)
204+
return string(forKey: Key.pumpID.rawValue)
204205
}
205206
set {
206-
set(newValue, forKey: Key.PumpID.rawValue)
207+
set(newValue, forKey: Key.pumpID.rawValue)
207208
}
208209
}
209210

210211
var pumpModelNumber: String? {
211212
get {
212-
return string(forKey: Key.PumpModelNumber.rawValue)
213+
return string(forKey: Key.pumpModelNumber.rawValue)
213214
}
214215
set {
215-
set(newValue, forKey: Key.PumpModelNumber.rawValue)
216+
set(newValue, forKey: Key.pumpModelNumber.rawValue)
216217
}
217218
}
218219

219220
var pumpRegion: PumpRegion? {
220221
get {
221222
// Defaults to 0 / northAmerica
222-
return PumpRegion(rawValue: integer(forKey: Key.PumpRegion.rawValue))
223+
return PumpRegion(rawValue: integer(forKey: Key.pumpRegion.rawValue))
223224
}
224225
set {
225-
set(newValue?.rawValue, forKey: Key.PumpRegion.rawValue)
226+
set(newValue?.rawValue, forKey: Key.pumpRegion.rawValue)
226227
}
227228
}
228229

229230
var pumpTimeZone: TimeZone? {
230231
get {
231-
if let offset = object(forKey: Key.PumpTimeZone.rawValue) as? NSNumber {
232+
if let offset = object(forKey: Key.pumpTimeZone.rawValue) as? NSNumber {
232233
return TimeZone(secondsFromGMT: offset.intValue)
233234
} else {
234235
return nil
235236
}
236237
} set {
237238
if let value = newValue {
238-
set(NSNumber(value: value.secondsFromGMT() as Int), forKey: Key.PumpTimeZone.rawValue)
239+
set(NSNumber(value: value.secondsFromGMT() as Int), forKey: Key.pumpTimeZone.rawValue)
239240
} else {
240-
removeObject(forKey: Key.PumpTimeZone.rawValue)
241+
removeObject(forKey: Key.pumpTimeZone.rawValue)
241242
}
242243
}
243244
}
244245

245246
var batteryChemistry: BatteryChemistryType? {
246247
get {
247-
return BatteryChemistryType(rawValue: integer(forKey: Key.BatteryChemistry.rawValue))
248+
return BatteryChemistryType(rawValue: integer(forKey: Key.batteryChemistry.rawValue))
248249
}
249250
set {
250251
if let batteryChemistry = newValue {
251-
set(batteryChemistry.rawValue, forKey: Key.BatteryChemistry.rawValue)
252+
set(batteryChemistry.rawValue, forKey: Key.batteryChemistry.rawValue)
252253
} else {
253-
removeObject(forKey: Key.BatteryChemistry.rawValue)
254+
removeObject(forKey: Key.batteryChemistry.rawValue)
254255
}
255256
}
256257
}

0 commit comments

Comments
 (0)