Skip to content

Commit 6b6e5a7

Browse files
committed
Implement PumpManager protocol
1 parent 96a322e commit 6b6e5a7

File tree

69 files changed

+860
-2459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+860
-2459
lines changed

Cartfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
github "LoopKit/LoopKit" == 2.0
1+
github "LoopKit/LoopKit" "pump-manager"
22
github "LoopKit/CGMBLEKit" "dev"
33
github "i-schuetz/SwiftCharts" == 0.6.1
44
github "mddub/dexcom-share-client-swift" == 0.4.1
55
github "mddub/G4ShareSpy" == 0.3.3
6-
github "ps2/rileylink_ios" == 2.0.2
6+
github "ps2/rileylink_ios" "pump-manager"
77
github "LoopKit/Amplitude-iOS" "decreepify"

Cartfile.resolved

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
github "LoopKit/Amplitude-iOS" "2137d5fd44bf630ed33e1e72d7af6d8f8612f270"
2-
github "LoopKit/CGMBLEKit" "v2.1.0"
3-
github "LoopKit/LoopKit" "v2.0"
4-
github "i-schuetz/SwiftCharts" "6b55a26a7b0b95e49202ddc1db5404702fce114f"
2+
github "LoopKit/CGMBLEKit" "1f9d0f221b886f12bcb2c46dc0b551589b623210"
3+
github "LoopKit/LoopKit" "8afd78fac3cc20d2b99a022c01ce4f8f2853cb53"
4+
github "i-schuetz/SwiftCharts" "0.6.1"
55
github "mddub/G4ShareSpy" "v0.3.3"
66
github "mddub/dexcom-share-client-swift" "v0.4.1"
7-
github "ps2/rileylink_ios" "v2.0.2"
7+
github "ps2/rileylink_ios" "02aa66f1421bec4dda6fef9b38b2876398cb67a1"

Common/Extensions/NSUserDefaults.swift

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,16 @@
99
import Foundation
1010
import LoopKit
1111
import HealthKit
12-
import MinimedKit
13-
import RileyLinkKit
1412

1513

1614
extension UserDefaults {
1715

1816
private enum Key: String {
1917
case basalRateSchedule = "com.loudnate.Naterade.BasalRateSchedule"
2018
case carbRatioSchedule = "com.loudnate.Naterade.CarbRatioSchedule"
21-
case connectedPeripheralIDs = "com.loudnate.Naterade.ConnectedPeripheralIDs"
2219
case insulinModelSettings = "com.loopkit.Loop.insulinModelSettings"
2320
case loopSettings = "com.loopkit.Loop.loopSettings"
2421
case insulinSensitivitySchedule = "com.loudnate.Naterade.InsulinSensitivitySchedule"
25-
case pumpSettings = "com.loopkit.Loop.PumpSettings"
26-
case pumpState = "com.loopkit.Loop.PumpState"
2722
}
2823

2924
var basalRateSchedule: BasalRateSchedule? {
@@ -52,15 +47,6 @@ extension UserDefaults {
5247
}
5348
}
5449

55-
var connectedPeripheralIDs: [String] {
56-
get {
57-
return array(forKey: Key.connectedPeripheralIDs.rawValue) as? [String] ?? []
58-
}
59-
set {
60-
set(newValue, forKey: Key.connectedPeripheralIDs.rawValue)
61-
}
62-
}
63-
6450
var insulinModelSettings: InsulinModelSettings? {
6551
get {
6652
if let rawValue = dictionary(forKey: Key.insulinModelSettings.rawValue) {
@@ -150,70 +136,4 @@ extension UserDefaults {
150136
set(newValue?.rawValue, forKey: Key.insulinSensitivitySchedule.rawValue)
151137
}
152138
}
153-
154-
var pumpSettings: PumpSettings? {
155-
get {
156-
if let raw = dictionary(forKey: Key.pumpSettings.rawValue) {
157-
return PumpSettings(rawValue: raw)
158-
} else {
159-
// Migrate the version 0 case
160-
let standard = UserDefaults.standard
161-
defer {
162-
standard.removeObject(forKey: "com.loudnate.Naterade.PumpID")
163-
standard.removeObject(forKey: "com.loopkit.Loop.PumpRegion")
164-
}
165-
166-
guard let pumpID = standard.string(forKey: "com.loudnate.Naterade.PumpID") else {
167-
return nil
168-
}
169-
170-
let settings = PumpSettings(
171-
pumpID: pumpID,
172-
// Defaults to 0 / northAmerica
173-
pumpRegion: PumpRegion(rawValue: standard.integer(forKey: "com.loopkit.Loop.PumpRegion"))
174-
)
175-
176-
self.pumpSettings = settings
177-
178-
return settings
179-
}
180-
}
181-
set {
182-
set(newValue?.rawValue, forKey: Key.pumpSettings.rawValue)
183-
}
184-
}
185-
186-
var pumpState: PumpState? {
187-
get {
188-
if let raw = dictionary(forKey: Key.pumpState.rawValue) {
189-
return PumpState(rawValue: raw)
190-
} else {
191-
// Migrate the version 0 case
192-
let standard = UserDefaults.standard
193-
defer {
194-
standard.removeObject(forKey: "com.loudnate.Naterade.PumpModelNumber")
195-
standard.removeObject(forKey: "com.loudnate.Naterade.PumpTimeZone")
196-
}
197-
198-
var state = PumpState()
199-
200-
if let pumpModelNumber = standard.string(forKey: "com.loudnate.Naterade.PumpModelNumber") {
201-
state.pumpModel = PumpModel(rawValue: pumpModelNumber)
202-
}
203-
204-
if let offset = standard.object(forKey: "com.loudnate.Naterade.PumpTimeZone") as? NSNumber,
205-
let timeZone = TimeZone(secondsFromGMT: offset.intValue)
206-
{
207-
state.timeZone = timeZone
208-
}
209-
210-
self.pumpState = state
211-
212-
return state
213-
}
214-
}
215-
set {
216-
set(newValue?.rawValue, forKey: Key.pumpState.rawValue)
217-
}
218-
}
219139
}

Common/Models/CGM.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
//
77

88
import Foundation
9+
import LoopKit
910

1011

1112
enum CGM {
1213
case g5(transmitterID: String?)
1314
case g4
14-
case enlite
15+
case usePump
1516

1617
var appURL: URL? {
1718
switch self {
@@ -26,7 +27,7 @@ enum CGM {
2627
}
2728
}
2829
return nil
29-
case .enlite:
30+
case .usePump:
3031
return nil
3132
}
3233
}
@@ -51,8 +52,8 @@ extension CGM: RawRepresentable {
5152
self = .g5(transmitterID: rawValue["transmitterID"] as? String)
5253
case .g4?:
5354
self = .g4
54-
case .enlite?:
55-
self = .enlite
55+
case .usePump?:
56+
self = .usePump
5657
case .none:
5758
return nil
5859
}
@@ -61,14 +62,14 @@ extension CGM: RawRepresentable {
6162
private enum CGMType: String {
6263
case g5
6364
case g4
64-
case enlite
65+
case usePump = "enlite"
6566
}
6667

6768
private var type: CGMType {
6869
switch self {
6970
case .g5: return .g5
7071
case .g4: return .g4
71-
case .enlite: return .enlite
72+
case .usePump: return .usePump
7273
}
7374
}
7475

@@ -90,7 +91,7 @@ extension CGM: RawRepresentable {
9091
extension CGM: Equatable {
9192
static func ==(lhs: CGM, rhs: CGM) -> Bool {
9293
switch (lhs, rhs) {
93-
case (.g4, .g4), (.enlite, .enlite):
94+
case (.g4, .g4), (.usePump, .usePump):
9495
return true
9596
case (.g5(let a), .g5(let b)):
9697
return a == b

Common/Models/GlucoseTrend.swift

Lines changed: 0 additions & 58 deletions
This file was deleted.

Common/Models/LoopSettings.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77

88
import LoopKit
9-
import RileyLinkBLEKit
109

1110

1211
struct LoopSettings {

Common/Models/StatusExtensionContext.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import Foundation
1111
import HealthKit
1212
import LoopKit
13-
import LoopUI
1413

1514

1615
struct NetBasalContext {
@@ -154,12 +153,13 @@ extension PredictedGlucoseContext: RawRepresentable {
154153

155154
struct StatusExtensionContext: RawRepresentable {
156155
typealias RawValue = [String: Any]
157-
private let version = 4
156+
private let version = 5
158157

159158
var predictedGlucose: PredictedGlucoseContext?
160159
var lastLoopCompleted: Date?
161160
var netBasal: NetBasalContext?
162161
var batteryPercentage: Double?
162+
var reservoirCapacity: Double?
163163
var sensor: SensorDisplayableContext?
164164

165165
init() { }
@@ -179,6 +179,7 @@ struct StatusExtensionContext: RawRepresentable {
179179

180180
lastLoopCompleted = rawValue["lastLoopCompleted"] as? Date
181181
batteryPercentage = rawValue["batteryPercentage"] as? Double
182+
reservoirCapacity = rawValue["reservoirCapacity"] as? Double
182183

183184
if let rawValue = rawValue["sensor"] as? SensorDisplayableContext.RawValue {
184185
sensor = SensorDisplayableContext(rawValue: rawValue)
@@ -194,6 +195,7 @@ struct StatusExtensionContext: RawRepresentable {
194195
raw["lastLoopCompleted"] = lastLoopCompleted
195196
raw["netBasal"] = netBasal?.rawValue
196197
raw["batteryPercentage"] = batteryPercentage
198+
raw["reservoirCapacity"] = reservoirCapacity
197199
raw["sensor"] = sensor?.rawValue
198200
return raw
199201
}

Loop Status Extension/StatusViewController.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,8 @@ class StatusViewController: UIViewController, NCWidgetProviding {
205205
self.hudView.batteryHUD.batteryLevel = Double(batteryPercentage)
206206
}
207207

208-
if let reservoir = lastReservoirValue,
209-
let capacity = defaults.pumpState?.pumpModel?.reservoirCapacity
210-
{
211-
self.hudView.reservoirVolumeHUD.reservoirLevel = min(1, max(0, Double(reservoir.unitVolume / Double(capacity))))
208+
if let reservoir = lastReservoirValue, let capacity = context.reservoirCapacity {
209+
self.hudView.reservoirVolumeHUD.reservoirLevel = min(1, max(0, Double(reservoir.unitVolume / capacity)))
212210
self.hudView.reservoirVolumeHUD.setReservoirVolume(volume: reservoir.unitVolume, at: reservoir.startDate)
213211
}
214212

Loop Status Extension/UIColor+Widget.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
import UIKit
10-
import LoopUI
10+
1111

1212
extension UIColor {
1313
@nonobjc static let axisLabelColor = subtitleLabelColor

0 commit comments

Comments
 (0)