Skip to content
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

Fix SAGE uploads in NS for Libre Transmitter #112

Merged
merged 1 commit into from
Apr 15, 2024
Merged
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
18 changes: 14 additions & 4 deletions FreeAPS/Sources/APS/CGM/PluginSource.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Combine
import Foundation
import LibreTransmitter
import LoopKit
import LoopKitUI

Expand Down Expand Up @@ -148,8 +149,17 @@ extension PluginSource: CGMManagerDelegate {
switch readingResult {
case let .newData(values):

var sensorActivatedAt: Date?
var sensorTransmitterID: String?
/// specific for Libre transmitter and send SAGE
if let cgmTransmitterManager = cgmManager as? LibreTransmitterManagerV3 {
sensorActivatedAt = cgmTransmitterManager.sensorInfoObservable.activatedAt
sensorTransmitterID = cgmTransmitterManager.sensorInfoObservable.sensorSerial
}

let bloodGlucose = values.compactMap { newGlucoseSample -> BloodGlucose? in
let quantity = newGlucoseSample.quantity

let value = Int(quantity.doubleValue(for: .milligramsPerDeciliter))
return BloodGlucose(
_id: UUID().uuidString,
Expand All @@ -161,10 +171,10 @@ extension PluginSource: CGMManagerDelegate {
filtered: nil,
noise: nil,
glucose: value,
type: "sgv"
// activationDate: activationDate,
// sessionStartDate: sessionStartDate
// transmitterID: self.transmitterID
type: "sgv",
activationDate: sensorActivatedAt,
sessionStartDate: sensorActivatedAt,
transmitterID: sensorTransmitterID
)
}
promise?(.success(bloodGlucose))
Expand Down