Skip to content

Commit

Permalink
isf conversion for watch
Browse files Browse the repository at this point in the history
  • Loading branch information
mountrcg committed Jun 20, 2024
1 parent 4e7d3df commit a731a13
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
15 changes: 13 additions & 2 deletions FreeAPS/Sources/Services/WatchManager/WatchManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ final class BaseWatchManager: NSObject, WatchManager, Injectable {
self.state.eventualBG = eBG.map { "" + $0 }
self.state.eventualBGRaw = eBG

self.state.isf = self.suggestion?.isf
let isfString = self.isfString()
self.state.isf = isfString

var overrideArray = [Override]()
let requestOverrides = Override.fetchRequest() as NSFetchRequest<Override>
Expand Down Expand Up @@ -201,6 +202,16 @@ final class BaseWatchManager: NSObject, WatchManager, Injectable {
)!
}

private func isfString() -> String? {
guard let isfValue = suggestion?.isf else {
return nil
}
let units = settingsManager.settings.units
return glucoseFormatter.string(
from: (units == .mmolL ? isfValue.asMmolL : Decimal(isfValue)) as NSNumber
)!
}

private var glucoseFormatter: NumberFormatter {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
Expand All @@ -216,7 +227,7 @@ final class BaseWatchManager: NSObject, WatchManager, Injectable {
private var eventualFormatter: NumberFormatter {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.maximumFractionDigits = 2
formatter.maximumFractionDigits = 1
return formatter
}

Expand Down
2 changes: 1 addition & 1 deletion FreeAPSWatch WatchKit Extension/DataFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct WatchState: Codable {
var displayOnWatch: AwConfig?
var displayFatAndProteinOnWatch: Bool?
var confirmBolusFaster: Bool?
var isf: Decimal?
var isf: String?
var override: String?
}

Expand Down
2 changes: 1 addition & 1 deletion FreeAPSWatch WatchKit Extension/Views/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ struct MainView: View {
}
case .isf:
Spacer()
let isf: String = state.isf != nil ? "\(state.isf ?? 0)" : "-"
let isf: String = state.isf != nil ? state.isf! : "-"
HStack {
Image(systemName: "arrow.up.arrow.down")
.renderingMode(.template)
Expand Down
4 changes: 2 additions & 2 deletions FreeAPSWatch WatchKit Extension/WatchStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class WatchStateModel: NSObject, ObservableObject {
@Published var lastUpdate: Date = .distantPast
@Published var timerDate = Date()
@Published var pendingBolus: Double?
@Published var isf: Decimal?
@Published var isf: String?
@Published var override: String?

private var lifetime = Set<AnyCancellable>()
Expand Down Expand Up @@ -176,7 +176,7 @@ class WatchStateModel: NSObject, ObservableObject {
displayOnWatch = state.displayOnWatch ?? .BGTarget
displayFatAndProteinOnWatch = state.displayFatAndProteinOnWatch ?? false
confirmBolusFaster = state.confirmBolusFaster ?? false
isf = state.isf
isf = state.isf ?? ""
override = state.override
}
}
Expand Down

0 comments on commit a731a13

Please sign in to comment.