         case downDownDown   = 7
         case notComputable  = 8
         case rateOutOfRange = 9
+        
+        init?(direction: String) {
+            for trend in GlucoseTrend.allCases {
+                if direction == trend.direction {
+                    self = trend
+                    return
+                }
+            }
+            return nil
+        }
 
         public var direction: String {
             switch self {

        case sensor
    }

    public enum GlucoseTrend: Int {
        case upUpUp         = 1
        case upUp           = 2
        case up             = 3

            self.trend = GlucoseTrend(rawValue: intTrend)
        } else if let stringTrend = rawValue["trend"] as? String, let intTrend = Int(stringTrend) {
            self.trend = GlucoseTrend(rawValue: intTrend)
        } else if let directionString = rawValue["direction"] as? String {
            self.trend = GlucoseTrend(direction: directionString)
        } else {
            self.trend = nil
        }
