Skip to content

Commit

Permalink
Merge pull request #291 from nightscout/dev
Browse files Browse the repository at this point in the history
Merge dev into feat/dana
  • Loading branch information
bjornoleh authored Jun 9, 2024
2 parents d8d5d2d + 32b5e95 commit 0ac6bd8
Show file tree
Hide file tree
Showing 62 changed files with 893 additions and 270 deletions.
2 changes: 1 addition & 1 deletion FreeAPS/Resources/javascript/bundle/autosens.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion FreeAPS/Resources/javascript/bundle/autotune-prep.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion FreeAPS/Resources/javascript/bundle/iob.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion FreeAPS/Resources/javascript/bundle/meal.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion FreeAPS/Resources/javascript/bundle/profile.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions FreeAPS/Resources/json/defaults/freeaps/freeaps_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
"oneDimensionalGraph" : false,
"rulerMarks" : true,
"maxCarbs": 250,
"maxFat": 250,
"maxProtein": 250,
"displayFatAndProteinOnWatch": false,
"confirmBolusFaster": false,
"lockScreenView": "simple"
}
2 changes: 1 addition & 1 deletion FreeAPS/Resources/json/defaults/preferences.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
"tddAdjBasal" : false,
"enableSMB_high_bg" : false,
"enableSMB_high_bg_target" : 110,
"threshold_setting" : 65,
"threshold_setting" : 60,
"updateInterval" : 20
}
66 changes: 17 additions & 49 deletions FreeAPS/Sources/APS/DeviceDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ private let staticPumpManagersByIdentifier: [String: PumpManagerUI.Type] = [
MockPumpManager.pluginIdentifier: MockPumpManager.self
]

// private let staticPumpManagersByIdentifier: [String: PumpManagerUI.Type] = staticPumpManagers.reduce(into: [:]) { map, Type in
// map[Type.managerIdentifier] = Type
// }

private let accessLock = NSRecursiveLock(label: "BaseDeviceDataManager.accessLock")

final class BaseDeviceDataManager: DeviceDataManager, Injectable {
Expand Down Expand Up @@ -81,7 +77,8 @@ final class BaseDeviceDataManager: DeviceDataManager, Injectable {
didSet {
pumpManager?.pumpManagerDelegate = self
pumpManager?.delegateQueue = processQueue
UserDefaults.standard.pumpManagerRawValue = pumpManager?.rawValue
rawPumpManager = pumpManager?.rawValue
UserDefaults.standard.clearLegacyPumpManagerRawValue()
if let pumpManager = pumpManager {
pumpDisplayState.value = PumpDisplayState(name: pumpManager.localizedTitle, image: pumpManager.smallImage)
pumpName.send(pumpManager.localizedTitle)
Expand All @@ -108,6 +105,8 @@ final class BaseDeviceDataManager: DeviceDataManager, Injectable {
}
}

@PersistedProperty(key: "PumpManagerState") var rawPumpManager: PumpManager.RawValue?

var bluetoothManager: BluetoothStateManager { bluetoothProvider }

var hasBLEHeartbeat: Bool {
Expand All @@ -126,7 +125,11 @@ final class BaseDeviceDataManager: DeviceDataManager, Injectable {
}

func setupPumpManager() {
pumpManager = UserDefaults.standard.pumpManagerRawValue.flatMap { pumpManagerFromRawValue($0) }
if let pumpManagerRawValue = rawPumpManager ?? UserDefaults.standard.legacyPumpManagerRawValue {
pumpManager = pumpManagerFromRawValue(pumpManagerRawValue)
} else {
pumpManager = nil
}
}

func createBolusProgressReporter() -> DoseProgressReporter? {
Expand Down Expand Up @@ -166,20 +169,6 @@ final class BaseDeviceDataManager: DeviceDataManager, Injectable {
self.updateUpdateFinished(true)
}
}

// pumpUpdateCancellable = Future<Bool, Never> { [unowned self] promise in
// pumpUpdatePromise = promise
// debug(.deviceManager, "Waiting for pump update and loop recommendation")
// processQueue.safeSync {
// pumpManager.ensureCurrentPumpData { _ in
// debug(.deviceManager, "Pump data updated.")
// }
// }
// }
// .timeout(30, scheduler: processQueue)
// .replaceError(with: false)
// .replaceEmpty(with: false)
// .sink(receiveValue: updateUpdateFinished)
}

private func updateUpdateFinished(_ recommendsLoop: Bool) {
Expand All @@ -189,11 +178,6 @@ final class BaseDeviceDataManager: DeviceDataManager, Injectable {
warning(.deviceManager, "Loop recommendation time out or got error. Trying to loop right now.")
}

// directly in loop() function
// guard !loopInProgress else {
// warning(.deviceManager, "Loop already in progress. Skip recommendation.")
// return
// }
self.recommendsLoop.send()
}

Expand Down Expand Up @@ -322,7 +306,7 @@ extension BaseDeviceDataManager: PumpManagerDelegate {
}

func pumpManagerDidUpdateState(_ pumpManager: PumpManager) {
UserDefaults.standard.pumpManagerRawValue = pumpManager.rawValue
rawPumpManager = pumpManager.rawValue
if self.pumpManager == nil, let newPumpManager = pumpManager as? PumpManagerUI {
self.pumpManager = newPumpManager
}
Expand Down Expand Up @@ -434,6 +418,9 @@ extension BaseDeviceDataManager: PumpManagerDelegate {
func pumpManagerWillDeactivate(_: PumpManager) {
dispatchPrecondition(condition: .onQueue(processQueue))
pumpManager = nil
broadcaster.notify(PumpDeactivatedObserver.self, on: processQueue) {
$0.pumpDeactivatedDidChange()
}
}

func pumpManager(_: PumpManager, didUpdatePumpRecordsBasalProfileStartEvents _: Bool) {}
Expand Down Expand Up @@ -540,29 +527,6 @@ extension BaseDeviceDataManager: DeviceManagerDelegate {

func recordRetractedAlert(_: Alert, at _: Date) {}

// func scheduleNotification(
// for _: DeviceManager,
// identifier: String,
// content: UNNotificationContent,
// trigger: UNNotificationTrigger?
// ) {
// let request = UNNotificationRequest(
// identifier: identifier,
// content: content,
// trigger: trigger
// )
//
// DispatchQueue.main.async {
// UNUserNotificationCenter.current().add(request)
// }
// }
//
// func clearNotification(for _: DeviceManager, identifier: String) {
// DispatchQueue.main.async {
// UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [identifier])
// }
// }

func removeNotificationRequests(for _: DeviceManager, identifiers: [String]) {
DispatchQueue.main.async {
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: identifiers)
Expand Down Expand Up @@ -670,3 +634,7 @@ protocol PumpReservoirObserver {
protocol PumpBatteryObserver {
func pumpBatteryDidChange(_ battery: Battery)
}

protocol PumpDeactivatedObserver {
func pumpDeactivatedDidChange()
}
18 changes: 2 additions & 16 deletions FreeAPS/Sources/APS/Extensions/PumpManagerExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import LoopKit
import LoopKitUI

extension PumpManager {
typealias RawValue = [String: Any]

var rawValue: [String: Any] {
[
"managerIdentifier": pluginIdentifier, // "managerIdentifier": type(of: self).managerIdentifier,
Expand All @@ -11,14 +13,6 @@ extension PumpManager {
}

extension PumpManagerUI {
// static func setupViewController() -> PumpManagerSetupViewController & UIViewController & CompletionNotifying {
// setupViewController(
// insulinTintColor: .accentColor,
// guidanceColors: GuidanceColors(acceptable: .green, warning: .orange, critical: .red),
// allowedInsulinTypes: [.apidra, .humalog, .novolog, .fiasp, .lyumjev]
// )
// }

func settingsViewController(
bluetoothProvider: BluetoothProvider,
pumpManagerOnboardingDelegate: PumpManagerOnboardingDelegate?
Expand All @@ -32,14 +26,6 @@ extension PumpManagerUI {
vc.pumpManagerOnboardingDelegate = pumpManagerOnboardingDelegate
return vc
}

// func settingsViewController() -> UIViewController & CompletionNotifying {
// settingsViewController(
// insulinTintColor: .accentColor,
// guidanceColors: GuidanceColors(acceptable: .green, warning: .orange, critical: .red),
// allowedInsulinTypes: [.apidra, .humalog, .novolog, .fiasp, .lyumjev]
// )
// }
}

protocol PumpSettingsBuilder {
Expand Down
29 changes: 19 additions & 10 deletions FreeAPS/Sources/APS/Extensions/UserDefaultsExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@ import RileyLinkKit

extension UserDefaults {
private enum Key: String {
case pumpManagerRawValue = "com.rileylink.PumpManagerRawValue"
case legacyPumpManagerRawValue = "com.rileylink.PumpManagerRawValue"
case rileyLinkConnectionManagerState = "com.rileylink.RileyLinkConnectionManagerState"
}

var pumpManagerRawValue: PumpManager.RawStateValue? {
get {
dictionary(forKey: Key.pumpManagerRawValue.rawValue)
}
set {
set(newValue, forKey: Key.pumpManagerRawValue.rawValue)
}
case legacyPumpManagerState = "com.loopkit.Loop.PumpManagerState"
case legacyCGMManagerState = "com.loopkit.Loop.CGMManagerState"
}

var rileyLinkConnectionManagerState: RileyLinkConnectionState? {
Expand All @@ -30,4 +23,20 @@ extension UserDefaults {
set(newValue?.rawValue, forKey: Key.rileyLinkConnectionManagerState.rawValue)
}
}

var legacyPumpManagerRawValue: PumpManager.RawValue? {
dictionary(forKey: Key.legacyPumpManagerRawValue.rawValue)
}

func clearLegacyPumpManagerRawValue() {
set(nil, forKey: Key.legacyPumpManagerRawValue.rawValue)
}

var legacyCGMManagerRawValue: CGMManager.RawValue? {
dictionary(forKey: Key.legacyCGMManagerState.rawValue)
}

func clearLegacyCGMManagerRawValue() {
set(nil, forKey: Key.legacyCGMManagerState.rawValue)
}
}
1 change: 1 addition & 0 deletions FreeAPS/Sources/APS/FetchGlucoseManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ final class BaseFetchGlucoseManager: FetchGlucoseManager, Injectable {
var cgmManager: CGMManagerUI? {
didSet {
rawCGMManager = cgmManager?.rawValue
UserDefaults.standard.clearLegacyCGMManagerRawValue()
}
}

Expand Down
4 changes: 2 additions & 2 deletions FreeAPS/Sources/APS/Storage/CarbsStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ final class BaseCarbsStorage: CarbsStorage, Injectable {
bolus: nil,
insulin: nil,
carbs: $0.carbs,
fat: nil,
protein: nil,
fat: $0.fat,
protein: $0.protein,
foodType: $0.note,
targetTop: nil,
targetBottom: nil
Expand Down
4 changes: 2 additions & 2 deletions FreeAPS/Sources/APS/Storage/PumpHistoryStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ extension NightscoutTreatment {
insulin: nil,
notes: nil,
carbs: Decimal(event.carbInput ?? 0),
fat: nil,
protein: nil,
fat: Decimal(event.fatInput ?? 0),
protein: Decimal(event.proteinInput ?? 0),
targetTop: nil,
targetBottom: nil
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import Foundation
self.key = key

let documents: URL

guard let localDocuments = try? FileManager.default.url(
for: .documentDirectory,
in: .userDomainMask,
Expand Down
33 changes: 27 additions & 6 deletions FreeAPS/Sources/Localizations/Main/ar.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,30 @@ Enact a temp Basal or a temp target */
/* Max setting */
"Max Carbs" = "Max Carbs";

/* Max setting */
"Max Fat" = "Max Fat";

/* Max setting */
"Max Protein" = "Max Protein";

/* Max setting */
"Limit Per Entry" = "Limit Per Entry";

/* Max Carbs limit exceeded */
"Max Carbs of" = "Max Carbs of";

/* Max Fat limit exceeded */
"Max Fat of" = "Max Fat of";

/* Max Protein limit exceeded */
"Max Protein of" = "Max Protein of";

/* Max Bolus limit exceeded */
"Max Bolus of" = "Max Bolus of";

/* Limit Exceeded label */
"exceeded" = "exceeded";

/* */
"Pump Settings" = "Pump Settings";

Expand Down Expand Up @@ -1052,9 +1076,6 @@ Enact a temp Basal or a temp target */
/* */
"Bolus failed" = "Bolus failed";

/* "Max Bolus Exceeded label" */
"Max Bolus exceeded!" = "Max Bolus exceeded!";

/* */
"Bolus failed or inaccurate. Check pump history before repeating." = "Bolus failed or inaccurate. Check pump history before repeating.";

Expand Down Expand Up @@ -2074,10 +2095,10 @@ Enact a temp Basal or a temp target */
"Use a sigmoid function for ISF (and for CR, when enabled), instead of the default Logarithmic formula. Requires the Dynamic ISF setting to be enabled in settings\n\nThe Adjustment setting adjusts the slope of the curve (Y: Dynamic ratio, X: Blood Glucose). A lower value ==> less steep == less aggressive.\n\nThe autosens.min/max settings determines both the max/min limits for the dynamic ratio AND how much the dynamic ratio is adjusted. If AF is the slope of the curve, the autosens.min/max is the height of the graph, the Y-interval, where Y: dynamic ratio. The curve will always have a sigmoid shape, no matter which autosens.min/max settings are used, meaning these settings have big consequences for the outcome of the computed dynamic ISF. Please be careful setting a too high autosens.max value. With a proper profile ISF setting, you will probably never need it to be higher than 1.5\n\nAn Autosens.max limit > 1.5 is not advisable when using the sigmoid function." = "Use a sigmoid function for ISF (and for CR, when enabled), instead of the default Logarithmic formula. Requires the Dynamic ISF setting to be enabled in settings\n\nThe Adjustment setting adjusts the slope of the curve (Y: Dynamic ratio, X: Blood Glucose). A lower value ==> less steep == less aggressive.\n\nThe autosens.min/max settings determines both the max/min limits for the dynamic ratio AND how much the dynamic ratio is adjusted. If AF is the slope of the curve, the autosens.min/max is the height of the graph, the Y-interval, where Y: dynamic ratio. The curve will always have a sigmoid shape, no matter which autosens.min/max settings are used, meaning these settings have big consequences for the outcome of the computed dynamic ISF. Please be careful setting a too high autosens.max value. With a proper profile ISF setting, you will probably never need it to be higher than 1.5\n\nAn Autosens.max limit > 1.5 is not advisable when using the sigmoid function.";

/* Headline Threshold Setting */
"Threshold Setting" = "Threshold Setting";
"Minimum Safety Threshold (mg/dL)" = "Minimum Safety Threshold (mg/dL)";

/* Threshold Setting */
"The default threshold in Trio depends on your current minimum BG target, as follows:\n\nIf your minimum BG target = 90 mg/dl -> threshold = 65 mg/dl,\n\nif minimum BG target = 100 mg/dl -> threshold = 70 mg/dl,\n\nminimum BG target = 110 mg/dl -> threshold = 75 mg/dl,\n\nand if minimum BG target = 130 mg/dl -> threshold = 85 mg/dl.\n\nThis setting allows you to change the default to a higher threshold for looping with dynISF. Valid values are 65 mg/dl<= Threshold Setting <= 120 mg/dl." = "The default threshold in Trio depends on your current minimum BG target, as follows:\n\nIf your minimum BG target = 90 mg/dl -> threshold = 65 mg/dl,\n\nif minimum BG target = 100 mg/dl -> threshold = 70 mg/dl,\n\nminimum BG target = 110 mg/dl -> threshold = 75 mg/dl,\n\nand if minimum BG target = 130 mg/dl -> threshold = 85 mg/dl.\n\nThis setting allows you to change the default to a higher threshold for looping with dynISF. Valid values are 65 mg/dl<= Threshold Setting <= 120 mg/dl.";
/* Minimum Safety Threshold */
"All insulin will be suspended if your glucose is predicted to drop below the safety threshold.\n\nMust be set between 60-120 mg/dL.\nTo convert from mmol/L, multiply by 18.\n\nNote: Basal may be resumed if there's negative IOB and glucose is rising faster than predicted." = "All insulin will be suspended if your glucose is predicted to drop below the safety threshold.\n\nMust be set between 60-120 mg/dL.\nTo convert from mmol/L, multiply by 18.\n\nNote: Basal may be resumed if there's negative IOB and glucose is rising faster than predicted.";

/* Header */
"Calculator settings" = "Calculator settings";
Expand Down
35 changes: 31 additions & 4 deletions FreeAPS/Sources/Localizations/Main/ca.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,33 @@ Enact a temp Basal or a temp target */
/* Max setting */
"Max Bolus" = "Max Bolus";

/* Max setting */
"Max Carbs" = "Max Carbs";

/* Max setting */
"Max Fat" = "Max Fat";

/* Max setting */
"Max Protein" = "Max Protein";

/* Max setting */
"Limit Per Entry" = "Limit Per Entry";

/* Max Carbs limit exceeded */
"Max Carbs of" = "Max Carbs of";

/* Max Fat limit exceeded */
"Max Fat of" = "Max Fat of";

/* Max Protein limit exceeded */
"Max Protein of" = "Max Protein of";

/* Max Bolus limit exceeded */
"Max Bolus of" = "Max Bolus of";

/* Limit Exceeded label */
"exceeded" = "exceeded";

/* */
"Pump Settings" = "Pump Settings";

Expand Down Expand Up @@ -1847,11 +1874,11 @@ Enact a temp Basal or a temp target */
"Use a sigmoid function for ISF (and for CR, when enabled), instead of the default Logarithmic formula. Requires the Dynamic ISF setting to be enabled in settings\n\nThe Adjustment setting adjusts the slope of the curve (Y: Dynamic ratio, X: Blood Glucose). A lower value ==> less steep == less aggressive.\n\nThe autosens.min/max settings determines both the max/min limits for the dynamic ratio AND how much the dynamic ratio is adjusted. If AF is the slope of the curve, the autosens.min/max is the height of the graph, the Y-interval, where Y: dynamic ratio. The curve will always have a sigmoid shape, no matter which autosens.min/max settings are used, meaning these settings have big consequences for the outcome of the computed dynamic ISF. Please be careful setting a too high autosens.max value. With a proper profile ISF setting, you will probably never need it to be higher than 1.5\n\nAn Autosens.max limit > 1.5 is not advisable when using the sigmoid function." = "Use a sigmoid function for ISF (and for CR, when enabled), instead of the default Logarithmic formula. Requires the Dynamic ISF setting to be enabled in settings\n\nThe Adjustment setting adjusts the slope of the curve (Y: Dynamic ratio, X: Blood Glucose). A lower value ==> less steep == less aggressive.\n\nThe autosens.min/max settings determines both the max/min limits for the dynamic ratio AND how much the dynamic ratio is adjusted. If AF is the slope of the curve, the autosens.min/max is the height of the graph, the Y-interval, where Y: dynamic ratio. The curve will always have a sigmoid shape, no matter which autosens.min/max settings are used, meaning these settings have big consequences for the outcome of the computed dynamic ISF. Please be careful setting a too high autosens.max value. With a proper profile ISF setting, you will probably never need it to be higher than 1.5\n\nAn Autosens.max limit > 1.5 is not advisable when using the sigmoid function.";


/* Headline "Threshold Setting" */
"Threshold Setting (mg/dl)" = "Threshold Setting (mg/dl)";
/* Headline Threshold Setting */
"Minimum Safety Threshold (mg/dL)" = "Minimum Safety Threshold (mg/dL)";

/* Threshold Setting */
"The default threshold in Trio depends on your current minimum BG target, as follows:\n\nIf your minimum BG target = 90 mg/dl -> threshold = 65 mg/dl,\n\nif minimum BG target = 100 mg/dl -> threshold = 70 mg/dl,\n\nminimum BG target = 110 mg/dl -> threshold = 75 mg/dl,\n\nand if minimum BG target = 130 mg/dl -> threshold = 85 mg/dl.\n\nThis setting allows you to change the default to a higher threshold for looping with dynISF. Valid values are 65 mg/dl<= Threshold Setting <= 120 mg/dl." = "The default threshold in Trio depends on your current minimum BG target, as follows:\n\nIf your minimum BG target = 90 mg/dl -> threshold = 65 mg/dl,\n\nif minimum BG target = 100 mg/dl -> threshold = 70 mg/dl,\n\nminimum BG target = 110 mg/dl -> threshold = 75 mg/dl,\n\nand if minimum BG target = 130 mg/dl -> threshold = 85 mg/dl.\n\nThis setting allows you to change the default to a higher threshold for looping with dynISF. Valid values are 65 mg/dl<= Threshold Setting <= 120 mg/dl.";
/* Minimum Safety Threshold */
"All insulin will be suspended if your glucose is predicted to drop below the safety threshold.\n\nMust be set between 60-120 mg/dL.\nTo convert from mmol/L, multiply by 18.\n\nNote: Basal may be resumed if there's negative IOB and glucose is rising faster than predicted." = "All insulin will be suspended if your glucose is predicted to drop below the safety threshold.\n\nMust be set between 60-120 mg/dL.\nTo convert from mmol/L, multiply by 18.\n\nNote: Basal may be resumed if there's negative IOB and glucose is rising faster than predicted.";

/* Headline "Weighted Average of TDD. Weight of past 24 hours:" */
"Weighted Average of TDD. Weight of past 24 hours:" = "Weighted Average of TDD. Weight of past 24 hours:";
Expand Down
Loading

0 comments on commit 0ac6bd8

Please sign in to comment.