Skip to content

Commit cd82e70

Browse files
authored
Merge branch 'nightscout:dev' into dev
2 parents 9b308e7 + 0e6aa5b commit cd82e70

21 files changed

Lines changed: 273 additions & 90 deletions

Config.xcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
APP_DISPLAY_NAME = Trio
22
APP_VERSION = 0.5.0
3-
APP_DEV_VERSION = 0.5.0.3
3+
APP_DEV_VERSION = 0.5.0.9
44
APP_BUILD_NUMBER = 1
55
COPYRIGHT_NOTICE =
66
DEVELOPER_TEAM = ##TEAM_ID##

Trio.xcodeproj/project.pbxproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@
247247
3B997DCB2DC00849006B6BB2 /* JSONImporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B997DCA2DC00849006B6BB2 /* JSONImporter.swift */; };
248248
3B997DCF2DC00A3A006B6BB2 /* JSONImporterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B997DCE2DC00A3A006B6BB2 /* JSONImporterTests.swift */; };
249249
3B997DD32DC02AEF006B6BB2 /* glucose.json in Resources */ = {isa = PBXBuildFile; fileRef = 3B997DD12DC02AEF006B6BB2 /* glucose.json */; };
250+
3BA8D1B32DDB87150006191F /* DecimalExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BA8D1B22DDB870F0006191F /* DecimalExtensions.swift */; };
250251
3BAD36B22D7CDC1A00CC298D /* MainLoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BAD36B12D7CDC1400CC298D /* MainLoadingView.swift */; };
251252
3BAD36CC2D7D420E00CC298D /* CoreDataInitializationCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BAD36CB2D7D420500CC298D /* CoreDataInitializationCoordinator.swift */; };
252253
3BCA5F7C2DC7B16400A7EAC7 /* pumphistory-with-external.json in Resources */ = {isa = PBXBuildFile; fileRef = 3BCA5F7B2DC7B15400A7EAC7 /* pumphistory-with-external.json */; };
@@ -1056,6 +1057,7 @@
10561057
3B997DCA2DC00849006B6BB2 /* JSONImporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONImporter.swift; sourceTree = "<group>"; };
10571058
3B997DCE2DC00A3A006B6BB2 /* JSONImporterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONImporterTests.swift; sourceTree = "<group>"; };
10581059
3B997DD12DC02AEF006B6BB2 /* glucose.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = glucose.json; sourceTree = "<group>"; };
1060+
3BA8D1B22DDB870F0006191F /* DecimalExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecimalExtensions.swift; sourceTree = "<group>"; };
10591061
3BAD36B12D7CDC1400CC298D /* MainLoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainLoadingView.swift; sourceTree = "<group>"; };
10601062
3BAD36CB2D7D420500CC298D /* CoreDataInitializationCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataInitializationCoordinator.swift; sourceTree = "<group>"; };
10611063
3BCA5F7B2DC7B15400A7EAC7 /* pumphistory-with-external.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "pumphistory-with-external.json"; sourceTree = "<group>"; };
@@ -2442,13 +2444,14 @@
24422444
38A504F625DDA0E200C5B9E8 /* Extensions */ = {
24432445
isa = PBXGroup;
24442446
children = (
2447+
CE2FAD39297D93F0001A872C /* BloodGlucoseExtensions.swift */,
2448+
3BA8D1B22DDB870F0006191F /* DecimalExtensions.swift */,
24452449
DDB37CC62D05127500D99BF4 /* FontExtensions.swift */,
2446-
38A5049125DD9C4000C5B9E8 /* UserDefaultsExtensions.swift */,
2447-
38BF021625E7CBBC00579895 /* PumpManagerExtensions.swift */,
24482450
CEB434E628B9053300B70274 /* LoopUIColorPalette+Default.swift */,
24492451
CE48C86328CA69D5007C0598 /* OmniBLEPumpManagerExtensions.swift */,
24502452
CE48C86528CA6B48007C0598 /* OmniPodManagerExtensions.swift */,
2451-
CE2FAD39297D93F0001A872C /* BloodGlucoseExtensions.swift */,
2453+
38BF021625E7CBBC00579895 /* PumpManagerExtensions.swift */,
2454+
38A5049125DD9C4000C5B9E8 /* UserDefaultsExtensions.swift */,
24522455
);
24532456
path = Extensions;
24542457
sourceTree = "<group>";
@@ -4535,6 +4538,7 @@
45354538
DDD163122C4C689900CD525A /* AdjustmentsStateModel.swift in Sources */,
45364539
BD47FDD72D8B64D20043966B /* CarbRatioStepView.swift in Sources */,
45374540
3B2F77862D7E52ED005ED9FA /* TDD.swift in Sources */,
4541+
3BA8D1B32DDB87150006191F /* DecimalExtensions.swift in Sources */,
45384542
DD3F1F892D9E078D00DCE7B3 /* TherapySettingEditorView.swift in Sources */,
45394543
DD1745132C54169400211FAC /* DevicesView.swift in Sources */,
45404544
7F7B756BE8543965D9FDF1A2 /* DataTableDataFlow.swift in Sources */,

Trio/Sources/APS/APSManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ extension BaseAPSManager: PumpManagerStatusObserver {
12701270
guard self.privateContext.hasChanges else { return }
12711271
try self.privateContext.save()
12721272
} catch {
1273-
print("Failed to fetch or save battery: \(error.localizedDescription)")
1273+
debug(.apsManager, "Failed to fetch or save battery: \(error)")
12741274
}
12751275
}
12761276
// TODO: - remove this after ensuring that NS still gets the same infos from Core Data

Trio/Sources/APS/DeviceDataManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ final class BaseDeviceDataManager: DeviceDataManager, Injectable {
176176
try self.privateContext.save()
177177

178178
} catch {
179-
print("Failed to delete OpenAPS_Battery entries: \(error.localizedDescription)")
179+
debug(.deviceManager, "Failed to delete OpenAPS_Battery entries: \(error)")
180180
}
181181
}
182182
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
3+
extension Decimal {
4+
func clamp(to pickerSetting: PickerSetting) -> Decimal {
5+
max(min(self, pickerSetting.max), pickerSetting.min)
6+
}
7+
}

Trio/Sources/APS/FetchGlucoseManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ protocol FetchGlucoseManager: SourceInfoProvider {
1111
func updateGlucoseSource(cgmGlucoseSourceType: CGMType, cgmGlucosePluginId: String, newManager: CGMManagerUI?)
1212
func deleteGlucoseSource() async
1313
func removeCalibrations()
14-
var glucoseSource: GlucoseSource! { get }
14+
var glucoseSource: GlucoseSource? { get }
1515
var cgmManager: CGMManagerUI? { get }
1616
var cgmGlucoseSourceType: CGMType { get set }
1717
var cgmGlucosePluginId: String { get }
@@ -113,7 +113,7 @@ final class BaseFetchGlucoseManager: FetchGlucoseManager, Injectable {
113113
timer.resume()
114114
}
115115

116-
var glucoseSource: GlucoseSource!
116+
var glucoseSource: GlucoseSource?
117117

118118
func removeCalibrations() {
119119
calibrationService.removeAllCalibrations()
@@ -286,7 +286,7 @@ final class BaseFetchGlucoseManager: FetchGlucoseManager, Injectable {
286286
}
287287

288288
func sourceInfo() -> [String: Any]? {
289-
glucoseSource.sourceInfo()
289+
glucoseSource?.sourceInfo()
290290
}
291291

292292
private func overcalibrate(entries: [BloodGlucose]) -> [BloodGlucose] {

Trio/Sources/APS/OpenAPS/Script.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct Script {
1010
do {
1111
body = try String(contentsOf: url)
1212
} catch {
13-
print("Error loading script: \(error.localizedDescription)")
13+
debug(.openAPS, "Error loading script: \(error)")
1414
body = "Error loading script"
1515
}
1616
} else {

Trio/Sources/APS/Storage/CarbsStorage.swift

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ final class BaseCarbsStorage: CarbsStorage, Injectable {
2727

2828
private let updateSubject = PassthroughSubject<Void, Never>()
2929

30+
private let settingsProvider = PickerSettingsProvider.shared
31+
3032
var updatePublisher: AnyPublisher<Void, Never> {
3133
updateSubject.eraseToAnyPublisher()
3234
}
@@ -111,7 +113,7 @@ final class BaseCarbsStorage: CarbsStorage, Injectable {
111113

112114
- Returns: The computed duration in hours.
113115
*/
114-
private func calculateComputedDuration(fpus: Decimal, timeCap: Int) -> Int {
116+
private func calculateComputedDuration(fpus: Decimal, timeCap: Decimal) -> Decimal {
115117
switch fpus {
116118
case ..<2:
117119
return 3
@@ -145,22 +147,25 @@ final class BaseCarbsStorage: CarbsStorage, Injectable {
145147
createdAt: Date,
146148
actualDate: Date?
147149
) -> ([CarbsEntry], Decimal) {
148-
let interval = settings.settings.minuteInterval
149-
let timeCap = settings.settings.timeCap
150-
let adjustment = settings.settings.individualAdjustmentFactor
151-
let delay = settings.settings.delay
150+
let trioSettings = settings.settings
151+
let providerSettings = settingsProvider.settings
152+
153+
let interval = trioSettings.minuteInterval.clamp(to: providerSettings.minuteInterval)
154+
let timeCap = trioSettings.timeCap.clamp(to: providerSettings.timeCap)
155+
let adjustment = trioSettings.individualAdjustmentFactor.clamp(to: providerSettings.individualAdjustmentFactor)
156+
let delay = trioSettings.delay.clamp(to: providerSettings.delay)
152157

153158
let kcal = protein * 4 + fat * 9
154159
let carbEquivalents = (kcal / 10) * adjustment
155160
let fpus = carbEquivalents / 10
156161
var computedDuration = calculateComputedDuration(fpus: fpus, timeCap: timeCap)
157162

158-
var carbEquivalentSize: Decimal = carbEquivalents / Decimal(computedDuration)
159-
carbEquivalentSize /= Decimal(60 / interval)
163+
var carbEquivalentSize: Decimal = carbEquivalents / computedDuration
164+
carbEquivalentSize /= Decimal(60) / interval
160165

161166
if carbEquivalentSize < 1.0 {
162167
carbEquivalentSize = 1.0
163-
computedDuration = Int(carbEquivalents / carbEquivalentSize)
168+
computedDuration = min(carbEquivalents / carbEquivalentSize, timeCap)
164169
}
165170

166171
let roundedEquivalent: Double = round(Double(carbEquivalentSize * 10)) / 10
@@ -172,9 +177,12 @@ final class BaseCarbsStorage: CarbsStorage, Injectable {
172177
var futureCarbArray = [CarbsEntry]()
173178
var firstIndex = true
174179

180+
// convert Decimal minutes to TimeInterval in seconds
181+
let delayTimeInterval = TimeInterval(delay * 60)
182+
let intervalTimeInterval = TimeInterval(interval * 60)
175183
while carbEquivalents > 0, numberOfEquivalents > 0 {
176-
useDate = firstIndex ? useDate.addingTimeInterval(delay.minutes.timeInterval) : useDate
177-
.addingTimeInterval(interval.minutes.timeInterval)
184+
useDate = firstIndex ? useDate.addingTimeInterval(delayTimeInterval) : useDate
185+
.addingTimeInterval(intervalTimeInterval)
178186
firstIndex = false
179187

180188
let eachCarbEntry = CarbsEntry(

Trio/Sources/APS/Storage/GlucoseStorage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ final class BaseGlucoseStorage: GlucoseStorage, Injectable {
287287
let results = try self.context.fetch(fr)
288288
date = results.first?.date
289289
} catch let error as NSError {
290-
print("Fetch error: \(DebuggingIdentifiers.failed) \(error.localizedDescription), \(error.userInfo)")
290+
debug(.storage, "Fetch error: \(DebuggingIdentifiers.failed) \(error), \(error.userInfo)")
291291
}
292292
}
293293

Trio/Sources/Localizations/Main/Localizable.xcstrings

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34782,6 +34782,12 @@
3478234782
}
3478334783
}
3478434784
}
34785+
},
34786+
"An unknown authentication error occurred. Please try again." : {
34787+
34788+
},
34789+
"An unknown biometric authentication error occurred. Please try again." : {
34790+
3478534791
},
3478634792
"Animated Background" : {
3478734793
"extractionState" : "manual",
@@ -37823,6 +37829,27 @@
3782337829
}
3782437830
}
3782537831
}
37832+
},
37833+
"Authentication context is invalid. Please try again." : {
37834+
37835+
},
37836+
"Authentication failed. Please try again." : {
37837+
37838+
},
37839+
"Authentication requires a device passcode. Please set one in iOS Settings > Face ID & Passcode." : {
37840+
37841+
},
37842+
"Authentication UI cannot be displayed. Try restarting the app." : {
37843+
37844+
},
37845+
"Authentication was canceled by the app." : {
37846+
37847+
},
37848+
"Authentication was canceled by the system. Try again." : {
37849+
37850+
},
37851+
"Authentication was canceled by you." : {
37852+
3782637853
},
3782737854
"Authorize Trio to send notifications and use Bluetooth. You must allow both for Trio to work properly." : {
3782837855
"localizations" : {
@@ -43524,6 +43551,15 @@
4352443551
}
4352543552
}
4352643553
}
43554+
},
43555+
"Biometric accessory is missing or not connected. Please reconnect it and try again." : {
43556+
43557+
},
43558+
"Biometric authentication is locked due to multiple failed attempts. Please unlock your device using your passcode." : {
43559+
43560+
},
43561+
"Biometric authentication is not available on this device." : {
43562+
4352743563
},
4352843564
"Blood glucose (BG) readings" : {
4352943565
"extractionState" : "stale",
@@ -72213,6 +72249,7 @@
7221372249
}
7221472250
},
7221572251
"Determination Failed" : {
72252+
"extractionState" : "stale",
7221672253
"localizations" : {
7221772254
"bg" : {
7221872255
"stringUnit" : {
@@ -87922,6 +87959,9 @@
8792287959
}
8792387960
}
8792487961
}
87962+
},
87963+
"Error while processing Treatment" : {
87964+
8792587965
},
8792687966
"Error! Bolus cancellation failed with error: %@" : {
8792787967
"comment" : "Error message for canceling a bolus",
@@ -91783,6 +91823,7 @@
9178391823
}
9178491824
},
9178591825
"Failed to update COB/IOB: %@" : {
91826+
"extractionState" : "stale",
9178691827
"localizations" : {
9178791828
"bg" : {
9178891829
"stringUnit" : {
@@ -138270,6 +138311,9 @@
138270138311
}
138271138312
}
138272138313
}
138314+
},
138315+
"No biometric identities are enrolled. Please set up Face ID or Touch ID." : {
138316+
138273138317
},
138274138318
"No Bolus Data" : {
138275138319
"localizations" : {
@@ -227692,6 +227736,9 @@
227692227736
}
227693227737
}
227694227738
}
227739+
},
227740+
"You tapped the fallback option, but no fallback method is configured." : {
227741+
227695227742
},
227696227743
"You will also be guided through re-configuring your algorithm settings, respecting Trio's new guardrails." : {
227697227744
"localizations" : {

0 commit comments

Comments
 (0)