Skip to content

Commit

Permalink
Merge pull request #259 from loopandlearn/guard-eventType
Browse files Browse the repository at this point in the history
Fix: Prevent crash by handling missing eventType in updateTreatments
  • Loading branch information
marionbarker authored Mar 4, 2024
2 parents 5e3a016 + e892fc1 commit 2fb9f3c
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions LoopFollow/Controllers/Nightscout/Treatments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,42 +50,39 @@ extension MainViewController {
var pumpSiteChange: [cageData] = []
var cgmSensorStart: [sageData] = []

for i in 0..<entries.count {
let entry = entries[i] as [String : AnyObject]?
switch entry?["eventType"] as! String {
for entry in entries {
guard let eventType = entry["eventType"] as? String else {
continue
}

switch eventType {
case "Temp Basal":
tempBasal.append(entry!)
case "Correction Bolus":
bolus.append(entry!)
case "Bolus":
bolus.append(entry!)
case "SMB":
bolus.append(entry!)
tempBasal.append(entry)
case "Correction Bolus", "Bolus", "SMB":
bolus.append(entry)
case "Meal Bolus":
carbs.append(entry!)
bolus.append(entry!)
carbs.append(entry)
bolus.append(entry)
case "Carb Correction":
carbs.append(entry!)
case "Temporary Override":
temporaryOverride.append(entry!)
case "Temporary Target":
temporaryOverride.append(entry!)
carbs.append(entry)
case "Temporary Override", "Temporary Target":
temporaryOverride.append(entry)
case "Note":
note.append(entry!)
note.append(entry)
print("Note: \(String(describing: entry))")
case "BG Check":
bgCheck.append(entry!)
bgCheck.append(entry)
case "Suspend Pump":
suspendPump.append(entry!)
suspendPump.append(entry)
case "Resume Pump":
resumePump.append(entry!)
resumePump.append(entry)
case "Pump Site Change", "Site Change":
if let createdAt = entry?["created_at"] as? String {
if let createdAt = entry["created_at"] as? String {
let newEntry = cageData(created_at: createdAt)
pumpSiteChange.append(newEntry)
}
case "Sensor Start":
if let createdAt = entry?["created_at"] as? String {
if let createdAt = entry["created_at"] as? String {
let newEntry = sageData(created_at: createdAt)
cgmSensorStart.append(newEntry)
}
Expand All @@ -97,7 +94,7 @@ extension MainViewController {
if tempBasal.count > 0 {
processNSBasals(entries: tempBasal)
} else {
if basalData.count < 0 {
if basalData.count > 0 {
clearOldTempBasal()
}
}
Expand Down

0 comments on commit 2fb9f3c

Please sign in to comment.