set TBR 0 when there is no pod
This commit is contained in:
parent
544ee9df6b
commit
e174f3982b
4 changed files with 23 additions and 7 deletions
|
@ -49,6 +49,7 @@ import io.reactivex.Completable
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
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 org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.time.ZonedDateTime
|
import java.time.ZonedDateTime
|
||||||
|
@ -108,18 +109,34 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
statusChecker = Runnable {
|
statusChecker = Runnable {
|
||||||
refreshStatusOnUnacknowledgedCommands()
|
refreshStatusOnUnacknowledgedCommands()
|
||||||
updatePodWarnings()
|
updatePodWarnings()
|
||||||
// createFakeTBRWhenNoActivePod()
|
aapsLogger.info(LTag.PUMP, "statusChecker")
|
||||||
// TODO: this is called from the main thread
|
|
||||||
|
val err = createFakeTBRWhenNoActivePod()
|
||||||
|
.subscribeOn(aapsSchedulers.io)
|
||||||
|
.subscribeBy(
|
||||||
|
onError = {
|
||||||
|
aapsLogger.warn(LTag.PUMP, "Error on createFakeTBRWhenNoActivePod=$it")
|
||||||
|
},
|
||||||
|
onComplete = {
|
||||||
|
aapsLogger.warn(LTag.PUMP, "createFakeTBRWhenNoActivePod complete")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
aapsLogger.info(LTag.PUMP, "status checker err=$err")
|
||||||
|
err?.let {
|
||||||
|
aapsLogger.warn(LTag.PUMP, "Error on createFakeTBRWhenNoActivePod=$it")
|
||||||
|
}
|
||||||
handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS)
|
handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createFakeTBRWhenNoActivePod() {
|
private fun createFakeTBRWhenNoActivePod(): Completable = Completable.defer {
|
||||||
if (!podStateManager.isPodRunning) {
|
if (!podStateManager.isPodRunning) {
|
||||||
val expectedState = pumpSync.expectedPumpState()
|
val expectedState = pumpSync.expectedPumpState()
|
||||||
val tbr = expectedState.temporaryBasal
|
val tbr = expectedState.temporaryBasal
|
||||||
if (tbr == null || tbr.rate != 0.0) {
|
if (tbr == null || tbr.rate != 0.0) {
|
||||||
aapsLogger.info(LTag.PUMP, "createFakeTBRWhenNoActivePod")
|
aapsLogger.info(LTag.PUMP, "createFakeTBRWhenNoActivePod")
|
||||||
|
// calling connectNewPump() here because pumpSerial could have changed(from 4241 to "n/a")
|
||||||
|
pumpSync.connectNewPump()
|
||||||
pumpSync.syncTemporaryBasalWithPumpId(
|
pumpSync.syncTemporaryBasalWithPumpId(
|
||||||
timestamp = System.currentTimeMillis(),
|
timestamp = System.currentTimeMillis(),
|
||||||
rate = 0.0,
|
rate = 0.0,
|
||||||
|
@ -132,6 +149,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Completable.complete()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePodWarnings() {
|
private fun updatePodWarnings() {
|
||||||
|
@ -1078,6 +1096,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
historyEntry = history.createRecord(OmnipodCommandType.DEACTIVATE_POD),
|
historyEntry = history.createRecord(OmnipodCommandType.DEACTIVATE_POD),
|
||||||
command = omnipodManager.deactivatePod().ignoreElements(),
|
command = omnipodManager.deactivatePod().ignoreElements(),
|
||||||
checkNoActiveCommand = false,
|
checkNoActiveCommand = false,
|
||||||
|
post = createFakeTBRWhenNoActivePod(),
|
||||||
).doOnComplete {
|
).doOnComplete {
|
||||||
rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_FAULT))
|
rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_FAULT))
|
||||||
}.toPumpEnactResult()
|
}.toPumpEnactResult()
|
||||||
|
|
|
@ -638,7 +638,6 @@ class OmnipodDashManagerImpl @Inject constructor(
|
||||||
observeConnectToPod,
|
observeConnectToPod,
|
||||||
observeSendDeactivateCommand
|
observeSendDeactivateCommand
|
||||||
).interceptPodEvents()
|
).interceptPodEvents()
|
||||||
//
|
|
||||||
.doOnComplete(podStateManager::reset)
|
.doOnComplete(podStateManager::reset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activati
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.R
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.R
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.databinding.OmnipodDashPodManagementBinding
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.databinding.OmnipodDashPodManagementBinding
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ActivationProgress
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ActivationProgress
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodStatus
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.wizard.activation.DashPodActivationWizardActivity
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.wizard.activation.DashPodActivationWizardActivity
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.wizard.deactivation.DashPodDeactivationWizardActivity
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.wizard.deactivation.DashPodDeactivationWizardActivity
|
||||||
|
|
|
@ -94,7 +94,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
// These properties are only valid between onCreateView and
|
// These properties are only valid between onCreateView and
|
||||||
// onDestroyView.
|
// onDestroyView.
|
||||||
val binding get() = _binding!!
|
val binding get() = _binding!!
|
||||||
val bluetoothStatusBinding get() = _bluetoothStatusBinding!!
|
private val bluetoothStatusBinding get() = _bluetoothStatusBinding!!
|
||||||
private val podInfoBinding get() = _podInfoBinding!!
|
private val podInfoBinding get() = _podInfoBinding!!
|
||||||
private val buttonBinding get() = _buttonBinding!!
|
private val buttonBinding get() = _buttonBinding!!
|
||||||
|
|
||||||
|
@ -245,7 +245,6 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
private fun updateBluetoothConnectionStatus(event: EventPumpStatusChanged) {
|
private fun updateBluetoothConnectionStatus(event: EventPumpStatusChanged) {
|
||||||
var status = event.getStatus(resourceHelper)
|
var status = event.getStatus(resourceHelper)
|
||||||
bluetoothStatusBinding.omnipodDashBluetoothStatus.text = status
|
bluetoothStatusBinding.omnipodDashBluetoothStatus.text = status
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateBluetoothStatus() {
|
private fun updateBluetoothStatus() {
|
||||||
|
|
Loading…
Reference in a new issue