Просмотр исходного кода

Stop simulator fetch when scenario isn't active

Warmup / calibration / expired / sensorFailed: real CGMs deliver no fresh readings. Match that so existing readings age out, stalenessState fires, and the highlight's imageName surfaces.
trioneer недель назад: 2
Родитель
Сommit
1b6a75e414
1 измененных файлов с 25 добавлено и 0 удалено
  1. 25 0
      Trio/Sources/APS/CGM/GlucoseSimulatorSource.swift

+ 25 - 0
Trio/Sources/APS/CGM/GlucoseSimulatorSource.swift

@@ -99,6 +99,14 @@ final class GlucoseSimulatorSource: GlucoseSource {
         guard canGenerateNewValues else {
         guard canGenerateNewValues else {
             return Just([]).eraseToAnyPublisher()
             return Just([]).eraseToAnyPublisher()
         }
         }
+        // Match real CGM behavior: scenarios where a physical sensor wouldn't
+        // be delivering readings (warmup, calibration, expired, failed) also
+        // stop the simulator from emitting fresh values. Existing readings
+        // then age out of the 12 min freshness window, the bobble flips to
+        // its compact symbol view, and the highlight's imageName surfaces.
+        guard simulatedScenario.deliversFreshGlucose else {
+            return Just([]).eraseToAnyPublisher()
+        }
 
 
         let glucoses = generator.getBloodGlucoses(
         let glucoses = generator.getBloodGlucoses(
             startDate: lastFetchDate,
             startDate: lastFetchDate,
@@ -237,6 +245,23 @@ enum SimulatedSensorScenario: String, CaseIterable, Identifiable {
         }
         }
     }
     }
 
 
+    /// Whether a real CGM would still be delivering fresh glucose readings
+    /// while in this state. Drives the simulator's `fetch()` gate so non-
+    /// active scenarios stop emitting and the home view sees stale data
+    /// the same way it would from a real sensor.
+    var deliversFreshGlucose: Bool {
+        switch self {
+        case .runningNormally,
+             .expiringSoon:
+            return true
+        case .warmup,
+             .calibrationRequired,
+             .expired,
+             .sensorFailed:
+            return false
+        }
+    }
+
     /// Short blurb shown under the picker so dev users know what each
     /// Short blurb shown under the picker so dev users know what each
     /// scenario renders on the home screen.
     /// scenario renders on the home screen.
     var devNotes: String {
     var devNotes: String {