Skip to content

Commit

Permalink
update OG/OGUI code to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Allène committed Jun 29, 2024
1 parent 1ba06ef commit 0b2bbcd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
1 change: 0 additions & 1 deletion xdrip.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@
47DB06E32A7137B000267BE3 /* LibreLinkUpFollowManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47DB06E22A7137B000267BE3 /* LibreLinkUpFollowManager.swift */; };
47DB06E72A715EC500267BE3 /* ConstantsLibreLinkUp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47DB06E62A715EC500267BE3 /* ConstantsLibreLinkUp.swift */; };
47DB06E92A715FD900267BE3 /* LibreLinkUpModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47DB06E82A715FD900267BE3 /* LibreLinkUpModels.swift */; };
47DE41AA2B860DF00041DA19 /* WatchConnectivity.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 47DE41A92B860DF00041DA19 /* WatchConnectivity.framework */; };
47DE41AD2B863D370041DA19 /* WatchState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47DE41AC2B863D370041DA19 /* WatchState.swift */; };
47DE41AE2B863D370041DA19 /* WatchState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47DE41AC2B863D370041DA19 /* WatchState.swift */; };
47DE41AF2B864EE50041DA19 /* xDrip Watch App.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 47A6ABDF2B790CC60047A4BA /* xDrip Watch App.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
Expand Down
29 changes: 16 additions & 13 deletions xdrip/Managers/OpenGlückManager/OpenGlückManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import OG
import os

public class OpenGlückManager: NSObject, OpenGlückSyncClientDelegate {
public class OpenGlückManager: NSObject, OpenGluckSyncClientDelegate {
// MARK: - public properties

// MARK: - private properties
Expand All @@ -23,8 +23,8 @@ public class OpenGlückManager: NSObject, OpenGlückSyncClientDelegate {
private var openGlückInitialized = false

/// reference to the OpenGlück client, should be used only if we're sure OpenGlück is supported on the device
private var openGlückClient: OpenGlückClient?
private var openGlückSyncClient: OpenGlückSyncClient?
private var openGlückClient: OpenGluckClient?
private var openGlückSyncClient: OpenGluckSyncClient?

/// dismisses low notifications 30m after low record
private let dismissLowAfter: TimeInterval = 30 * 60 // 30m
Expand Down Expand Up @@ -65,15 +65,18 @@ public class OpenGlückManager: NSObject, OpenGlückSyncClientDelegate {
openGlückSyncClient = nil
guard UserDefaults.standard.openGlückEnabled, let openGlückHostname = UserDefaults.standard.openGlückHostname, let openGlückToken = UserDefaults.standard.openGlückToken else { return false }

openGlückClient = OpenGlückClient(hostname: openGlückHostname, token: openGlückToken, target: "xdripswift")
openGlückSyncClient = OpenGlückSyncClient()
openGlückSyncClient!.delegate = self
openGlückClient = OpenGluckClient(hostname: openGlückHostname, token: openGlückToken, target: "xdripswift")
Task {
let openGlückSyncClient = OpenGluckSyncClient()
await openGlückSyncClient.setDelegate(self)
self.openGlückSyncClient = openGlückSyncClient
}

// all checks ok , return true
return true
}

public func getClient() -> OpenGlückClient? {
public func getClient() -> OpenGluckClient? {
openGlückClient
}

Expand Down Expand Up @@ -124,19 +127,19 @@ public class OpenGlückManager: NSObject, OpenGlückSyncClientDelegate {

// reupload at least 4 historic records + scans
let uploadHistoricAfter = (UserDefaults.standard.timeStampLatestOpenGlückBgReading ?? Date().addingTimeInterval(-86400)).addingTimeInterval(-historicScanTipoffInterval)
let glucoseRecordsToUpload: [OpenGlückGlucoseRecord] = (
let glucoseRecordsToUpload: [OpenGluckGlucoseRecord] = (
historics.map ({
OpenGlückGlucoseRecord(timestamp: $0.timeStamp, mgDl: Int(round($0.calculatedValue)), recordType: "historic")
OpenGluckGlucoseRecord(timestamp: $0.timeStamp, mgDl: Int(round($0.calculatedValue)), recordType: "historic")
}) + scans.map ({
OpenGlückGlucoseRecord(timestamp: $0.timeStamp, mgDl: Int(round($0.calculatedValue)), recordType: "scan")
OpenGluckGlucoseRecord(timestamp: $0.timeStamp, mgDl: Int(round($0.calculatedValue)), recordType: "scan")
})
).filter {
$0.timestamp >= uploadHistoricAfter
}
let modelName = "xdripswift"
let deviceId = UIDevice.current.identifierForVendor?.uuidString ?? "(unknown-ifv)"
let instantGlucoseRecords = bgReadingsToStore.map { bgReading in
OpenGlückInstantGlucoseRecord(timestamp: bgReading.timeStamp, mgDl: Int(round(bgReading.calculatedValue)), modelName: modelName, deviceId: deviceId)
OpenGluckInstantGlucoseRecord(timestamp: bgReading.timeStamp, mgDl: Int(round(bgReading.calculatedValue)), modelName: modelName, deviceId: deviceId)
}
Task {
if UserDefaults.standard.openGlückUploadEnabled {
Expand All @@ -145,7 +148,7 @@ public class OpenGlückManager: NSObject, OpenGlückSyncClientDelegate {
// and all records uploaded here also end up in the instant glucose records
do {
let timeStampLastReadingToUpload = glucoseRecordsToUpload.filter { $0.recordType == "historic" }.map { $0.timestamp }.max()!
let device = OpenGlückDevice(modelName: modelName, deviceId: deviceId)
let device = OpenGluckDevice(modelName: modelName, deviceId: deviceId)
_ = try await openGlückClient.upload(currentCgmProperties: CgmCurrentDeviceProperties(hasRealTime: true, realTimeInterval: 60), device: device, glucoseRecords: glucoseRecordsToUpload)
await MainActor.run {
let currentLatest = UserDefaults.standard.timeStampLatestOpenGlückBgReading
Expand Down Expand Up @@ -173,7 +176,7 @@ public class OpenGlückManager: NSObject, OpenGlückSyncClientDelegate {
}
}

public func getClient() -> OpenGlückClient {
public func getClient() -> OpenGluckClient {
return openGlückClient!
}

Expand Down

0 comments on commit 0b2bbcd

Please sign in to comment.