From 25c44f42068cb6537d45178c34a24e6b4478b3ea Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sat, 12 Jun 2021 23:21:57 +0200 Subject: [PATCH 1/2] add invalidateTemporaryBasalWithPumpId --- .../androidaps/interfaces/PumpSync.kt | 16 ++++++++++++ .../plugins/pump/PumpSyncImplementation.kt | 13 ++++++++++ ...dateTemporaryBasalTransactionWithPumpId.kt | 25 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 database/src/main/java/info/nightscout/androidaps/database/transactions/InvalidateTemporaryBasalTransactionWithPumpId.kt diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/PumpSync.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/PumpSync.kt index ffc7c04d0a..46493ebfe2 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/PumpSync.kt +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/PumpSync.kt @@ -344,6 +344,22 @@ interface PumpSync { **/ fun invalidateTemporaryBasal(id: Long): Boolean + /** + * Invalidate of temporary basals that failed to start + * Dash specific, replace by setting duration to zero ???? + * + * If exists, isValid is set false + * If db record doesn't exist data is ignored and false returned + * + * + * @param pumpId pumpId of temporary basal + * @param pumpType pump type like PumpType.ACCU_CHEK_COMBO + * @param pumpSerial pump serial number + * @return true if running record is found and invalidated + **/ + + fun invalidateTemporaryBasalWithPumpId(pumpId: Long, pumpType: PumpType, pumpSerial: String): Boolean + /** * Invalidate of temporary basals that failed to start * MDT specific diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/PumpSyncImplementation.kt b/core/src/main/java/info/nightscout/androidaps/plugins/pump/PumpSyncImplementation.kt index dfe8a94a42..842381fd03 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/pump/PumpSyncImplementation.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/pump/PumpSyncImplementation.kt @@ -330,6 +330,19 @@ class PumpSyncImplementation @Inject constructor( } } + override fun invalidateTemporaryBasalWithPumpId(pumpId: Long, pumpType: PumpType, pumpSerial: String): Boolean { + repository.runTransactionForResult(InvalidateTemporaryBasalTransactionWithPumpId(pumpId, pumpType.toDbPumpType(), + pumpSerial)) + .doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating TemporaryBasal", it) } + .blockingGet() + .also { result -> + result.invalidated.forEach { + aapsLogger.debug(LTag.DATABASE, "Invalidated TemporaryBasal $it") + } + return result.invalidated.size > 0 + } + } + override fun invalidateTemporaryBasalWithTempId(temporaryId: Long): Boolean { repository.runTransactionForResult(InvalidateTemporaryBasalWithTempIdTransaction(temporaryId)) .doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating TemporaryBasal", it) } diff --git a/database/src/main/java/info/nightscout/androidaps/database/transactions/InvalidateTemporaryBasalTransactionWithPumpId.kt b/database/src/main/java/info/nightscout/androidaps/database/transactions/InvalidateTemporaryBasalTransactionWithPumpId.kt new file mode 100644 index 0000000000..558731b28c --- /dev/null +++ b/database/src/main/java/info/nightscout/androidaps/database/transactions/InvalidateTemporaryBasalTransactionWithPumpId.kt @@ -0,0 +1,25 @@ +package info.nightscout.androidaps.database.transactions + +import info.nightscout.androidaps.database.embedments.InterfaceIDs +import info.nightscout.androidaps.database.entities.TemporaryBasal + +class InvalidateTemporaryBasalTransactionWithPumpId(val pumpId: Long, val pumpType: InterfaceIDs.PumpType, val +pumpSerial: +String) : + Transaction() { + + override fun run(): TransactionResult { + val result = TransactionResult() + val temporaryBasal = database.temporaryBasalDao.findByPumpIds(pumpId, pumpType, pumpSerial) + ?: throw IllegalArgumentException("There is no such Temporary Basal with the specified temp ID.") + temporaryBasal.isValid = false + database.temporaryBasalDao.updateExistingEntry(temporaryBasal) + result.invalidated.add(temporaryBasal) + return result + } + + class TransactionResult { + + val invalidated = mutableListOf() + } +} \ No newline at end of file From 89b08054e6265031359c545204c38a3dbd6787ce Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sat, 12 Jun 2021 23:39:59 +0200 Subject: [PATCH 2/2] update comment --- .../main/java/info/nightscout/androidaps/interfaces/PumpSync.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/PumpSync.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/PumpSync.kt index 46493ebfe2..cc14666dac 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/PumpSync.kt +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/PumpSync.kt @@ -346,7 +346,6 @@ interface PumpSync { /** * Invalidate of temporary basals that failed to start - * Dash specific, replace by setting duration to zero ???? * * If exists, isValid is set false * If db record doesn't exist data is ignored and false returned