Skip to content
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

[LOOP-5153] Remove HealthKit dependency from LoopAlgorithm #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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: 0 additions & 4 deletions MinimedKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@
C1E34B7D29C7B075009A50A5 /* RileyLinkKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1E34B7C29C7B075009A50A5 /* RileyLinkKit.framework */; };
C1E34B8129C7B155009A50A5 /* PumpOpsSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E34B8029C7B155009A50A5 /* PumpOpsSession.swift */; };
C1E34B8329C7B1AB009A50A5 /* TimeZone.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E34B8229C7B1AB009A50A5 /* TimeZone.swift */; };
C1E34B8529C7B1D4009A50A5 /* HKUnit.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E34B8429C7B1D4009A50A5 /* HKUnit.swift */; };
C1E34B8829C7B292009A50A5 /* Comparable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E34B8729C7B292009A50A5 /* Comparable.swift */; };
C1E34B8A29C7B2FC009A50A5 /* LocalisedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E34B8929C7B2FC009A50A5 /* LocalisedString.swift */; };
C1E34B8C29C7B334009A50A5 /* IdentifiableClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E34B8B29C7B334009A50A5 /* IdentifiableClass.swift */; };
Expand Down Expand Up @@ -695,7 +694,6 @@
C1E34B7C29C7B075009A50A5 /* RileyLinkKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = RileyLinkKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C1E34B8029C7B155009A50A5 /* PumpOpsSession.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PumpOpsSession.swift; sourceTree = "<group>"; };
C1E34B8229C7B1AB009A50A5 /* TimeZone.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeZone.swift; sourceTree = "<group>"; };
C1E34B8429C7B1D4009A50A5 /* HKUnit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HKUnit.swift; sourceTree = "<group>"; };
C1E34B8729C7B292009A50A5 /* Comparable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Comparable.swift; sourceTree = "<group>"; };
C1E34B8929C7B2FC009A50A5 /* LocalisedString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalisedString.swift; sourceTree = "<group>"; };
C1E34B8B29C7B334009A50A5 /* IdentifiableClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentifiableClass.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1147,7 +1145,6 @@
C1E34B7829C7AFF7009A50A5 /* TimeInterval.swift */,
C1E34B7A29C7B044009A50A5 /* OSLog.swift */,
C1E34B8229C7B1AB009A50A5 /* TimeZone.swift */,
C1E34B8429C7B1D4009A50A5 /* HKUnit.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -1580,7 +1577,6 @@
C1E34AC329C7A98F009A50A5 /* DataFrameMessageBody.swift in Sources */,
C1E34A7629C7A98F009A50A5 /* ChangeSensorRateOfChangeAlertSetupPumpEvent.swift in Sources */,
C1E34AA929C7A98F009A50A5 /* MySentryAlertType.swift in Sources */,
C1E34B8529C7B1D4009A50A5 /* HKUnit.swift in Sources */,
C1E34ABC29C7A98F009A50A5 /* ChangeMaxBolusMessageBody.swift in Sources */,
C1E34A4229C7A98F009A50A5 /* PumpSettings.swift in Sources */,
C1E34AA129C7A98F009A50A5 /* DeviceLinkMessageBody.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2016 Nathan Racklyeft. All rights reserved.
//

import HealthKit
import LoopAlgorithm
import LoopKit


Expand Down Expand Up @@ -39,7 +39,7 @@ extension MySentryPumpStatusMessageBody: GlucoseDisplayable {
}
}

public var trendRate: HKQuantity? {
public var trendRate: LoopQuantity? {
return nil
}

Expand Down
23 changes: 0 additions & 23 deletions MinimedKit/Extensions/HKUnit.swift

This file was deleted.

5 changes: 2 additions & 3 deletions MinimedKit/PumpManager/EnliteSensorDisplayable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
//

import Foundation
import HealthKit
import LoopKit
import LoopAlgorithm

struct EnliteSensorDisplayable: Equatable, GlucoseDisplayable {
public let isStateValid: Bool
public let trendType: LoopKit.GlucoseTrend?
public let trendRate: HKQuantity?
public let trendRate: LoopQuantity?
public let isLocal: Bool

// TODO Placeholder. This functionality will come with LOOP-1311
Expand Down Expand Up @@ -50,7 +49,7 @@ extension MinimedKit.RelativeTimestampedGlucoseEvent {
return nil
}

var trendRate: HKQuantity? {
var trendRate: LoopQuantity? {
return nil
}

Expand Down
13 changes: 7 additions & 6 deletions MinimedKit/PumpManager/MinimedPumpManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import HealthKit
import LoopAlgorithm
import LoopKit
import RileyLinkKit
import RileyLinkBLEKit
Expand Down Expand Up @@ -430,7 +431,7 @@ extension MinimedPumpManager {
if let date = glucoseDateComponents?.date {
let sample = NewGlucoseSample(
date: date,
quantity: HKQuantity(unit: .milligramsPerDeciliter, doubleValue: Double(glucose)),
quantity: LoopQuantity(unit: .milligramsPerDeciliter, doubleValue: Double(glucose)),
condition: nil,
trend: status.glucoseTrend.loopKitGlucoseTrend,
trendRate: nil,
Expand Down Expand Up @@ -1430,13 +1431,13 @@ extension MinimedPumpManager: PumpManager {
try session.setMaxBasalRate(unitsPerHour: maxBasalRate)
}

if let maxBolus = deliveryLimits.maximumBolus?.doubleValue(for: .internationalUnit()) {
if let maxBolus = deliveryLimits.maximumBolus?.doubleValue(for: .internationalUnit) {
try session.setMaxBolus(units: maxBolus)
}

let settings = try session.getSettings()
let storedDeliveryLimits = DeliveryLimits(maximumBasalRate: HKQuantity(unit: .internationalUnitsPerHour, doubleValue: settings.maxBasal),
maximumBolus: HKQuantity(unit: .internationalUnit(), doubleValue: settings.maxBolus))
let storedDeliveryLimits = DeliveryLimits(maximumBasalRate: LoopQuantity(unit: .internationalUnitsPerHour, doubleValue: settings.maxBasal),
maximumBolus: LoopQuantity(unit: .internationalUnit, doubleValue: settings.maxBolus))
completion(.success(storedDeliveryLimits))
} catch let error {
self.log.error("Save delivery limit settings failed: %{public}@", String(describing: error))
Expand Down Expand Up @@ -1556,13 +1557,13 @@ extension MinimedPumpManager: CGMManager {
self.recents.sensorState = EnliteSensorDisplayable(latestSensorEvent)
}

let unit = HKUnit.milligramsPerDeciliter
let unit = LoopUnit.milligramsPerDeciliter
let glucoseValues: [NewGlucoseSample] = events
// TODO: Is the { $0.date > latestGlucoseDate } filter duplicative?
.filter({ $0.glucoseEvent is SensorValueGlucoseEvent && $0.date > latestGlucoseDate })
.map {
let glucoseEvent = $0.glucoseEvent as! SensorValueGlucoseEvent
let quantity = HKQuantity(unit: unit, doubleValue: Double(glucoseEvent.sgv))
let quantity = LoopQuantity(unit: unit, doubleValue: Double(glucoseEvent.sgv))
return NewGlucoseSample(date: $0.date, quantity: quantity, condition: nil, trend: glucoseEvent.trendType, trendRate: glucoseEvent.trendRate, isDisplayOnly: false, wasUserEntered: false, syncIdentifier: glucoseEvent.glucoseSyncIdentifier ?? UUID().uuidString, device: self.device)
}

Expand Down
6 changes: 3 additions & 3 deletions MinimedKitUI/Views/MinimedPumpSettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MinimedKit
import LoopKit
import SwiftUI
import LoopKitUI
import HealthKit
import LoopAlgorithm


enum MinimedSettingsViewAlert: Identifiable {
Expand Down Expand Up @@ -96,7 +96,7 @@ class MinimedPumpSettingsViewModel: ObservableObject {
}()

let reservoirVolumeFormatter = {
let formatter = QuantityFormatter(for: .internationalUnit())
let formatter = QuantityFormatter(for: .internationalUnit)
formatter.numberFormatter.maximumFractionDigits = 1
return formatter
}()
Expand Down Expand Up @@ -225,7 +225,7 @@ class MinimedPumpSettingsViewModel: ObservableObject {
}

func reservoirText(for units: Double) -> String {
let quantity = HKQuantity(unit: .internationalUnit(), doubleValue: units)
let quantity = LoopQuantity(unit: .internationalUnit, doubleValue: units)
return reservoirVolumeFormatter.string(from: quantity) ?? ""
}

Expand Down