diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSOfflineEvent.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSOfflineEvent.kt index 64b7607b17..4ef09b0413 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSOfflineEvent.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSOfflineEvent.kt @@ -4,17 +4,17 @@ import info.nightscout.sdk.localmodel.entry.NsUnits data class NSOfflineEvent( override val date: Long, - override val device: String?, + override val device: String? = null, override val identifier: String?, - override val units: NsUnits?, - override val srvModified: Long?, - override val srvCreated: Long?, + override val units: NsUnits? = null, + override val srvModified: Long? = null, + override val srvCreated: Long? = null, override val utcOffset: Long, - override val subject: String?, - override var isReadOnly: Boolean, + override val subject: String? = null, + override var isReadOnly: Boolean = false, override val isValid: Boolean, override val eventType: EventType, - override val notes: String?, + override val notes: String? = null, override val pumpId: Long?, override val endId: Long?, override val pumpType: String?, diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt index 5a6567541a..fbc30ba890 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt @@ -39,6 +39,7 @@ import info.nightscout.plugins.sync.nsclientV3.extensions.toNSBolusWizard import info.nightscout.plugins.sync.nsclientV3.extensions.toNSCarbs import info.nightscout.plugins.sync.nsclientV3.extensions.toNSEffectiveProfileSwitch import info.nightscout.plugins.sync.nsclientV3.extensions.toNSFood +import info.nightscout.plugins.sync.nsclientV3.extensions.toNSOfflineEvent import info.nightscout.plugins.sync.nsclientV3.extensions.toNSProfileSwitch import info.nightscout.plugins.sync.nsclientV3.extensions.toNSTemporaryBasal import info.nightscout.plugins.sync.nsclientV3.extensions.toNSTemporaryTarget @@ -389,7 +390,7 @@ class NSClientV3Plugin @Inject constructor( // is DataSyncSelector.PairExtendedBolus -> dataPair.value.toJson(false, profileFunction.getProfile(dataPair.value.timestamp), dateUtil) is DataSyncSelector.PairProfileSwitch -> dataPair.value.toNSProfileSwitch(dateUtil) is DataSyncSelector.PairEffectiveProfileSwitch -> dataPair.value.toNSEffectiveProfileSwitch(dateUtil) - // is DataSyncSelector.PairOfflineEvent -> dataPair.value.toJson(false, dateUtil) + is DataSyncSelector.PairOfflineEvent -> dataPair.value.toNSOfflineEvent() else -> null }?.let { data -> runBlocking { @@ -480,7 +481,15 @@ class NSClientV3Plugin @Inject constructor( } dataSyncSelector.confirmLastEffectiveProfileSwitchIdIfGreater(dataPair.id) } - // is DataSyncSelector.PairOfflineEvent -> dataPair.value.toJson(false, dateUtil) + + is DataSyncSelector.PairOfflineEvent -> { + if (result.response == 201) { // created + dataPair.value.interfaceIDs.nightscoutId = result.identifier + storeDataForDb.nsIdOfflineEvents.add(dataPair.value) + storeDataForDb.scheduleNsIdUpdate() + } + dataSyncSelector.confirmLastOfflineEventIdIfGreater(dataPair.id) + } } } } catch (e: Exception) { diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/extensions/OfflineEventExtension.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/extensions/OfflineEventExtension.kt index 642ea88c48..f2ceb0ec75 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/extensions/OfflineEventExtension.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/extensions/OfflineEventExtension.kt @@ -2,6 +2,7 @@ package info.nightscout.plugins.sync.nsclientV3.extensions import info.nightscout.database.entities.OfflineEvent import info.nightscout.database.entities.embedments.InterfaceIDs +import info.nightscout.sdk.localmodel.treatment.EventType import info.nightscout.sdk.localmodel.treatment.NSOfflineEvent fun NSOfflineEvent.toOfflineEvent(): OfflineEvent = @@ -16,3 +17,21 @@ fun NSOfflineEvent.toOfflineEvent(): OfflineEvent = fun NSOfflineEvent.Reason?.toReason(): OfflineEvent.Reason = OfflineEvent.Reason.fromString(this?.name) + +fun OfflineEvent.toNSOfflineEvent(): NSOfflineEvent = + NSOfflineEvent( + eventType = EventType.APS_OFFLINE, + isValid = isValid, + date = timestamp, + utcOffset = utcOffset, + duration = duration, + reason = reason.toReason(), + identifier = interfaceIDs.nightscoutId, + pumpId = interfaceIDs.pumpId, + pumpType = interfaceIDs.pumpType?.name, + pumpSerial = interfaceIDs.pumpSerial, + endId = interfaceIDs.endId + ) + +fun OfflineEvent.Reason?.toReason(): NSOfflineEvent.Reason = + NSOfflineEvent.Reason.fromString(this?.name) diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/OfflineEventKtTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/OfflineEventKtTest.kt new file mode 100644 index 0000000000..e4883fbb6d --- /dev/null +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/OfflineEventKtTest.kt @@ -0,0 +1,66 @@ +package info.nightscout.plugins.sync.nsclientV3.extensions + +import info.nightscout.database.entities.OfflineEvent +import info.nightscout.database.entities.embedments.InterfaceIDs +import info.nightscout.sdk.localmodel.treatment.NSOfflineEvent +import info.nightscout.sdk.mapper.convertToRemoteAndBack +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +@Suppress("SpellCheckingInspection") +internal class OfflineEventKtTest { + + @Test + fun toOfflineEvent() { + var offlineEvent = OfflineEvent( + timestamp = 10000, + isValid = true, + reason = OfflineEvent.Reason.DISCONNECT_PUMP, + duration = 30000, + interfaceIDs_backing = InterfaceIDs( + nightscoutId = "nightscoutId", + pumpId = 11000, + pumpType = InterfaceIDs.PumpType.DANA_I, + pumpSerial = "bbbb" + ) + ) + + var offlineEvent2 = (offlineEvent.toNSOfflineEvent().convertToRemoteAndBack() as NSOfflineEvent).toOfflineEvent() + Assertions.assertTrue(offlineEvent.contentEqualsTo(offlineEvent2)) + Assertions.assertTrue(offlineEvent.interfaceIdsEqualsTo(offlineEvent2)) + + offlineEvent = OfflineEvent( + timestamp = 10000, + isValid = true, + reason = OfflineEvent.Reason.SUSPEND, + duration = 3600000, + interfaceIDs_backing = InterfaceIDs( + nightscoutId = "nightscoutId", + pumpId = 11000, + pumpType = InterfaceIDs.PumpType.DANA_I, + pumpSerial = "bbbb" + ) + ) + + offlineEvent2 = (offlineEvent.toNSOfflineEvent().convertToRemoteAndBack() as NSOfflineEvent).toOfflineEvent() + Assertions.assertTrue(offlineEvent.contentEqualsTo(offlineEvent2)) + Assertions.assertTrue(offlineEvent.interfaceIdsEqualsTo(offlineEvent2)) + + offlineEvent = OfflineEvent( + timestamp = 10000, + isValid = true, + reason = OfflineEvent.Reason.DISABLE_LOOP, + duration = 0, + interfaceIDs_backing = InterfaceIDs( + nightscoutId = "nightscoutId", + pumpId = 11000, + pumpType = InterfaceIDs.PumpType.DANA_I, + pumpSerial = "bbbb" + ) + ) + + offlineEvent2 = (offlineEvent.toNSOfflineEvent().convertToRemoteAndBack() as NSOfflineEvent).toOfflineEvent() + Assertions.assertTrue(offlineEvent.contentEqualsTo(offlineEvent2)) + Assertions.assertTrue(offlineEvent.interfaceIdsEqualsTo(offlineEvent2)) + } +} \ No newline at end of file diff --git a/wear/src/test/java/info/nightscout/androidaps/interaction/utils/DisplayFormatTest.kt b/wear/src/test/java/info/nightscout/androidaps/interaction/utils/DisplayFormatTest.kt index 9b321c1a6c..ff34768940 100644 --- a/wear/src/test/java/info/nightscout/androidaps/interaction/utils/DisplayFormatTest.kt +++ b/wear/src/test/java/info/nightscout/androidaps/interaction/utils/DisplayFormatTest.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.interaction.utils +import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.data.RawDisplayData import info.nightscout.androidaps.testing.mockers.RawDataMocker @@ -24,7 +25,11 @@ class DisplayFormatTest : TestBase() { displayFormat = DisplayFormat() displayFormat.wearUtil = wearUtil displayFormat.sp = sp + displayFormat.context = context Mockito.`when`(sp.getBoolean("complication_unicode", true)).thenReturn(true) + Mockito.`when`(context.getString(R.string.hour_short)).thenReturn("h") + Mockito.`when`(context.getString(R.string.day_short)).thenReturn("d") + Mockito.`when`(context.getString(R.string.week_short)).thenReturn("w") } @Test fun shortTimeSinceTest() {