Skip to content

Commit 3598ea4

Browse files
committed
[LOOP-4669] Reset Loop Testing Data on Reset
1 parent 9835d66 commit 3598ea4

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

Loop/Managers/DeviceDataManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ extension DeviceDataManager {
12711271

12721272
func deleteTestingCGMData(completion: ((Error?) -> Void)? = nil) {
12731273
guard let testingCGMManager = cgmManager as? TestingCGMManager else {
1274-
assertionFailure("\(#function) should be invoked only when a testing CGM manager is in use")
1274+
completion?(nil)
12751275
return
12761276
}
12771277

Loop/Managers/LoopAppManager.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,14 @@ extension LoopAppManager: ResetLoopManagerDelegate {
620620
}
621621
}
622622

623+
func resetTestingData(completion: @escaping () -> Void) {
624+
deviceDataManager.deleteTestingCGMData { [weak deviceDataManager] _ in
625+
deviceDataManager?.deleteTestingPumpData { _ in
626+
completion()
627+
}
628+
}
629+
}
630+
623631
func presentCouldNotResetLoopAlert(error: Error) {
624632
alertManager.presentCouldNotResetLoopAlert(error: error)
625633
}

Loop/Managers/ResetLoopManager.swift

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ protocol ResetLoopManagerDelegate: AnyObject {
1212
func loopWillReset()
1313
func loopDidReset()
1414

15+
func resetTestingData(completion: @escaping () -> Void)
16+
1517
func presentConfirmationAlert(
1618
confirmAction: @escaping (_ pumpManager: PumpManager?, _ completion: @escaping () -> Void) -> Void,
1719
cancelAction: @escaping () -> Void
@@ -46,15 +48,17 @@ class ResetLoopManager {
4648
self?.resetAlertPresented = false
4749

4850
guard let pumpManager else {
49-
self?.resetLoop()
50-
completion()
51+
self?.resetLoop {
52+
completion()
53+
}
5154
return
5255
}
5356

5457
pumpManager.prepareForDeactivation() { [weak self] error in
5558
guard let error = error else {
56-
self?.resetLoop()
57-
completion()
59+
self?.resetLoop() {
60+
completion()
61+
}
5862
return
5963
}
6064

@@ -84,13 +88,15 @@ class ResetLoopManager {
8488
loopIsAlreadyReset = hasReset
8589
}
8690

87-
private func resetLoop() {
91+
private func resetLoop(completion: @escaping () -> Void) {
8892
delegate?.loopWillReset()
89-
90-
resetLoopDocuments()
91-
resetLoopUserDefaults()
92-
93-
delegate?.loopDidReset()
93+
94+
delegate?.resetTestingData { [weak self] in
95+
self?.resetLoopDocuments()
96+
self?.resetLoopUserDefaults()
97+
self?.delegate?.loopDidReset()
98+
completion()
99+
}
94100
}
95101

96102
private func resetLoopUserDefaults() {

0 commit comments

Comments
 (0)