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 {
|
override fun setNewBasalProfile(profile: Profile): PumpEnactResult {
|
||||||
return executeSimpleProgrammingCommand(
|
return executeSimpleProgrammingCommand(
|
||||||
historyEntry = history.createRecord(
|
|
||||||
commandType = OmnipodCommandType.SET_BASAL_PROFILE
|
|
||||||
),
|
|
||||||
command = omnipodManager.setBasalProgram(mapProfileToBasalProgram(profile)).ignoreElements(),
|
|
||||||
pre = suspendDeliveryIfActive(),
|
pre = suspendDeliveryIfActive(),
|
||||||
|
historyEntry = history.createRecord(commandType = OmnipodCommandType.SET_BASAL_PROFILE),
|
||||||
|
command = omnipodManager.setBasalProgram(mapProfileToBasalProgram(profile))
|
||||||
|
.ignoreElements(),
|
||||||
).toPumpEnactResult()
|
).toPumpEnactResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +171,17 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
else
|
else
|
||||||
executeSimpleProgrammingCommand(
|
executeSimpleProgrammingCommand(
|
||||||
history.createRecord(OmnipodCommandType.SUSPEND_DELIVERY),
|
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()
|
command = omnipodManager.suspendDelivery()
|
||||||
.filter { podEvent -> podEvent is PodEvent.CommandSent }
|
.filter { podEvent -> podEvent is PodEvent.CommandSent }
|
||||||
.map {
|
.map {
|
||||||
pumpSyncTempBasal(it,
|
pumpSyncTempBasal(
|
||||||
|
it,
|
||||||
0.0,
|
0.0,
|
||||||
PodConstants.MAX_POD_LIFETIME.standardMinutes,
|
PodConstants.MAX_POD_LIFETIME.standardMinutes,
|
||||||
PumpSync.TemporaryBasalType.PUMP_SUSPEND)
|
PumpSync.TemporaryBasalType.PUMP_SUSPEND
|
||||||
|
)
|
||||||
}
|
}
|
||||||
.ignoreElements(),
|
.ignoreElements(),
|
||||||
pre = observeDeliveryActive(),
|
pre = observeDeliveryActive(),
|
||||||
|
@ -626,7 +637,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
|
|
||||||
private fun handleCommandConfirmation(confirmation: CommandConfirmed) {
|
private fun handleCommandConfirmation(confirmation: CommandConfirmed) {
|
||||||
val historyEntry = history.getById(confirmation.historyId)
|
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) {
|
when (historyEntry.commandType) {
|
||||||
OmnipodCommandType.CANCEL_TEMPORARY_BASAL,
|
OmnipodCommandType.CANCEL_TEMPORARY_BASAL,
|
||||||
OmnipodCommandType.SET_BASAL_PROFILE,
|
OmnipodCommandType.SET_BASAL_PROFILE,
|
||||||
|
|
|
@ -55,17 +55,16 @@ class DashHistory @Inject constructor(
|
||||||
bolusRecord: BolusRecord? = null,
|
bolusRecord: BolusRecord? = null,
|
||||||
resolveResult: ResolvedResult? = null,
|
resolveResult: ResolvedResult? = null,
|
||||||
resolvedAt: Long? = null
|
resolvedAt: Long? = null
|
||||||
): Single<String> {
|
): Single<String> = Single.defer {
|
||||||
val id = ULID.random()
|
val id = ULID.random()
|
||||||
|
|
||||||
when {
|
when {
|
||||||
commandType == SET_BOLUS && bolusRecord == null ->
|
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 ->
|
commandType == SET_TEMPORARY_BASAL && tempBasalRecord == null ->
|
||||||
return Single.error(IllegalArgumentException("tempBasalRecord missing on SET_TEMPORARY_BASAL"))
|
Single.error(IllegalArgumentException("tempBasalRecord missing on SET_TEMPORARY_BASAL"))
|
||||||
}
|
else ->
|
||||||
|
dao.save(
|
||||||
return dao.save(
|
|
||||||
HistoryRecordEntity(
|
HistoryRecordEntity(
|
||||||
id = id,
|
id = id,
|
||||||
date = date,
|
date = date,
|
||||||
|
@ -79,6 +78,7 @@ class DashHistory @Inject constructor(
|
||||||
)
|
)
|
||||||
).toSingle { id }
|
).toSingle { id }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getRecords(): Single<List<HistoryRecord>> =
|
fun getRecords(): Single<List<HistoryRecord>> =
|
||||||
dao.all().map { list -> list.map(historyMapper::entityToDomain) }
|
dao.all().map { list -> list.map(historyMapper::entityToDomain) }
|
||||||
|
|
Loading…
Reference in a new issue