Skip to content

Implement PumpManager protocol #753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github "LoopKit/LoopKit" == 2.0
github "LoopKit/LoopKit" "dev"
github "LoopKit/CGMBLEKit" "dev"
github "i-schuetz/SwiftCharts" == 0.6.1
github "mddub/dexcom-share-client-swift" == 0.4.1
github "mddub/G4ShareSpy" == 0.3.3
github "ps2/rileylink_ios" == 2.0.2
github "ps2/rileylink_ios" "dev"
github "LoopKit/Amplitude-iOS" "decreepify"
8 changes: 4 additions & 4 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github "LoopKit/Amplitude-iOS" "2137d5fd44bf630ed33e1e72d7af6d8f8612f270"
github "LoopKit/CGMBLEKit" "v2.1.0"
github "LoopKit/LoopKit" "v2.0"
github "i-schuetz/SwiftCharts" "6b55a26a7b0b95e49202ddc1db5404702fce114f"
github "LoopKit/CGMBLEKit" "1f9d0f221b886f12bcb2c46dc0b551589b623210"
github "LoopKit/LoopKit" "f2f82d9bd67cd329b4021b365b7ebdec4b39f0af"
github "i-schuetz/SwiftCharts" "0.6.1"
github "mddub/G4ShareSpy" "v0.3.3"
github "mddub/dexcom-share-client-swift" "v0.4.1"
github "ps2/rileylink_ios" "v2.0.2"
github "ps2/rileylink_ios" "3b257bdfa5f01ebaa343c9e6e1c2140ffd2569a1"
80 changes: 0 additions & 80 deletions Common/Extensions/NSUserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@
import Foundation
import LoopKit
import HealthKit
import MinimedKit
import RileyLinkKit


extension UserDefaults {

private enum Key: String {
case basalRateSchedule = "com.loudnate.Naterade.BasalRateSchedule"
case carbRatioSchedule = "com.loudnate.Naterade.CarbRatioSchedule"
case connectedPeripheralIDs = "com.loudnate.Naterade.ConnectedPeripheralIDs"
case insulinModelSettings = "com.loopkit.Loop.insulinModelSettings"
case loopSettings = "com.loopkit.Loop.loopSettings"
case insulinSensitivitySchedule = "com.loudnate.Naterade.InsulinSensitivitySchedule"
case pumpSettings = "com.loopkit.Loop.PumpSettings"
case pumpState = "com.loopkit.Loop.PumpState"
}

var basalRateSchedule: BasalRateSchedule? {
Expand Down Expand Up @@ -52,15 +47,6 @@ extension UserDefaults {
}
}

var connectedPeripheralIDs: [String] {
get {
return array(forKey: Key.connectedPeripheralIDs.rawValue) as? [String] ?? []
}
set {
set(newValue, forKey: Key.connectedPeripheralIDs.rawValue)
}
}

var insulinModelSettings: InsulinModelSettings? {
get {
if let rawValue = dictionary(forKey: Key.insulinModelSettings.rawValue) {
Expand Down Expand Up @@ -150,70 +136,4 @@ extension UserDefaults {
set(newValue?.rawValue, forKey: Key.insulinSensitivitySchedule.rawValue)
}
}

var pumpSettings: PumpSettings? {
get {
if let raw = dictionary(forKey: Key.pumpSettings.rawValue) {
return PumpSettings(rawValue: raw)
} else {
// Migrate the version 0 case
let standard = UserDefaults.standard
defer {
standard.removeObject(forKey: "com.loudnate.Naterade.PumpID")
standard.removeObject(forKey: "com.loopkit.Loop.PumpRegion")
}

guard let pumpID = standard.string(forKey: "com.loudnate.Naterade.PumpID") else {
return nil
}

let settings = PumpSettings(
pumpID: pumpID,
// Defaults to 0 / northAmerica
pumpRegion: PumpRegion(rawValue: standard.integer(forKey: "com.loopkit.Loop.PumpRegion"))
)

self.pumpSettings = settings

return settings
}
}
set {
set(newValue?.rawValue, forKey: Key.pumpSettings.rawValue)
}
}

var pumpState: PumpState? {
get {
if let raw = dictionary(forKey: Key.pumpState.rawValue) {
return PumpState(rawValue: raw)
} else {
// Migrate the version 0 case
let standard = UserDefaults.standard
defer {
standard.removeObject(forKey: "com.loudnate.Naterade.PumpModelNumber")
standard.removeObject(forKey: "com.loudnate.Naterade.PumpTimeZone")
}

var state = PumpState()

if let pumpModelNumber = standard.string(forKey: "com.loudnate.Naterade.PumpModelNumber") {
state.pumpModel = PumpModel(rawValue: pumpModelNumber)
}

if let offset = standard.object(forKey: "com.loudnate.Naterade.PumpTimeZone") as? NSNumber,
let timeZone = TimeZone(secondsFromGMT: offset.intValue)
{
state.timeZone = timeZone
}

self.pumpState = state

return state
}
}
set {
set(newValue?.rawValue, forKey: Key.pumpState.rawValue)
}
}
}
15 changes: 8 additions & 7 deletions Common/Models/CGM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
//

import Foundation
import LoopKit


enum CGM {
case g5(transmitterID: String?)
case g4
case enlite
case usePump

var appURL: URL? {
switch self {
Expand All @@ -26,7 +27,7 @@ enum CGM {
}
}
return nil
case .enlite:
case .usePump:
return nil
}
}
Expand All @@ -51,8 +52,8 @@ extension CGM: RawRepresentable {
self = .g5(transmitterID: rawValue["transmitterID"] as? String)
case .g4?:
self = .g4
case .enlite?:
self = .enlite
case .usePump?:
self = .usePump
case .none:
return nil
}
Expand All @@ -61,14 +62,14 @@ extension CGM: RawRepresentable {
private enum CGMType: String {
case g5
case g4
case enlite
case usePump = "enlite"
}

private var type: CGMType {
switch self {
case .g5: return .g5
case .g4: return .g4
case .enlite: return .enlite
case .usePump: return .usePump
}
}

Expand All @@ -90,7 +91,7 @@ extension CGM: RawRepresentable {
extension CGM: Equatable {
static func ==(lhs: CGM, rhs: CGM) -> Bool {
switch (lhs, rhs) {
case (.g4, .g4), (.enlite, .enlite):
case (.g4, .g4), (.usePump, .usePump):
return true
case (.g5(let a), .g5(let b)):
return a == b
Expand Down
58 changes: 0 additions & 58 deletions Common/Models/GlucoseTrend.swift

This file was deleted.

1 change: 0 additions & 1 deletion Common/Models/LoopSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import LoopKit
import RileyLinkBLEKit


struct LoopSettings {
Expand Down
6 changes: 4 additions & 2 deletions Common/Models/StatusExtensionContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import Foundation
import HealthKit
import LoopKit
import LoopUI


struct NetBasalContext {
Expand Down Expand Up @@ -154,12 +153,13 @@ extension PredictedGlucoseContext: RawRepresentable {

struct StatusExtensionContext: RawRepresentable {
typealias RawValue = [String: Any]
private let version = 4
private let version = 5

var predictedGlucose: PredictedGlucoseContext?
var lastLoopCompleted: Date?
var netBasal: NetBasalContext?
var batteryPercentage: Double?
var reservoirCapacity: Double?
var sensor: SensorDisplayableContext?

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

lastLoopCompleted = rawValue["lastLoopCompleted"] as? Date
batteryPercentage = rawValue["batteryPercentage"] as? Double
reservoirCapacity = rawValue["reservoirCapacity"] as? Double

if let rawValue = rawValue["sensor"] as? SensorDisplayableContext.RawValue {
sensor = SensorDisplayableContext(rawValue: rawValue)
Expand All @@ -194,6 +195,7 @@ struct StatusExtensionContext: RawRepresentable {
raw["lastLoopCompleted"] = lastLoopCompleted
raw["netBasal"] = netBasal?.rawValue
raw["batteryPercentage"] = batteryPercentage
raw["reservoirCapacity"] = reservoirCapacity
raw["sensor"] = sensor?.rawValue
return raw
}
Expand Down
6 changes: 2 additions & 4 deletions Loop Status Extension/StatusViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ class StatusViewController: UIViewController, NCWidgetProviding {
self.hudView.batteryHUD.batteryLevel = Double(batteryPercentage)
}

if let reservoir = lastReservoirValue,
let capacity = defaults.pumpState?.pumpModel?.reservoirCapacity
{
self.hudView.reservoirVolumeHUD.reservoirLevel = min(1, max(0, Double(reservoir.unitVolume / Double(capacity))))
if let reservoir = lastReservoirValue, let capacity = context.reservoirCapacity {
self.hudView.reservoirVolumeHUD.reservoirLevel = min(1, max(0, Double(reservoir.unitVolume / capacity)))
self.hudView.reservoirVolumeHUD.setReservoirVolume(volume: reservoir.unitVolume, at: reservoir.startDate)
}

Expand Down
2 changes: 1 addition & 1 deletion Loop Status Extension/UIColor+Widget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import UIKit
import LoopUI


extension UIColor {
@nonobjc static let axisLabelColor = subtitleLabelColor
Expand Down
Loading