@@ -21,7 +21,9 @@ final class WatchContext: RawRepresentable {
2121 var displayGlucoseUnit : HKUnit ?
2222
2323 var glucose : HKQuantity ?
24- var glucoseTrendRawValue : Int ?
24+ var glucoseCondition : GlucoseCondition ?
25+ var glucoseTrend : GlucoseTrend ?
26+ var glucoseTrendRate : HKQuantity ?
2527 var glucoseDate : Date ?
2628 var glucoseIsDisplayOnly : Bool ?
2729 var glucoseWasUserEntered : Bool ?
@@ -68,7 +70,15 @@ final class WatchContext: RawRepresentable {
6870 glucose = HKQuantity ( unit: unit, doubleValue: glucoseValue)
6971 }
7072
71- glucoseTrendRawValue = rawValue [ " gt " ] as? Int
73+ if let rawGlucoseCondition = rawValue [ " gc " ] as? GlucoseCondition . RawValue {
74+ glucoseCondition = GlucoseCondition ( rawValue: rawGlucoseCondition)
75+ }
76+ if let rawGlucoseTrend = rawValue [ " gt " ] as? GlucoseTrend . RawValue {
77+ glucoseTrend = GlucoseTrend ( rawValue: rawGlucoseTrend)
78+ }
79+ if let glucoseTrendRateUnitString = rawValue [ " gtru " ] as? String , let glucoseTrendRateValue = rawValue [ " gtrv " ] as? Double {
80+ glucoseTrendRate = HKQuantity ( unit: HKUnit ( from: glucoseTrendRateUnitString) , doubleValue: glucoseTrendRateValue)
81+ }
7282 glucoseDate = rawValue [ " gd " ] as? Date
7383 glucoseIsDisplayOnly = rawValue [ " gdo " ] as? Bool
7484 glucoseWasUserEntered = rawValue [ " gue " ] as? Bool
@@ -114,7 +124,13 @@ final class WatchContext: RawRepresentable {
114124 raw [ " gu " ] = displayGlucoseUnit? . unitString
115125 raw [ " gv " ] = glucose? . doubleValue ( for: unit)
116126
117- raw [ " gt " ] = glucoseTrendRawValue
127+ raw [ " gc " ] = glucoseCondition? . rawValue
128+ raw [ " gt " ] = glucoseTrend? . rawValue
129+ if let glucoseTrendRate = glucoseTrendRate {
130+ let unitPerMinute = unit. unitDivided ( by: . minute( ) )
131+ raw [ " gtru " ] = unitPerMinute. unitString
132+ raw [ " gtrv " ] = glucoseTrendRate. doubleValue ( for: unitPerMinute)
133+ }
118134 raw [ " gd " ] = glucoseDate
119135 raw [ " gdo " ] = glucoseIsDisplayOnly
120136 raw [ " gue " ] = glucoseWasUserEntered
@@ -149,7 +165,9 @@ extension WatchContext {
149165 if let quantity = glucose, let date = glucoseDate, let syncIdentifier = glucoseSyncIdentifier {
150166 return NewGlucoseSample ( date: date,
151167 quantity: quantity,
152- trend: glucoseTrendRawValue. flatMap { GlucoseTrend ( rawValue: $0) } ,
168+ condition: glucoseCondition,
169+ trend: glucoseTrend,
170+ trendRate: glucoseTrendRate,
153171 isDisplayOnly: glucoseIsDisplayOnly ?? false ,
154172 wasUserEntered: glucoseWasUserEntered ?? false ,
155173 syncIdentifier: syncIdentifier, syncVersion: 0 )
0 commit comments