-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Libre Conversion Notification Bug #40
Comments
Is this exclusively related to Libre CGM? |
I believe so - here |
Is this still an issue for Libre CGM? |
Like #167 the notification is published by Libre submodules "itself" and the update should be done by the module... |
I have noticed the same, but as soon as I disconnected Trio with FSL2 through bluetooth and reconnected it through LibreLink the notifications were in mmol instead of mg/dl. |
I'm receiving notifications about my blood sugar in mg/dL when I have it set to mmol/L. I even tried to turn off the notification but still get it. |
This is an issue with the Libre module and cannot be solved by the Trio team as of now. Apologies. |
Tagging @dabear, perhaps something to consider fixing in https://github.com/LoopKit/LibreTransmitter? |
LibreTransmitterManagerV3 defaults to the mgdl unit, but will change the glucose value formatter according to events received following the Loopkit DisplayGlucoseUnitObserver protocol unitDidChange method. This is how Loop does that:
Additionally, I did not find any calls to unitDidChange inside of Trio. |
Trios code:
It explicitly calls the CGMManager's settings view with displayglucose units derived from Trio's current settings. So that's why it works in the ui |
@dabear We need to ensure that all values that are propagated to Trio from LT are mg/dL and are only parsed for display.
|
Recommendation: On these two events
then retrieve the CGMManager as CGMManagerUI , GlucoseUnits from trio settings and apply
|
what's the target I should make a PR against? Trio Dev branch? diff --git a/FreeAPS/Sources/APS/FetchGlucoseManager.swift b/FreeAPS/Sources/APS/FetchGlucoseManager.swift
index 333b4ef7..7b6f44c7 100644
--- a/FreeAPS/Sources/APS/FetchGlucoseManager.swift
+++ b/FreeAPS/Sources/APS/FetchGlucoseManager.swift
@@ -1,5 +1,6 @@
import Combine
import Foundation
+import HealthKit
import LoopKit
import LoopKitUI
import SwiftDate
@@ -98,6 +99,14 @@ final class BaseFetchGlucoseManager: FetchGlucoseManager, Injectable {
settingsManager.settings.uploadGlucose = cgmM.shouldSyncToRemoteService
}
+ private func updateManagerUnits(_ manager: CGMManagerUI?) {
+ let units = settingsManager.settings.units
+ let managerName = cgmManager.map { "\(type(of: $0))" } ?? "nil"
+ let loopkitUnits: HKUnit = units == .mgdL ? .milligramsPerDeciliter : .millimolesPerLiter
+ print("manager: \(managerName) is changing units to: \(loopkitUnits.description) ")
+ manager?.unitDidChange(to: loopkitUnits)
+ }
+
func updateGlucoseSource(cgmGlucoseSourceType: CGMType, cgmGlucosePluginId: String, newManager: CGMManagerUI?) {
// if changed, remove all calibrations
if self.cgmGlucoseSourceType != cgmGlucoseSourceType || self.cgmGlucosePluginId != cgmGlucosePluginId {
@@ -120,6 +129,8 @@ final class BaseFetchGlucoseManager: FetchGlucoseManager, Injectable {
removeCalibrations()
} else if self.cgmGlucoseSourceType == .plugin, cgmManager == nil, let rawCGMManager = rawCGMManager {
cgmManager = cgmManagerFromRawValue(rawCGMManager)
+ updateManagerUnits(cgmManager)
+
} else {
saveConfigManager()
}
@@ -151,7 +162,6 @@ final class BaseFetchGlucoseManager: FetchGlucoseManager, Injectable {
else {
return nil
}
-
return Manager.init(rawState: rawState)
}
diff --git a/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorDataFlow.swift b/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorDataFlow.swift
index 1bbd54d6..0915350f 100644
--- a/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorDataFlow.swift
+++ b/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorDataFlow.swift
@@ -109,6 +109,7 @@ protocol PreferencesEditorProvider: Provider {
var preferences: Preferences { get }
func savePreferences(_ preferences: Preferences)
func migrateUnits()
+ func updateManagerUnits()
}
protocol PreferencesSettable: AnyObject {
diff --git a/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorProvider.swift b/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorProvider.swift
index 7e8c63a0..f2a2765e 100644
--- a/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorProvider.swift
+++ b/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorProvider.swift
@@ -1,8 +1,10 @@
import Foundation
+import HealthKit
extension PreferencesEditor {
final class Provider: BaseProvider, PreferencesEditorProvider {
@Injected() private var settingsManager: SettingsManager!
+ @Injected() var fetchGlucoseManager: FetchGlucoseManager!
private let processQueue = DispatchQueue(label: "PreferencesEditorProvider.processQueue")
var preferences: Preferences {
@@ -17,6 +19,15 @@ extension PreferencesEditor {
}
}
+ func updateManagerUnits() {
+ var manager = fetchGlucoseManager.cgmManager
+ let managerName = manager.map { "\(type(of: $0))" } ?? "nil"
+ let units = settingsManager.settings.units
+ let loopkitUnits: HKUnit = units == .mgdL ? .milligramsPerDeciliter : .millimolesPerLiter
+ print("manager: \(managerName) is changing units to: \(loopkitUnits.description) ")
+ manager?.unitDidChange(to: loopkitUnits)
+ }
+
func migrateUnits() {
migrateTargets()
migrateISF()
diff --git a/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift b/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift
index d28869fb..01175ffb 100644
--- a/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift
+++ b/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift
@@ -16,6 +16,7 @@ extension PreferencesEditor {
subscribeSetting(\.units, on: $unitsIndex.map { $0 == 0 ? GlucoseUnits.mgdL : .mmolL }) {
unitsIndex = $0 == .mgdL ? 0 : 1
} didSet: { [weak self] _ in
+ self?.provider.updateManagerUnits()
self?.provider.migrateUnits()
}
|
see #429 |
@dabear Indeed against Dev, and I reopened it and assigned it to you |
@dabear can you please answer this?
Will the change you have now PR'd also prompt propagation of mmol/L glucose values, or will they stay (expected behavior on my end) mg/dL? |
Shouldn't change anything. But since all cgmmanagers get this change you can even test it with dexcom G7 sensors |
Great, thanks |
Any cgmmanagers including G6.. |
Let me know if anything is needed to get that PR merged :) no hurry from my side though |
Dev branch with live activities and loop_dev_submodules
Notification shows mg/dL when mmol/L selected as glucose value.
Transmitter also shows N/A.
The text was updated successfully, but these errors were encountered: