diff --git a/core/src/test/java/info/nightscout/androidaps/data/ProfileTest.kt b/core/src/test/java/info/nightscout/androidaps/data/ProfileTest.kt index 94bb95e426..3a4631c4a2 100644 --- a/core/src/test/java/info/nightscout/androidaps/data/ProfileTest.kt +++ b/core/src/test/java/info/nightscout/androidaps/data/ProfileTest.kt @@ -73,7 +73,7 @@ class ProfileTest : TestBase() { // Test valid profile var p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(okProfile), dateUtil)!!) - Assert.assertEquals(true, p.isValid("Test", testPumpPlugin, config, resourceHelper, rxBus, hardLimits).isValid) + Assert.assertEquals(true, p.isValid("Test", testPumpPlugin, config, resourceHelper, rxBus, hardLimits, false).isValid) // Assert.assertEquals(true, p.log().contains("NS units: mmol")) // JSONAssert.assertEquals(JSONObject(okProfile), p.toPureNsJson(dateUtil), false) Assert.assertEquals(5.0, p.dia, 0.01) @@ -125,7 +125,7 @@ class ProfileTest : TestBase() { //Test basal profile below limit p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(belowLimitValidProfile), dateUtil)!!) - p.isValid("Test", testPumpPlugin, config, resourceHelper, rxBus, hardLimits) + p.isValid("Test", testPumpPlugin, config, resourceHelper, rxBus, hardLimits, false) // Test profile w/o units Assert.assertNull(pureProfileFromJson(JSONObject(noUnitsValidProfile), dateUtil)) @@ -158,6 +158,6 @@ class ProfileTest : TestBase() { // Test hour alignment testPumpPlugin.pumpDescription.is30minBasalRatesCapable = false p = ProfileSealed.Pure(pureProfileFromJson(JSONObject(notAlignedBasalValidProfile), dateUtil)!!) - p.isValid("Test", testPumpPlugin, config, resourceHelper, rxBus, hardLimits) + p.isValid("Test", testPumpPlugin, config, resourceHelper, rxBus, hardLimits, false) } } \ No newline at end of file diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/ErosHistory.java b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/ErosHistory.java deleted file mode 100644 index f117643cbe..0000000000 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/ErosHistory.java +++ /dev/null @@ -1,31 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.eros.history; - -import java.util.List; - -import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordDao; -import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordEntity; -import io.reactivex.Single; - -public class ErosHistory -{ - private final ErosHistoryRecordDao dao; - - public ErosHistory(ErosHistoryRecordDao dao) { - this.dao = dao; - } - - public List getAllErosHistoryRecordsFromTimestamp(long timeInMillis) { - return dao.allSinceAsc(timeInMillis).blockingGet(); - - } - - public ErosHistoryRecordEntity findErosHistoryRecordByPumpId(long pumpId) { - Single entity = dao.byId(pumpId); - return (entity == null) ? null: entity.blockingGet(); - } - - public void create(ErosHistoryRecordEntity historyRecord){ - // no need for rowId, but lose warnings in IDE and make sure transaction is completed. - long rowId = Single.just(dao.insert(historyRecord)).blockingGet(); - } -} diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/ErosHistory.kt b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/ErosHistory.kt new file mode 100644 index 0000000000..90d1a82ee3 --- /dev/null +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/ErosHistory.kt @@ -0,0 +1,40 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.eros.history + +import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordDao +import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordEntity +import io.reactivex.Maybe +import io.reactivex.Single +import io.reactivex.schedulers.Schedulers + +class ErosHistory(private val dao: ErosHistoryRecordDao) { + + fun getAllErosHistoryRecordsFromTimestamp(timeInMillis: Long): List { + return dao.allSinceAsc(timeInMillis) + .subscribeOn(Schedulers.io()) + .blockingGet() + } + + fun findErosHistoryRecordByPumpId(pumpId: Long): ErosHistoryRecordEntity? { + val record = dao.byId(pumpId) + .subscribeOn(Schedulers.io()) + .toWrappedSingle() + .blockingGet() + return if (record is ValueWrapper.Existing) record.value else null + } + + fun create(historyRecord: ErosHistoryRecordEntity?) { + // no need for rowId, but lose warnings in IDE and make sure transaction is completed. + val rowId = Single.just(dao.insert(historyRecord!!)).blockingGet() + } +} + +@Suppress("USELESS_CAST") +inline fun Maybe.toWrappedSingle(): Single> = + this.map { ValueWrapper.Existing(it) as ValueWrapper } + .switchIfEmpty(Maybe.just(ValueWrapper.Absent())) + .toSingle() + +sealed class ValueWrapper { + data class Existing(val value: T) : ValueWrapper() + class Absent : ValueWrapper() +} \ No newline at end of file diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/database/ErosHistoryRecordDao.kt b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/database/ErosHistoryRecordDao.kt index 7fc1ff18f5..7a21629b06 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/database/ErosHistoryRecordDao.kt +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/history/database/ErosHistoryRecordDao.kt @@ -4,7 +4,7 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import androidx.room.Transaction +import io.reactivex.Maybe import io.reactivex.Single @Dao @@ -14,7 +14,7 @@ interface ErosHistoryRecordDao { fun allSinceAsc(since: Long): Single> @Query("SELECT * FROM historyrecords WHERE pumpId = :id LIMIT 1") - fun byId(id: Long): Single? + fun byId(id: Long): Maybe @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(ErosHistoryRecordEntity: ErosHistoryRecordEntity): Long