create fake TBR on suspend. Fix createHistory timing bug
This commit is contained in:
parent
5d3b2faeb9
commit
33243a7ed4
5 changed files with 58 additions and 47 deletions
|
@ -158,11 +158,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
|
||||
override fun setNewBasalProfile(profile: Profile): PumpEnactResult {
|
||||
return executeSimpleProgrammingCommand(
|
||||
historyEntry = history.createRecord(
|
||||
commandType = OmnipodCommandType.SET_BASAL_PROFILE
|
||||
),
|
||||
command = omnipodManager.setBasalProgram(mapProfileToBasalProgram(profile)).ignoreElements(),
|
||||
pre = suspendDeliveryIfActive(),
|
||||
historyEntry = history.createRecord(commandType = OmnipodCommandType.SET_BASAL_PROFILE),
|
||||
command = omnipodManager.setBasalProgram(mapProfileToBasalProgram(profile))
|
||||
.ignoreElements(),
|
||||
).toPumpEnactResult()
|
||||
}
|
||||
|
||||
|
@ -172,7 +171,17 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
else
|
||||
executeSimpleProgrammingCommand(
|
||||
history.createRecord(OmnipodCommandType.SUSPEND_DELIVERY),
|
||||
omnipodManager.suspendDelivery().ignoreElements()
|
||||
omnipodManager.suspendDelivery()
|
||||
.filter { podEvent -> podEvent is PodEvent.CommandSent }
|
||||
.map {
|
||||
pumpSyncTempBasal(
|
||||
it,
|
||||
0.0,
|
||||
PodConstants.MAX_POD_LIFETIME.standardMinutes,
|
||||
PumpSync.TemporaryBasalType.PUMP_SUSPEND
|
||||
)
|
||||
}
|
||||
.ignoreElements(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -528,10 +537,12 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
command = omnipodManager.suspendDelivery()
|
||||
.filter { podEvent -> podEvent is PodEvent.CommandSent }
|
||||
.map {
|
||||
pumpSyncTempBasal(it,
|
||||
pumpSyncTempBasal(
|
||||
it,
|
||||
0.0,
|
||||
PodConstants.MAX_POD_LIFETIME.standardMinutes,
|
||||
PumpSync.TemporaryBasalType.PUMP_SUSPEND)
|
||||
PumpSync.TemporaryBasalType.PUMP_SUSPEND
|
||||
)
|
||||
}
|
||||
.ignoreElements(),
|
||||
pre = observeDeliveryActive(),
|
||||
|
@ -626,7 +637,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
|
||||
private fun handleCommandConfirmation(confirmation: CommandConfirmed) {
|
||||
val historyEntry = history.getById(confirmation.historyId)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "handling confirmation command: $confirmation")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "handling command confirmation: $confirmation")
|
||||
when (historyEntry.commandType) {
|
||||
OmnipodCommandType.CANCEL_TEMPORARY_BASAL,
|
||||
OmnipodCommandType.SET_BASAL_PROFILE,
|
||||
|
|
|
@ -55,17 +55,16 @@ class DashHistory @Inject constructor(
|
|||
bolusRecord: BolusRecord? = null,
|
||||
resolveResult: ResolvedResult? = null,
|
||||
resolvedAt: Long? = null
|
||||
): Single<String> {
|
||||
): Single<String> = Single.defer {
|
||||
val id = ULID.random()
|
||||
|
||||
when {
|
||||
commandType == SET_BOLUS && bolusRecord == null ->
|
||||
return Single.error(IllegalArgumentException("bolusRecord missing on SET_BOLUS"))
|
||||
Single.error(IllegalArgumentException("bolusRecord missing on SET_BOLUS"))
|
||||
commandType == SET_TEMPORARY_BASAL && tempBasalRecord == null ->
|
||||
return Single.error(IllegalArgumentException("tempBasalRecord missing on SET_TEMPORARY_BASAL"))
|
||||
}
|
||||
|
||||
return dao.save(
|
||||
Single.error(IllegalArgumentException("tempBasalRecord missing on SET_TEMPORARY_BASAL"))
|
||||
else ->
|
||||
dao.save(
|
||||
HistoryRecordEntity(
|
||||
id = id,
|
||||
date = date,
|
||||
|
@ -79,6 +78,7 @@ class DashHistory @Inject constructor(
|
|||
)
|
||||
).toSingle { id }
|
||||
}
|
||||
}
|
||||
|
||||
fun getRecords(): Single<List<HistoryRecord>> =
|
||||
dao.all().map { list -> list.map(historyMapper::entityToDomain) }
|
||||
|
|
Loading…
Reference in a new issue