Forráskód Böngészése

Merge pull request #292 from loopandlearn/glucose

Allow bg entries as glucose
Marion Barker 2 éve
szülő
commit
cbe8bfb716
1 módosított fájl, 4 hozzáadás és 1 törlés
  1. 4 1
      LoopFollow/Extensions/ShareClientExtension.swift

+ 4 - 1
LoopFollow/Extensions/ShareClientExtension.swift

@@ -17,6 +17,7 @@ public struct ShareGlucoseData: Decodable {
     enum CodingKeys: String, CodingKey {
         case sgv  // Sensor Blood Glucose
         case mbg  // Manual Blood Glucose
+        case glucose  // Other type of entry
         case date
         case direction
     }
@@ -29,8 +30,10 @@ public struct ShareGlucoseData: Decodable {
             sgv = Int(glucoseValue.rounded())
         } else if let mbgValue = try? container.decode(Double.self, forKey: .mbg) {
             sgv = Int(mbgValue.rounded())
+        } else if let mbgValue = try? container.decode(Double.self, forKey: .glucose) {
+            sgv = Int(mbgValue.rounded())
         } else {
-            throw DecodingError.dataCorruptedError(forKey: .sgv, in: container, debugDescription: "Expected to decode Double for sgv or mbg.")
+            throw DecodingError.dataCorruptedError(forKey: .sgv, in: container, debugDescription: "Expected to decode Double for sgv, mbg or glucose.")
         }
     
         // Decode the date and optional direction