diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt index c502c4b71a..12d772b2ad 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt @@ -49,6 +49,7 @@ import io.reactivex.Completable import io.reactivex.Single import io.reactivex.disposables.CompositeDisposable import io.reactivex.rxkotlin.plusAssign +import io.reactivex.rxkotlin.subscribeBy import org.json.JSONObject import java.time.Duration import java.time.ZonedDateTime @@ -108,18 +109,34 @@ class OmnipodDashPumpPlugin @Inject constructor( statusChecker = Runnable { refreshStatusOnUnacknowledgedCommands() updatePodWarnings() - // createFakeTBRWhenNoActivePod() - // TODO: this is called from the main thread + aapsLogger.info(LTag.PUMP, "statusChecker") + + 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) } } - private fun createFakeTBRWhenNoActivePod() { + private fun createFakeTBRWhenNoActivePod(): Completable = Completable.defer { if (!podStateManager.isPodRunning) { val expectedState = pumpSync.expectedPumpState() val tbr = expectedState.temporaryBasal if (tbr == null || tbr.rate != 0.0) { aapsLogger.info(LTag.PUMP, "createFakeTBRWhenNoActivePod") + // calling connectNewPump() here because pumpSerial could have changed(from 4241 to "n/a") + pumpSync.connectNewPump() pumpSync.syncTemporaryBasalWithPumpId( timestamp = System.currentTimeMillis(), rate = 0.0, @@ -132,6 +149,7 @@ class OmnipodDashPumpPlugin @Inject constructor( ) } } + Completable.complete() } private fun updatePodWarnings() { @@ -1078,6 +1096,7 @@ class OmnipodDashPumpPlugin @Inject constructor( historyEntry = history.createRecord(OmnipodCommandType.DEACTIVATE_POD), command = omnipodManager.deactivatePod().ignoreElements(), checkNoActiveCommand = false, + post = createFakeTBRWhenNoActivePod(), ).doOnComplete { rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_FAULT)) }.toPumpEnactResult() diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt index e504e93e62..d64ea2ef42 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt @@ -638,7 +638,6 @@ class OmnipodDashManagerImpl @Inject constructor( observeConnectToPod, observeSendDeactivateCommand ).interceptPodEvents() - // .doOnComplete(podStateManager::reset) } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt index d535d251e2..0e31e65ff7 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt @@ -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.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.PodStatus 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.deactivation.DashPodDeactivationWizardActivity diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt index 49fe0db85f..34915dce52 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt @@ -94,7 +94,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() { // These properties are only valid between onCreateView and // onDestroyView. val binding get() = _binding!! - val bluetoothStatusBinding get() = _bluetoothStatusBinding!! + private val bluetoothStatusBinding get() = _bluetoothStatusBinding!! private val podInfoBinding get() = _podInfoBinding!! private val buttonBinding get() = _buttonBinding!! @@ -245,7 +245,6 @@ class OmnipodDashOverviewFragment : DaggerFragment() { private fun updateBluetoothConnectionStatus(event: EventPumpStatusChanged) { var status = event.getStatus(resourceHelper) bluetoothStatusBinding.omnipodDashBluetoothStatus.text = status - } private fun updateBluetoothStatus() {