NSCv3: utcOffset, improve handling

This commit is contained in:
Milos Kozak 2023-01-03 23:10:04 +01:00
parent 688a95746c
commit 854acc2992
19 changed files with 58 additions and 43 deletions

View file

@ -120,7 +120,7 @@ class NSAndroidClientImpl(
val response = api.getSgvsModifiedSince(from, limit) val response = api.getSgvsModifiedSince(from, limit)
if (response.isSuccessful) { if (response.isSuccessful) {
val eTagString = response.headers()["ETag"] val eTagString = response.headers()["ETag"]
val eTag = eTagString?.substring(3, eTagString.length - 1)?.toLong() ?: throw UnsuccessfullNightscoutException() val eTag = eTagString?.substring(3, eTagString.length - 1)?.toLong()
return@callWrapper NSAndroidClient.ReadResponse(eTag, response.body()?.result?.map(RemoteEntry::toSgv).toNotNull()) return@callWrapper NSAndroidClient.ReadResponse(eTag, response.body()?.result?.map(RemoteEntry::toSgv).toNotNull())
} else { } else {
throw UnsuccessfullNightscoutException() throw UnsuccessfullNightscoutException()
@ -142,6 +142,7 @@ class NSAndroidClientImpl(
val remoteEntry = nsSgvV3.toRemoteEntry() val remoteEntry = nsSgvV3.toRemoteEntry()
remoteEntry.app = "AAPS" remoteEntry.app = "AAPS"
val response = api.createEntry(remoteEntry) val response = api.createEntry(remoteEntry)
val responseBody = response.body()
val errorResponse = response.errorBody()?.string() val errorResponse = response.errorBody()?.string()
if (response.code() == 200) { if (response.code() == 200) {
return@callWrapper CreateUpdateResponse( return@callWrapper CreateUpdateResponse(
@ -152,11 +153,10 @@ class NSAndroidClientImpl(
} else if (response.code() == 201) { } else if (response.code() == 201) {
return@callWrapper CreateUpdateResponse( return@callWrapper CreateUpdateResponse(
response = response.code(), response = response.code(),
identifier = response.body()?.result?.identifier identifier = responseBody?.result?.identifier,
?: throw UnknownResponseNightscoutException(), isDeduplication = responseBody?.result?.isDeduplication ?: false,
isDeduplication = response.body()?.result?.isDeduplication ?: false, deduplicatedIdentifier = responseBody?.result?.deduplicatedIdentifier,
deduplicatedIdentifier = response.body()?.result?.deduplicatedIdentifier, lastModified = responseBody?.result?.lastModified
lastModified = response.body()?.result?.lastModified
) )
} else if (response.code() == 400 && errorResponse?.contains("Bad or missing utcOffset field") == true && nsSgvV3.utcOffset != 0L) { } else if (response.code() == 400 && errorResponse?.contains("Bad or missing utcOffset field") == true && nsSgvV3.utcOffset != 0L) {
// Record can be originally uploaded without utcOffset // Record can be originally uploaded without utcOffset
@ -211,7 +211,6 @@ class NSAndroidClientImpl(
if (response.isSuccessful) { if (response.isSuccessful) {
val eTagString = response.headers()["ETag"] val eTagString = response.headers()["ETag"]
val eTag = eTagString?.substring(3, eTagString.length - 1)?.toLong() val eTag = eTagString?.substring(3, eTagString.length - 1)?.toLong()
?: throw UnsuccessfullNightscoutException()
return@callWrapper NSAndroidClient.ReadResponse(eTag, response.body()?.result?.map(RemoteTreatment::toTreatment).toNotNull()) return@callWrapper NSAndroidClient.ReadResponse(eTag, response.body()?.result?.map(RemoteTreatment::toTreatment).toNotNull())
} else { } else {
throw UnsuccessfullNightscoutException() throw UnsuccessfullNightscoutException()
@ -243,8 +242,7 @@ class NSAndroidClientImpl(
} else if (response.code() == 201) { } else if (response.code() == 201) {
return@callWrapper CreateUpdateResponse( return@callWrapper CreateUpdateResponse(
response = response.code(), response = response.code(),
identifier = response.body()?.result?.identifier identifier = response.body()?.result?.identifier,
?: throw UnknownResponseNightscoutException(),
isDeduplication = response.body()?.result?.isDeduplication ?: false, isDeduplication = response.body()?.result?.isDeduplication ?: false,
deduplicatedIdentifier = response.body()?.result?.deduplicatedIdentifier, deduplicatedIdentifier = response.body()?.result?.deduplicatedIdentifier,
lastModified = response.body()?.result?.lastModified lastModified = response.body()?.result?.lastModified
@ -326,7 +324,7 @@ class NSAndroidClientImpl(
} else if (response.code() == 201) { } else if (response.code() == 201) {
return@callWrapper CreateUpdateResponse( return@callWrapper CreateUpdateResponse(
response = response.code(), response = response.code(),
identifier = response.body()?.result?.identifier ?: throw UnknownResponseNightscoutException(), identifier = response.body()?.result?.identifier,
isDeduplication = response.body()?.result?.isDeduplication ?: false, isDeduplication = response.body()?.result?.isDeduplication ?: false,
deduplicatedIdentifier = response.body()?.result?.deduplicatedIdentifier, deduplicatedIdentifier = response.body()?.result?.deduplicatedIdentifier,
lastModified = response.body()?.result?.lastModified lastModified = response.body()?.result?.lastModified
@ -361,7 +359,8 @@ class NSAndroidClientImpl(
delayBetweenRetries = RETRY_DELAY, delayBetweenRetries = RETRY_DELAY,
excludedExceptions = listOf( excludedExceptions = listOf(
InvalidAccessTokenException::class, InvalidAccessTokenException::class,
DateHeaderOutOfToleranceException::class DateHeaderOutOfToleranceException::class,
InvalidFormatNightscoutException::class
) )
) { ) {
block.invoke() block.invoke()

View file

@ -11,7 +11,7 @@ import info.nightscout.sdk.remotemodel.RemoteDeviceStatus
interface NSAndroidClient { interface NSAndroidClient {
class ReadResponse<T>( class ReadResponse<T>(
val lastServerModified: Long, val lastServerModified: Long?,
val values: T val values: T
) )

View file

@ -1,6 +1,7 @@
package info.nightscout.database.transactions package info.nightscout.database.transactions
import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
import java.util.TimeZone
data class TransactionGlucoseValue( data class TransactionGlucoseValue(
val timestamp: Long, val timestamp: Long,
@ -10,5 +11,6 @@ data class TransactionGlucoseValue(
val trendArrow: GlucoseValue.TrendArrow, val trendArrow: GlucoseValue.TrendArrow,
val nightscoutId: String? = null, val nightscoutId: String? = null,
val sourceSensor: GlucoseValue.SourceSensor, val sourceSensor: GlucoseValue.SourceSensor,
val isValid: Boolean = true val isValid: Boolean = true,
val utcOffset: Long = TimeZone.getDefault().getOffset(timestamp).toLong()
) )

View file

@ -24,7 +24,8 @@ class CgmSourceTransaction constructor(
noise = it.noise, noise = it.noise,
trendArrow = it.trendArrow, trendArrow = it.trendArrow,
sourceSensor = it.sourceSensor, sourceSensor = it.sourceSensor,
isValid = it.isValid isValid = it.isValid,
utcOffset = it.utcOffset
).also { gv -> ).also { gv ->
gv.interfaceIDs.nightscoutId = it.nightscoutId gv.interfaceIDs.nightscoutId = it.nightscoutId
} }

View file

@ -121,7 +121,8 @@ class NSClientSourcePlugin @Inject constructor(
trendArrow = GlucoseValue.TrendArrow.fromString(sgv.direction?.nsName), trendArrow = GlucoseValue.TrendArrow.fromString(sgv.direction?.nsName),
nightscoutId = sgv.identifier, nightscoutId = sgv.identifier,
sourceSensor = GlucoseValue.SourceSensor.fromString(sgv.device), sourceSensor = GlucoseValue.SourceSensor.fromString(sgv.device),
isValid = sgv.isValid isValid = sgv.isValid,
utcOffset = T.mins(sgv.utcOffset ?: 0L).msecs()
) )
} }

View file

@ -358,7 +358,7 @@ class NSClientV3Plugin @Inject constructor(
call?.let { it(data) }?.let { result -> call?.let { it(data) }?.let { result ->
when (result.response) { when (result.response) {
200 -> rxBus.send(EventNSClientNewLog("UPDATED", "OK ${dataPair.value.javaClass.simpleName}")) 200 -> rxBus.send(EventNSClientNewLog("UPDATED", "OK ${dataPair.value.javaClass.simpleName}"))
201 -> rxBus.send(EventNSClientNewLog("ADDED", "OK ${dataPair.value.javaClass.simpleName} ${result.identifier}")) 201 -> rxBus.send(EventNSClientNewLog("ADDED", "OK ${dataPair.value.javaClass.simpleName}"))
400 -> rxBus.send(EventNSClientNewLog("FAIL", "${dataPair.value.javaClass.simpleName} ${result.errorResponse}")) 400 -> rxBus.send(EventNSClientNewLog("FAIL", "${dataPair.value.javaClass.simpleName} ${result.errorResponse}"))
else -> { else -> {
@ -411,7 +411,7 @@ class NSClientV3Plugin @Inject constructor(
call?.let { it(data) }?.let { result -> call?.let { it(data) }?.let { result ->
when (result.response) { when (result.response) {
200 -> rxBus.send(EventNSClientNewLog("UPDATED", "OK ${dataPair.value.javaClass.simpleName}")) 200 -> rxBus.send(EventNSClientNewLog("UPDATED", "OK ${dataPair.value.javaClass.simpleName}"))
201 -> rxBus.send(EventNSClientNewLog("ADDED", "OK ${dataPair.value.javaClass.simpleName} ${result.identifier}")) 201 -> rxBus.send(EventNSClientNewLog("ADDED", "OK ${dataPair.value.javaClass.simpleName}"))
400 -> rxBus.send(EventNSClientNewLog("FAIL", "${dataPair.value.javaClass.simpleName} ${result.errorResponse}")) 400 -> rxBus.send(EventNSClientNewLog("FAIL", "${dataPair.value.javaClass.simpleName} ${result.errorResponse}"))
else -> { else -> {
@ -490,7 +490,7 @@ class NSClientV3Plugin @Inject constructor(
call?.let { it(data) }?.let { result -> call?.let { it(data) }?.let { result ->
when (result.response) { when (result.response) {
200 -> rxBus.send(EventNSClientNewLog("UPDATED", "OK ${dataPair.value.javaClass.simpleName}")) 200 -> rxBus.send(EventNSClientNewLog("UPDATED", "OK ${dataPair.value.javaClass.simpleName}"))
201 -> rxBus.send(EventNSClientNewLog("ADDED", "OK ${dataPair.value.javaClass.simpleName} ${result.identifier}")) 201 -> rxBus.send(EventNSClientNewLog("ADDED", "OK ${dataPair.value.javaClass.simpleName}"))
400 -> rxBus.send(EventNSClientNewLog("FAIL", "${dataPair.value.javaClass.simpleName} ${result.errorResponse}")) 400 -> rxBus.send(EventNSClientNewLog("FAIL", "${dataPair.value.javaClass.simpleName} ${result.errorResponse}"))
else -> { else -> {

View file

@ -6,6 +6,7 @@ import info.nightscout.database.entities.BolusCalculatorResult
import info.nightscout.sdk.localmodel.entry.NsUnits import info.nightscout.sdk.localmodel.entry.NsUnits
import info.nightscout.sdk.localmodel.treatment.EventType import info.nightscout.sdk.localmodel.treatment.EventType
import info.nightscout.sdk.localmodel.treatment.NSBolusWizard import info.nightscout.sdk.localmodel.treatment.NSBolusWizard
import info.nightscout.shared.utils.T
fun NSBolusWizard.toBolusCalculatorResult(): BolusCalculatorResult? = fun NSBolusWizard.toBolusCalculatorResult(): BolusCalculatorResult? =
try { try {
@ -25,7 +26,7 @@ fun BolusCalculatorResult.toNSBolusWizard(): NSBolusWizard =
eventType = EventType.BOLUS_WIZARD, eventType = EventType.BOLUS_WIZARD,
isValid = isValid, isValid = isValid,
date = timestamp, date = timestamp,
utcOffset = utcOffset, utcOffset = T.msecs(utcOffset).mins(),
notes = note, notes = note,
bolusCalculatorResult = Gson().toJson(this).toString(), bolusCalculatorResult = Gson().toJson(this).toString(),
units = NsUnits.MG_DL, units = NsUnits.MG_DL,

View file

@ -4,13 +4,14 @@ import info.nightscout.database.entities.Bolus
import info.nightscout.database.entities.embedments.InterfaceIDs import info.nightscout.database.entities.embedments.InterfaceIDs
import info.nightscout.sdk.localmodel.treatment.EventType import info.nightscout.sdk.localmodel.treatment.EventType
import info.nightscout.sdk.localmodel.treatment.NSBolus import info.nightscout.sdk.localmodel.treatment.NSBolus
import info.nightscout.shared.utils.T
import java.security.InvalidParameterException import java.security.InvalidParameterException
fun NSBolus.toBolus(): Bolus = fun NSBolus.toBolus(): Bolus =
Bolus( Bolus(
isValid = isValid, isValid = isValid,
timestamp = date ?: throw InvalidParameterException(), timestamp = date ?: throw InvalidParameterException(),
utcOffset = utcOffset ?: 0L, utcOffset = T.mins(utcOffset ?: 0L).msecs(),
amount = insulin, amount = insulin,
type = type.toBolusType(), type = type.toBolusType(),
notes = notes, notes = notes,
@ -26,7 +27,7 @@ fun Bolus.toNSBolus(): NSBolus =
eventType = if (type == Bolus.Type.SMB) EventType.CORRECTION_BOLUS else EventType.MEAL_BOLUS, eventType = if (type == Bolus.Type.SMB) EventType.CORRECTION_BOLUS else EventType.MEAL_BOLUS,
isValid = isValid, isValid = isValid,
date = timestamp, date = timestamp,
utcOffset = utcOffset, utcOffset = T.msecs(utcOffset).mins(),
insulin = amount, insulin = amount,
type = type.toBolusType(), type = type.toBolusType(),
notes = notes, notes = notes,

View file

@ -4,13 +4,14 @@ import info.nightscout.database.entities.Carbs
import info.nightscout.database.entities.embedments.InterfaceIDs import info.nightscout.database.entities.embedments.InterfaceIDs
import info.nightscout.sdk.localmodel.treatment.EventType import info.nightscout.sdk.localmodel.treatment.EventType
import info.nightscout.sdk.localmodel.treatment.NSCarbs import info.nightscout.sdk.localmodel.treatment.NSCarbs
import info.nightscout.shared.utils.T
import java.security.InvalidParameterException import java.security.InvalidParameterException
fun NSCarbs.toCarbs(): Carbs = fun NSCarbs.toCarbs(): Carbs =
Carbs( Carbs(
isValid = isValid, isValid = isValid,
timestamp = date ?: throw InvalidParameterException(), timestamp = date ?: throw InvalidParameterException(),
utcOffset = utcOffset ?: 0L, utcOffset = T.mins(utcOffset ?: 0L).msecs(),
amount = carbs, amount = carbs,
notes = notes, notes = notes,
duration = duration ?: 0L, duration = duration ?: 0L,
@ -22,7 +23,7 @@ fun Carbs.toNSCarbs(): NSCarbs =
eventType = if (amount < 12) EventType.CARBS_CORRECTION else EventType.MEAL_BOLUS, eventType = if (amount < 12) EventType.CARBS_CORRECTION else EventType.MEAL_BOLUS,
isValid = isValid, isValid = isValid,
date = timestamp, date = timestamp,
utcOffset = utcOffset, utcOffset = T.msecs(utcOffset).mins(),
carbs = amount, carbs = amount,
notes = notes, notes = notes,
duration = if (duration != 0L) duration else null, duration = if (duration != 0L) duration else null,

View file

@ -8,6 +8,7 @@ import info.nightscout.plugins.sync.nsclient.extensions.fromConstant
import info.nightscout.sdk.localmodel.treatment.EventType import info.nightscout.sdk.localmodel.treatment.EventType
import info.nightscout.sdk.localmodel.treatment.NSEffectiveProfileSwitch import info.nightscout.sdk.localmodel.treatment.NSEffectiveProfileSwitch
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import info.nightscout.shared.utils.T
import java.security.InvalidParameterException import java.security.InvalidParameterException
fun NSEffectiveProfileSwitch.toEffectiveProfileSwitch(dateUtil: DateUtil): EffectiveProfileSwitch? { fun NSEffectiveProfileSwitch.toEffectiveProfileSwitch(dateUtil: DateUtil): EffectiveProfileSwitch? {
@ -17,7 +18,7 @@ fun NSEffectiveProfileSwitch.toEffectiveProfileSwitch(dateUtil: DateUtil): Effec
return EffectiveProfileSwitch( return EffectiveProfileSwitch(
isValid = isValid, isValid = isValid,
timestamp = date ?: throw InvalidParameterException(), timestamp = date ?: throw InvalidParameterException(),
utcOffset = utcOffset ?: 0L, utcOffset = T.mins(utcOffset ?: 0L).msecs(),
basalBlocks = profileSealed.basalBlocks, basalBlocks = profileSealed.basalBlocks,
isfBlocks = profileSealed.isfBlocks, isfBlocks = profileSealed.isfBlocks,
icBlocks = profileSealed.icBlocks, icBlocks = profileSealed.icBlocks,
@ -39,7 +40,7 @@ fun EffectiveProfileSwitch.toNSEffectiveProfileSwitch(dateUtil: DateUtil) : NSEf
eventType = EventType.NOTE, eventType = EventType.NOTE,
isValid = isValid, isValid = isValid,
date = timestamp, date = timestamp,
utcOffset = utcOffset, utcOffset = T.msecs(utcOffset).mins(),
profileJson = ProfileSealed.EPS(this).toPureNsJson(dateUtil), profileJson = ProfileSealed.EPS(this).toPureNsJson(dateUtil),
originalProfileName = originalProfileName, originalProfileName = originalProfileName,
originalCustomizedName = originalCustomizedName, originalCustomizedName = originalCustomizedName,

View file

@ -7,13 +7,14 @@ import info.nightscout.interfaces.profile.Profile
import info.nightscout.sdk.localmodel.treatment.EventType import info.nightscout.sdk.localmodel.treatment.EventType
import info.nightscout.sdk.localmodel.treatment.NSExtendedBolus import info.nightscout.sdk.localmodel.treatment.NSExtendedBolus
import info.nightscout.sdk.localmodel.treatment.NSTreatment import info.nightscout.sdk.localmodel.treatment.NSTreatment
import info.nightscout.shared.utils.T
import java.security.InvalidParameterException import java.security.InvalidParameterException
fun NSExtendedBolus.toExtendedBolus(): ExtendedBolus = fun NSExtendedBolus.toExtendedBolus(): ExtendedBolus =
ExtendedBolus( ExtendedBolus(
isValid = isValid, isValid = isValid,
timestamp = date ?: throw InvalidParameterException(), timestamp = date ?: throw InvalidParameterException(),
utcOffset = utcOffset ?: 0L, utcOffset = T.mins(utcOffset ?: 0L).msecs(),
amount = enteredinsulin, amount = enteredinsulin,
duration = duration, duration = duration,
isEmulatingTempBasal = isEmulatingTempBasal ?: false, isEmulatingTempBasal = isEmulatingTempBasal ?: false,
@ -30,7 +31,7 @@ fun ExtendedBolus.toNSExtendedBolus(profile: Profile, convertToTemporaryBasal: B
eventType = EventType.COMBO_BOLUS, eventType = EventType.COMBO_BOLUS,
isValid = isValid, isValid = isValid,
date = timestamp, date = timestamp,
utcOffset = utcOffset, utcOffset = T.msecs(utcOffset).mins(),
enteredinsulin = amount, enteredinsulin = amount,
duration = duration, duration = duration,
isEmulatingTempBasal = isEmulatingTempBasal, isEmulatingTempBasal = isEmulatingTempBasal,

View file

@ -5,6 +5,7 @@ import info.nightscout.database.transactions.TransactionGlucoseValue
import info.nightscout.sdk.localmodel.entry.Direction import info.nightscout.sdk.localmodel.entry.Direction
import info.nightscout.sdk.localmodel.entry.NSSgvV3 import info.nightscout.sdk.localmodel.entry.NSSgvV3
import info.nightscout.sdk.localmodel.entry.NsUnits import info.nightscout.sdk.localmodel.entry.NsUnits
import info.nightscout.shared.utils.T
import java.security.InvalidParameterException import java.security.InvalidParameterException
// copy of NSClientSourcePlugin for testing // copy of NSClientSourcePlugin for testing
@ -12,12 +13,13 @@ fun NSSgvV3.toTransactionGlucoseValue(): TransactionGlucoseValue {
return TransactionGlucoseValue( return TransactionGlucoseValue(
timestamp = date ?: throw InvalidParameterException(), timestamp = date ?: throw InvalidParameterException(),
value = sgv, value = sgv,
noise = noise?.toDouble(), noise = noise,
raw = filtered, raw = filtered,
trendArrow = GlucoseValue.TrendArrow.fromString(direction?.nsName), trendArrow = GlucoseValue.TrendArrow.fromString(direction?.nsName),
nightscoutId = identifier, nightscoutId = identifier,
sourceSensor = GlucoseValue.SourceSensor.fromString(device), sourceSensor = GlucoseValue.SourceSensor.fromString(device),
isValid = isValid isValid = isValid,
utcOffset = T.mins(utcOffset ?: 0L).msecs()
) )
} }
@ -30,7 +32,8 @@ fun TransactionGlucoseValue.toGlucoseValue() =
noise = noise, noise = noise,
trendArrow = trendArrow, trendArrow = trendArrow,
sourceSensor = sourceSensor, sourceSensor = sourceSensor,
isValid = isValid isValid = isValid,
utcOffset = utcOffset
).also { gv -> ).also { gv ->
gv.interfaceIDs.nightscoutId = nightscoutId gv.interfaceIDs.nightscoutId = nightscoutId
} }
@ -39,7 +42,7 @@ fun GlucoseValue.toNSSvgV3(): NSSgvV3 =
NSSgvV3( NSSgvV3(
isValid = isValid, isValid = isValid,
date = timestamp, date = timestamp,
utcOffset = utcOffset, utcOffset = T.msecs(utcOffset).mins(),
filtered = raw, filtered = raw,
unfiltered = 0.0, unfiltered = 0.0,
sgv = value, sgv = value,

View file

@ -4,13 +4,14 @@ import info.nightscout.database.entities.OfflineEvent
import info.nightscout.database.entities.embedments.InterfaceIDs import info.nightscout.database.entities.embedments.InterfaceIDs
import info.nightscout.sdk.localmodel.treatment.EventType import info.nightscout.sdk.localmodel.treatment.EventType
import info.nightscout.sdk.localmodel.treatment.NSOfflineEvent import info.nightscout.sdk.localmodel.treatment.NSOfflineEvent
import info.nightscout.shared.utils.T
import java.security.InvalidParameterException import java.security.InvalidParameterException
fun NSOfflineEvent.toOfflineEvent(): OfflineEvent = fun NSOfflineEvent.toOfflineEvent(): OfflineEvent =
OfflineEvent( OfflineEvent(
isValid = isValid, isValid = isValid,
timestamp = date ?: throw InvalidParameterException(), timestamp = date ?: throw InvalidParameterException(),
utcOffset = utcOffset ?: 0L, utcOffset = T.mins(utcOffset ?: 0L).msecs(),
duration = duration, duration = duration,
reason = reason.toReason(), reason = reason.toReason(),
interfaceIDs_backing = InterfaceIDs(nightscoutId = identifier, pumpId = pumpId, pumpType = InterfaceIDs.PumpType.fromString(pumpType), pumpSerial = pumpSerial, endId = endId) interfaceIDs_backing = InterfaceIDs(nightscoutId = identifier, pumpId = pumpId, pumpType = InterfaceIDs.PumpType.fromString(pumpType), pumpSerial = pumpSerial, endId = endId)
@ -24,7 +25,7 @@ fun OfflineEvent.toNSOfflineEvent(): NSOfflineEvent =
eventType = EventType.APS_OFFLINE, eventType = EventType.APS_OFFLINE,
isValid = isValid, isValid = isValid,
date = timestamp, date = timestamp,
utcOffset = utcOffset, utcOffset = T.msecs(utcOffset).mins(),
duration = duration, duration = duration,
reason = reason.toReason(), reason = reason.toReason(),
identifier = interfaceIDs.nightscoutId, identifier = interfaceIDs.nightscoutId,

View file

@ -23,7 +23,7 @@ fun NSProfileSwitch.toProfileSwitch(activePlugin: ActivePlugin, dateUtil: DateUt
return ProfileSwitch( return ProfileSwitch(
isValid = isValid, isValid = isValid,
timestamp = date ?: throw InvalidParameterException(), timestamp = date ?: throw InvalidParameterException(),
utcOffset = utcOffset ?: 0L, utcOffset = T.mins(utcOffset ?: 0L).msecs(),
basalBlocks = profileSealed.basalBlocks, basalBlocks = profileSealed.basalBlocks,
isfBlocks = profileSealed.isfBlocks, isfBlocks = profileSealed.isfBlocks,
icBlocks = profileSealed.icBlocks, icBlocks = profileSealed.icBlocks,
@ -49,7 +49,7 @@ fun ProfileSwitch.toNSProfileSwitch(dateUtil: DateUtil): NSProfileSwitch {
eventType = EventType.PROFILE_SWITCH, eventType = EventType.PROFILE_SWITCH,
isValid = isValid, isValid = isValid,
date = timestamp, date = timestamp,
utcOffset = utcOffset, utcOffset = T.msecs(utcOffset).mins(),
timeShift = timeshift, timeShift = timeshift,
percentage = percentage, percentage = percentage,
duration = T.mins(duration).msecs(), duration = T.mins(duration).msecs(),

View file

@ -6,13 +6,14 @@ import info.nightscout.database.entities.embedments.InterfaceIDs
import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.Profile
import info.nightscout.sdk.localmodel.treatment.EventType import info.nightscout.sdk.localmodel.treatment.EventType
import info.nightscout.sdk.localmodel.treatment.NSTemporaryBasal import info.nightscout.sdk.localmodel.treatment.NSTemporaryBasal
import info.nightscout.shared.utils.T
import java.security.InvalidParameterException import java.security.InvalidParameterException
fun NSTemporaryBasal.toTemporaryBasal(): TemporaryBasal = fun NSTemporaryBasal.toTemporaryBasal(): TemporaryBasal =
TemporaryBasal( TemporaryBasal(
isValid = isValid, isValid = isValid,
timestamp = date ?: throw InvalidParameterException(), timestamp = date ?: throw InvalidParameterException(),
utcOffset = utcOffset ?: 0L, utcOffset = T.mins(utcOffset ?: 0L).msecs(),
type = type.toType(), type = type.toType(),
rate = rate, rate = rate,
isAbsolute = isAbsolute, isAbsolute = isAbsolute,
@ -28,7 +29,7 @@ fun TemporaryBasal.toNSTemporaryBasal(profile: Profile): NSTemporaryBasal =
eventType = EventType.TEMPORARY_BASAL, eventType = EventType.TEMPORARY_BASAL,
isValid = isValid, isValid = isValid,
date = timestamp, date = timestamp,
utcOffset = utcOffset, utcOffset = T.msecs(utcOffset).mins(),
type = type.toType(), type = type.toType(),
rate = convertedToAbsolute(timestamp, profile), rate = convertedToAbsolute(timestamp, profile),
isAbsolute = isAbsolute, isAbsolute = isAbsolute,

View file

@ -5,13 +5,14 @@ import info.nightscout.database.entities.embedments.InterfaceIDs
import info.nightscout.sdk.localmodel.entry.NsUnits import info.nightscout.sdk.localmodel.entry.NsUnits
import info.nightscout.sdk.localmodel.treatment.EventType import info.nightscout.sdk.localmodel.treatment.EventType
import info.nightscout.sdk.localmodel.treatment.NSTemporaryTarget import info.nightscout.sdk.localmodel.treatment.NSTemporaryTarget
import info.nightscout.shared.utils.T
import java.security.InvalidParameterException import java.security.InvalidParameterException
fun NSTemporaryTarget.toTemporaryTarget(): TemporaryTarget = fun NSTemporaryTarget.toTemporaryTarget(): TemporaryTarget =
TemporaryTarget( TemporaryTarget(
isValid = isValid, isValid = isValid,
timestamp = date ?: throw InvalidParameterException(), timestamp = date ?: throw InvalidParameterException(),
utcOffset = utcOffset ?: 0L, utcOffset = T.mins(utcOffset ?: 0L).msecs(),
reason = reason.toReason(), reason = reason.toReason(),
highTarget = targetTop.asMgdl(), highTarget = targetTop.asMgdl(),
lowTarget = targetBottom.asMgdl(), lowTarget = targetBottom.asMgdl(),
@ -27,7 +28,7 @@ fun TemporaryTarget.toNSTemporaryTarget(): NSTemporaryTarget =
eventType = EventType.TEMPORARY_TARGET, eventType = EventType.TEMPORARY_TARGET,
isValid = isValid, isValid = isValid,
date = timestamp, date = timestamp,
utcOffset = utcOffset, utcOffset = T.msecs(utcOffset).mins(),
reason = reason.toReason(), reason = reason.toReason(),
targetTop = highTarget, targetTop = highTarget,
targetBottom = lowTarget, targetBottom = lowTarget,

View file

@ -5,13 +5,14 @@ import info.nightscout.database.entities.embedments.InterfaceIDs
import info.nightscout.sdk.localmodel.entry.NsUnits import info.nightscout.sdk.localmodel.entry.NsUnits
import info.nightscout.sdk.localmodel.treatment.EventType import info.nightscout.sdk.localmodel.treatment.EventType
import info.nightscout.sdk.localmodel.treatment.NSTherapyEvent import info.nightscout.sdk.localmodel.treatment.NSTherapyEvent
import info.nightscout.shared.utils.T
import java.security.InvalidParameterException import java.security.InvalidParameterException
fun NSTherapyEvent.toTherapyEvent(): TherapyEvent = fun NSTherapyEvent.toTherapyEvent(): TherapyEvent =
TherapyEvent( TherapyEvent(
isValid = isValid, isValid = isValid,
timestamp = date ?: throw InvalidParameterException(), timestamp = date ?: throw InvalidParameterException(),
utcOffset = utcOffset ?: 0L, utcOffset = T.mins(utcOffset ?: 0L).msecs(),
glucoseUnit = units.toUnits(), glucoseUnit = units.toUnits(),
type = eventType.toType(), type = eventType.toType(),
note = notes, note = notes,
@ -39,7 +40,7 @@ fun TherapyEvent.toNSTherapyEvent(): NSTherapyEvent =
NSTherapyEvent( NSTherapyEvent(
isValid = isValid, isValid = isValid,
date = timestamp, date = timestamp,
utcOffset = utcOffset, utcOffset = T.msecs(utcOffset).mins(),
units = glucoseUnit.toUnits(), units = glucoseUnit.toUnits(),
eventType = type.toType(), eventType = type.toType(),
notes = note, notes = note,

View file

@ -55,7 +55,7 @@ class LoadBgWorker(
else { else {
response = nsAndroidClient.getSgvsModifiedSince(lastLoaded, 500) response = nsAndroidClient.getSgvsModifiedSince(lastLoaded, 500)
sgvs = response.values sgvs = response.values
nsClientV3Plugin.lastLoadedSrvModified.collections.entries = response.lastServerModified response.lastServerModified?.let { nsClientV3Plugin.lastLoadedSrvModified.collections.entries = it }
nsClientV3Plugin.storeLastLoadedSrvModified() nsClientV3Plugin.storeLastLoadedSrvModified()
} }
aapsLogger.debug("SGVS: $sgvs") aapsLogger.debug("SGVS: $sgvs")

View file

@ -53,7 +53,7 @@ class LoadTreatmentsWorker(
else { else {
response = nsAndroidClient.getTreatmentsModifiedSince(lastLoaded, 500) response = nsAndroidClient.getTreatmentsModifiedSince(lastLoaded, 500)
treatments = response.values treatments = response.values
nsClientV3Plugin.lastLoadedSrvModified.collections.treatments = response.lastServerModified response.lastServerModified?.let { nsClientV3Plugin.lastLoadedSrvModified.collections.treatments = it }
nsClientV3Plugin.storeLastLoadedSrvModified() nsClientV3Plugin.storeLastLoadedSrvModified()
} }
aapsLogger.debug("TREATMENTS: $treatments") aapsLogger.debug("TREATMENTS: $treatments")