Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions LoopFollow/Controllers/Nightscout/DeviceStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extension MainViewController {

Observable.shared.previousAlertLastLoopTime.value = Observable.shared.alertLastLoopTime.value

if let lastPumpRecord = lastDeviceStatus?["pump"] as! [String: AnyObject]? {
if let lastPumpRecord = lastDeviceStatus?["pump"] as? [String: AnyObject] {
if let bolusIncrement = lastPumpRecord["bolusIncrement"] as? Double, bolusIncrement > 0 {
Storage.shared.bolusIncrement.value = HKQuantity(unit: .internationalUnit(), doubleValue: bolusIncrement)
Storage.shared.bolusIncrementDetected.value = true
Expand Down Expand Up @@ -174,7 +174,7 @@ extension MainViewController {
}

// Loop - handle new data
if let lastLoopRecord = lastDeviceStatus?["loop"] as! [String: AnyObject]? {
if let lastLoopRecord = lastDeviceStatus?["loop"] as? [String: AnyObject] {
// Some pumps report no `pump.clock`; without it alertLastLoopTime stays 0
// and the forecast anchors to epoch 0. Fall back to the loop cycle timestamp.
if (lastDeviceStatus?["pump"] as? [String: AnyObject])?["clock"] == nil,
Expand Down Expand Up @@ -215,7 +215,7 @@ extension MainViewController {
}

// OpenAPS - handle new data
if let lastLoopRecord = lastDeviceStatus?["openaps"] as! [String: AnyObject]? {
if let lastLoopRecord = lastDeviceStatus?["openaps"] as? [String: AnyObject] {
DeviceStatusOpenAPS(formatter: formatter, lastDeviceStatus: lastDeviceStatus, lastLoopRecord: lastLoopRecord)
}

Expand Down
7 changes: 1 addition & 6 deletions LoopFollow/Controllers/Nightscout/Treatments/Bolus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ extension MainViewController {
var lastFoundIndex = 0

for currentEntry in entries.reversed() {
var bolusDate: String
if currentEntry["timestamp"] != nil {
bolusDate = currentEntry["timestamp"] as! String
} else if currentEntry["created_at"] != nil {
bolusDate = currentEntry["created_at"] as! String
} else {
guard let bolusDate = currentEntry["timestamp"] as? String ?? currentEntry["created_at"] as? String else {
continue
}

Expand Down
7 changes: 1 addition & 6 deletions LoopFollow/Controllers/Nightscout/Treatments/Carbs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ extension MainViewController {
var lastFoundSmb = 0

for currentEntry in entries.reversed() {
var carbDate: String
if currentEntry["timestamp"] != nil {
carbDate = currentEntry["timestamp"] as! String
} else if currentEntry["created_at"] != nil {
carbDate = currentEntry["created_at"] as! String
} else {
guard let carbDate = currentEntry["timestamp"] as? String ?? currentEntry["created_at"] as? String else {
continue
}

Expand Down
7 changes: 1 addition & 6 deletions LoopFollow/Controllers/Nightscout/Treatments/Notes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ extension MainViewController {
for currentEntry in entries.reversed() {
guard let currentEntry = currentEntry as? [String: AnyObject] else { continue }

var date: String
if currentEntry["timestamp"] != nil {
date = currentEntry["timestamp"] as! String
} else if currentEntry["created_at"] != nil {
date = currentEntry["created_at"] as! String
} else {
guard let date = currentEntry["timestamp"] as? String ?? currentEntry["created_at"] as? String else {
continue
}

Expand Down
7 changes: 1 addition & 6 deletions LoopFollow/Controllers/Nightscout/Treatments/SMB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ extension MainViewController {
var lastFoundIndex = 0

for currentEntry in entries.reversed() {
var bolusDate: String
if currentEntry["timestamp"] != nil {
bolusDate = currentEntry["timestamp"] as! String
} else if currentEntry["created_at"] != nil {
bolusDate = currentEntry["created_at"] as! String
} else {
guard let bolusDate = currentEntry["timestamp"] as? String ?? currentEntry["created_at"] as? String else {
continue
}

Expand Down
21 changes: 3 additions & 18 deletions LoopFollow/Stats/StatsDataFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,7 @@ class StatsDataFetcher {
var lastFoundIndex = 0

for currentEntry in bolusEntries.reversed() {
var bolusDate: String
if currentEntry["timestamp"] != nil {
bolusDate = currentEntry["timestamp"] as! String
} else if currentEntry["created_at"] != nil {
bolusDate = currentEntry["created_at"] as! String
} else {
guard let bolusDate = currentEntry["timestamp"] as? String ?? currentEntry["created_at"] as? String else {
continue
}

Expand Down Expand Up @@ -250,12 +245,7 @@ class StatsDataFetcher {
var lastFoundIndex = 0

for currentEntry in smbEntries.reversed() {
var bolusDate: String
if currentEntry["timestamp"] != nil {
bolusDate = currentEntry["timestamp"] as! String
} else if currentEntry["created_at"] != nil {
bolusDate = currentEntry["created_at"] as! String
} else {
guard let bolusDate = currentEntry["timestamp"] as? String ?? currentEntry["created_at"] as? String else {
continue
}

Expand Down Expand Up @@ -296,12 +286,7 @@ class StatsDataFetcher {
var lastFoundBolus = 0

for currentEntry in carbEntries.reversed() {
var carbDate: String
if currentEntry["timestamp"] != nil {
carbDate = currentEntry["timestamp"] as! String
} else if currentEntry["created_at"] != nil {
carbDate = currentEntry["created_at"] as! String
} else {
guard let carbDate = currentEntry["timestamp"] as? String ?? currentEntry["created_at"] as? String else {
continue
}

Expand Down
Loading