From 26433a872e96f67986f7234c5f958c45acac9bde Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 27 Jan 2023 15:50:06 +0100 Subject: [PATCH] Tidepool: small improvements --- .../nightscout/core/profile/ProfileSealed.kt | 2 +- .../sync/tidepool/comm/TidepoolUploader.kt | 11 ++++++---- .../plugins/sync/tidepool/comm/UploadChunk.kt | 4 +++- .../sync/tidepool/elements/ProfileElement.kt | 13 ++++++------ .../messages/OpenDatasetRequestMessage.kt | 21 ++++++++----------- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/core/main/src/main/java/info/nightscout/core/profile/ProfileSealed.kt b/core/main/src/main/java/info/nightscout/core/profile/ProfileSealed.kt index 51a16b2870..e0b3dcac5d 100644 --- a/core/main/src/main/java/info/nightscout/core/profile/ProfileSealed.kt +++ b/core/main/src/main/java/info/nightscout/core/profile/ProfileSealed.kt @@ -377,7 +377,7 @@ sealed class ProfileSealed( val ret = Array(shifted.size) { ProfileValue(0, 0.0) } var elapsed = 0 for (index in shifted.indices) { - ret[index] = ProfileValue(elapsed, (shifted[index].lowTarget + shifted[index].highTarget) / 2.0) + ret[index] = ProfileValue(elapsed, Profile.toMgdl((shifted[index].lowTarget + shifted[index].highTarget) / 2.0, units)) elapsed += T.msecs(shifted[index].duration).secs().toInt() } return ret diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/comm/TidepoolUploader.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/comm/TidepoolUploader.kt index e63775a9d7..bb1e8e930f 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/comm/TidepoolUploader.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/comm/TidepoolUploader.kt @@ -4,6 +4,7 @@ import android.content.Context import android.os.PowerManager import android.os.SystemClock import info.nightscout.core.ui.dialogs.OKDialog +import info.nightscout.interfaces.Config import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.plugins.sync.R import info.nightscout.plugins.sync.tidepool.events.EventTidepoolStatus @@ -37,7 +38,8 @@ class TidepoolUploader @Inject constructor( private val sp: SP, private val uploadChunk: UploadChunk, private val activePlugin: ActivePlugin, - private val dateUtil: DateUtil + private val dateUtil: DateUtil, + private val config: Config ) { private var wl: PowerManager.WakeLock? = null @@ -157,7 +159,7 @@ class TidepoolUploader @Inject constructor( rxBus.send(EventTidepoolStatus(("Creating new dataset"))) val call = session.service.openDataSet( session.token!!, session.authReply!!.userid!!, - OpenDatasetRequestMessage(activePlugin.activePump.serialNumber(), dateUtil).getBody() + OpenDatasetRequestMessage(config, dateUtil).getBody() ) call.enqueue(TidepoolCallback(aapsLogger, rxBus, session, "Open New Dataset", { connectionStatus = ConnectionStatus.CONNECTED @@ -229,8 +231,9 @@ class TidepoolUploader @Inject constructor( releaseWakeLock() uploadNext() }, { - rxBus.send(EventTidepoolStatus(("Upload FAILED"))) - releaseWakeLock() + connectionStatus = ConnectionStatus.FAILED + rxBus.send(EventTidepoolStatus(("Upload FAILED"))) + releaseWakeLock() })) } } diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/comm/UploadChunk.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/comm/UploadChunk.kt index c363cd98fc..dc962f0f83 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/comm/UploadChunk.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/comm/UploadChunk.kt @@ -176,7 +176,9 @@ class UploadChunk @Inject constructor( val pss = repository.getEffectiveProfileSwitchDataFromTimeToTime(start, end, true).blockingGet() val selection = LinkedList() for (ps in pss) { - newInstanceOrNull(ps)?.let { selection.add(it) } + newInstanceOrNull(ps)?.let { + selection.add(it) + } } if (selection.size > 0) rxBus.send(EventTidepoolStatus("${selection.size} ProfileSwitches selected for upload")) diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/elements/ProfileElement.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/elements/ProfileElement.kt index a9800f195b..297bee3ca5 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/elements/ProfileElement.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/elements/ProfileElement.kt @@ -24,7 +24,7 @@ class ProfileElement(ps: EffectiveProfileSwitch, serialNumber: String, dateUtil: @Expose internal var insulinSensitivities: IsfProfile = IsfProfile() @Expose - internal var deviceId: String = TidepoolUploader.PUMP_TYPE + ":" + serialNumber + internal var deviceId: String? = TidepoolUploader.PUMP_TYPE + ":" + serialNumber @Expose internal var deviceSerialNumber: String = serialNumber @Expose @@ -35,15 +35,14 @@ class ProfileElement(ps: EffectiveProfileSwitch, serialNumber: String, dateUtil: init { type = "pumpSettings" val profile: Profile = ProfileSealed.EPS(ps) - checkNotNull(profile) for (br in profile.getBasalValues()) basalSchedules.Normal.add(BasalRate(br.timeAsSeconds * 1000, br.value)) for (target in profile.getSingleTargetsMgdl()) - bgTargets.Normal.add(Target(target.timeAsSeconds * 1000, target.value)) + bgTargets.Normal.add(Target(target.timeAsSeconds * 1000, target.value.toInt())) for (ic in profile.getIcsValues()) - carbRatios.Normal.add(Ratio(ic.timeAsSeconds * 1000, ic.value)) + carbRatios.Normal.add(Ratio(ic.timeAsSeconds * 1000, ic.value.toInt())) for (isf in profile.getIsfsMgdlValues()) - insulinSensitivities.Normal.add(Ratio(isf.timeAsSeconds * 1000, isf.value)) + insulinSensitivities.Normal.add(Ratio(isf.timeAsSeconds * 1000, isf.value.toInt())) } inner class BasalProfile internal constructor( @@ -74,7 +73,7 @@ class ProfileElement(ps: EffectiveProfileSwitch, serialNumber: String, dateUtil: @field:Expose internal var start: Int, @field:Expose - internal var target: Double + internal var target: Int ) inner class IcProfile internal constructor( @@ -91,6 +90,6 @@ class ProfileElement(ps: EffectiveProfileSwitch, serialNumber: String, dateUtil: @field:Expose internal var start: Int, @field:Expose - internal var amount: Double + internal var amount: Int ) } diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/messages/OpenDatasetRequestMessage.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/messages/OpenDatasetRequestMessage.kt index 5117af073c..e1fcc48543 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/messages/OpenDatasetRequestMessage.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/tidepool/messages/OpenDatasetRequestMessage.kt @@ -1,15 +1,16 @@ package info.nightscout.plugins.sync.tidepool.messages import com.google.gson.annotations.Expose +import info.nightscout.interfaces.Config import info.nightscout.plugins.sync.tidepool.comm.TidepoolUploader import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.T import java.util.TimeZone -class OpenDatasetRequestMessage(serialNumber: String, dateUtil: DateUtil) : BaseMessage() { +class OpenDatasetRequestMessage(config: Config, dateUtil: DateUtil) : BaseMessage() { @Expose - var deviceId: String = TidepoolUploader.PUMP_TYPE + ":" + serialNumber + var deviceId: String? = null @Expose var time: String = dateUtil.toISOAsUTC(System.currentTimeMillis()) @@ -22,7 +23,7 @@ class OpenDatasetRequestMessage(serialNumber: String, dateUtil: DateUtil) : Base //public String byUser; @Expose - var client = ClientInfo() + var client = ClientInfo(config.APPLICATION_ID) @Expose var computerTime: String = dateUtil.toISONoZone(System.currentTimeMillis()) @@ -49,16 +50,12 @@ class OpenDatasetRequestMessage(serialNumber: String, dateUtil: DateUtil) : Base var timezone: String = TimeZone.getDefault().id @Expose - var version = "1.0" + var version = config.VERSION_NAME - inner class ClientInfo { - - @Expose - val name = "AAPS" - - @Expose - val version = TidepoolUploader.VERSION - } + inner class ClientInfo( + @Expose val name: String, + @Expose val version: String = TidepoolUploader.VERSION + ) inner class Deduplicator {