diff --git a/FreeAPS/Sources/Modules/Bolus/View/BolusRootView.swift b/FreeAPS/Sources/Modules/Bolus/View/BolusRootView.swift index 51817c5db..91d579fff 100644 --- a/FreeAPS/Sources/Modules/Bolus/View/BolusRootView.swift +++ b/FreeAPS/Sources/Modules/Bolus/View/BolusRootView.swift @@ -148,8 +148,8 @@ extension Bolus { } HStack { Text("ISF").foregroundColor(.secondary) - let isf = state.isf - Text(isf.formatted()) + let isf = state.units == .mmolL ? state.target.asMmolL : state.isf + Text(isf.formatted(.number.grouping(.never).rounded().precision(.fractionLength(fractionDigits)))) Text(state.units.rawValue + NSLocalizedString("/U", comment: "/Insulin unit")) .foregroundColor(.secondary) } diff --git a/FreeAPS/Sources/Services/WatchManager/WatchManager.swift b/FreeAPS/Sources/Services/WatchManager/WatchManager.swift index f28c44f4c..d0e64011d 100644 --- a/FreeAPS/Sources/Services/WatchManager/WatchManager.swift +++ b/FreeAPS/Sources/Services/WatchManager/WatchManager.swift @@ -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 @@ -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 as NSNumber : isfValue as NSNumber + ) + } + private var glucoseFormatter: NumberFormatter { let formatter = NumberFormatter() formatter.numberStyle = .decimal diff --git a/FreeAPSWatch WatchKit Extension/DataFlow.swift b/FreeAPSWatch WatchKit Extension/DataFlow.swift index 4037bf41c..8ef299a99 100644 --- a/FreeAPSWatch WatchKit Extension/DataFlow.swift +++ b/FreeAPSWatch WatchKit Extension/DataFlow.swift @@ -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? } diff --git a/FreeAPSWatch WatchKit Extension/Views/MainView.swift b/FreeAPSWatch WatchKit Extension/Views/MainView.swift index ab2268523..2609ed0b6 100644 --- a/FreeAPSWatch WatchKit Extension/Views/MainView.swift +++ b/FreeAPSWatch WatchKit Extension/Views/MainView.swift @@ -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) diff --git a/FreeAPSWatch WatchKit Extension/WatchStateModel.swift b/FreeAPSWatch WatchKit Extension/WatchStateModel.swift index 0994564a8..2107e3cc3 100644 --- a/FreeAPSWatch WatchKit Extension/WatchStateModel.swift +++ b/FreeAPSWatch WatchKit Extension/WatchStateModel.swift @@ -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() @@ -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 } }