From a731a136c07af32ec41398aaf6313da39273f583 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 20 Jun 2024 13:38:52 +0200 Subject: [PATCH] isf conversion for watch --- .../Services/WatchManager/WatchManager.swift | 15 +++++++++++++-- FreeAPSWatch WatchKit Extension/DataFlow.swift | 2 +- .../Views/MainView.swift | 2 +- .../WatchStateModel.swift | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/FreeAPS/Sources/Services/WatchManager/WatchManager.swift b/FreeAPS/Sources/Services/WatchManager/WatchManager.swift index f28c44f4c..2d0c5009f 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 : Decimal(isfValue)) as NSNumber + )! + } + private var glucoseFormatter: NumberFormatter { let formatter = NumberFormatter() formatter.numberStyle = .decimal @@ -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 } 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 } }