callback if carbs are added to db but not pump
This commit is contained in:
parent
93b1b37021
commit
94a0283eb6
1 changed files with 24 additions and 15 deletions
|
@ -41,6 +41,7 @@ import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
|
import io.reactivex.rxkotlin.subscribeBy
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
@ -196,20 +197,28 @@ open class CommandQueue @Inject constructor(
|
||||||
// Check if pump store carbs
|
// Check if pump store carbs
|
||||||
// If not, it's not necessary add command to the queue and initiate connection
|
// If not, it's not necessary add command to the queue and initiate connection
|
||||||
// Assuming carbs in the future and carbs with duration are NOT stores anyway
|
// Assuming carbs in the future and carbs with duration are NOT stores anyway
|
||||||
if (detailedBolusInfo.carbs > 0)
|
if ((detailedBolusInfo.carbs > 0) &&
|
||||||
if (!activePlugin.get().activePump.pumpDescription.storesCarbInfo
|
(!activePlugin.get().activePump.pumpDescription.storesCarbInfo ||
|
||||||
|| detailedBolusInfo.carbsDuration != 0L
|
detailedBolusInfo.carbsDuration != 0L ||
|
||||||
|| detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp > dateUtil._now()
|
(detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp) > dateUtil._now())
|
||||||
) {
|
) {
|
||||||
disposable += repository.runTransactionForResult(detailedBolusInfo.insertCarbsTransaction())
|
disposable += repository.runTransactionForResult(detailedBolusInfo.insertCarbsTransaction())
|
||||||
.subscribe(
|
.subscribeBy(
|
||||||
{ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted carbs $it") } },
|
onSuccess = { result ->
|
||||||
{ aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it) }
|
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted carbs $it") }
|
||||||
|
callback?.result(PumpEnactResult(injector).enacted(false).success(true))?.run()
|
||||||
|
|
||||||
|
},
|
||||||
|
onError = {
|
||||||
|
aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it)
|
||||||
|
callback?.result(PumpEnactResult(injector).enacted(false).success(false))?.run()
|
||||||
|
}
|
||||||
)
|
)
|
||||||
// Do not process carbs anymore
|
// Do not process carbs anymore
|
||||||
detailedBolusInfo.carbs = 0.0
|
detailedBolusInfo.carbs = 0.0
|
||||||
// if no insulin just exit
|
// if no insulin just exit
|
||||||
if (detailedBolusInfo.insulin == 0.0) return true
|
if (detailedBolusInfo.insulin == 0.0) return true
|
||||||
|
|
||||||
}
|
}
|
||||||
var type = if (detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB) CommandType.SMB_BOLUS else CommandType.BOLUS
|
var type = if (detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB) CommandType.SMB_BOLUS else CommandType.BOLUS
|
||||||
if (type == CommandType.SMB_BOLUS) {
|
if (type == CommandType.SMB_BOLUS) {
|
||||||
|
|
Loading…
Reference in a new issue