Merge pull request #130 from 0pen-dash/avereha/fixes-2

More fixes
This commit is contained in:
Andrei Vereha 2021-09-24 23:21:06 +02:00 committed by GitHub
commit 54b3609b15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 8 deletions

View file

@ -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,27 @@ class OmnipodDashPumpPlugin @Inject constructor(
statusChecker = Runnable {
refreshStatusOnUnacknowledgedCommands()
updatePodWarnings()
// createFakeTBRWhenNoActivePod()
// TODO: this is called from the main thread
aapsLogger.info(LTag.PUMP, "statusChecker")
createFakeTBRWhenNoActivePod()
.subscribeOn(aapsSchedulers.io)
.subscribeBy(
onError = {
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 +142,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
)
}
}
Completable.complete()
}
private fun updatePodWarnings() {
@ -1078,6 +1089,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()

View file

@ -638,7 +638,6 @@ class OmnipodDashManagerImpl @Inject constructor(
observeConnectToPod,
observeSendDeactivateCommand
).interceptPodEvents()
//
.doOnComplete(podStateManager::reset)
}

View file

@ -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

View file

@ -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() {
@ -540,7 +539,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
val rate = tempBasal.rate
val duration = tempBasal.durationInMinutes
val minutesRunning = 0 // TODO
val minutesRunning = Duration.ofMillis(System.currentTimeMillis() - startTime).toMinutes()
podInfoBinding.tempBasal.text = resourceHelper.gs(
R.string.omnipod_common_overview_temp_basal_value,