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 fb0c430054..2ce0d5852e 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 @@ -45,6 +45,7 @@ import org.json.JSONObject import java.util.* import javax.inject.Inject import javax.inject.Singleton +import kotlin.random.Random @Singleton class OmnipodDashPumpPlugin @Inject constructor( @@ -131,6 +132,7 @@ class OmnipodDashPumpPlugin @Inject constructor( history.updateFromState(podStateManager), podStateManager.updateActiveCommand() .map { handleCommandConfirmation(it) } + .map { checkPodKaput() } .ignoreElement(), ) ).blockingGet() @@ -141,6 +143,25 @@ class OmnipodDashPumpPlugin @Inject constructor( } } + private fun checkPodKaput() { + if (podStateManager.isPodKaput) { + val tbr = pumpSync.expectedPumpState().temporaryBasal + if (tbr?.rate == 0.0) { + return + } + pumpSync.syncTemporaryBasalWithPumpId( + timestamp = System.currentTimeMillis(), + rate = 0.0, + duration = T.mins(PodConstants.MAX_POD_LIFETIME.standardMinutes).msecs(), + isAbsolute = true, + type = PumpSync.TemporaryBasalType.PUMP_SUSPEND, + pumpId = Random.Default.nextLong(), // we don't use this, just make sure it's unique + pumpType = PumpType.OMNIPOD_DASH, + pumpSerial = serialNumber() + ) + } + } + override fun setNewBasalProfile(profile: Profile): PumpEnactResult { val basalProgram = mapProfileToBasalProgram(profile) return executeProgrammingCommand( @@ -220,7 +241,10 @@ class OmnipodDashPumpPlugin @Inject constructor( val date = Date() val ret = podStateManager.basalProgram?.rateAt(date) ?: 0.0 aapsLogger.info(LTag.PUMP, "baseBasalRate: %ret at $date}") - return ret + return if (podStateManager.alarmType != null) { + 0.0 + } else + ret } override val reservoirLevel: Double diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt index 7be3770745..46e9652aaf 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt @@ -28,6 +28,7 @@ interface OmnipodDashPodStateManager { val isActivationCompleted: Boolean val isSuspended: Boolean val isPodRunning: Boolean + val isPodKaput: Boolean var bluetoothConnectionState: BluetoothConnectionState val lastUpdatedSystem: Long // System.currentTimeMillis() @@ -57,6 +58,7 @@ interface OmnipodDashPodStateManager { val deliveryStatus: DeliveryStatus? val minutesSinceActivation: Short? val activeAlerts: EnumSet? + val alarmType: AlarmType? var tempBasal: TempBasal? val tempBasalActive: Boolean diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt index 9d24462b68..423cd8f836 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt @@ -55,6 +55,9 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( get() = podState.deliveryStatus?.equals(DeliveryStatus.SUSPENDED) ?: false + override val isPodKaput: Boolean + get() = podState.podStatus in arrayOf(PodStatus.ALARM, PodStatus.DEACTIVATED) + override val isPodRunning: Boolean get() = podState.podStatus?.isRunning() ?: false @@ -137,6 +140,9 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( override val activeAlerts: EnumSet? get() = podState.activeAlerts + override val alarmType: AlarmType? + get() = podState.alarmType + override var tempBasal: OmnipodDashPodStateManager.TempBasal? get() = podState.tempBasal set(tempBasal) { @@ -384,15 +390,24 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( } override fun updateFromAlarmStatusResponse(response: AlarmStatusResponse) { - // TODO - logger.error( - LTag.PUMP, - "Not implemented: OmnipodDashPodStateManagerImpl.updateFromAlarmStatusResponse(AlarmStatusResponse)" - ) logger.info( LTag.PUMP, "Received AlarmStatusReponse: $response" ) + podState.deliveryStatus = response.deliveryStatus + podState.podStatus = response.podStatus + podState.pulsesDelivered = response.totalPulsesDelivered + if (response.reservoirPulsesRemaining < 1023) { + podState.pulsesRemaining = response.reservoirPulsesRemaining + } + podState.sequenceNumberOfLastProgrammingCommand = response.sequenceNumberOfLastProgrammingCommand + podState.minutesSinceActivation = response.minutesSinceActivation + podState.activeAlerts = response.activeAlerts + podState.alarmType = response.alarmType + + podState.lastUpdatedSystem = System.currentTimeMillis() + podState.lastStatusResponseReceived = SystemClock.elapsedRealtime() + store() rxBus.send(EventOmnipodDashPumpValuesChanged()) } @@ -464,6 +479,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( var deliveryStatus: DeliveryStatus? = null var minutesSinceActivation: Short? = null var activeAlerts: EnumSet? = null + var alarmType: AlarmType? = null var basalProgram: BasalProgram? = null var tempBasal: OmnipodDashPodStateManager.TempBasal? = null 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 6962b5f4f4..8ec1db4fa4 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 @@ -212,7 +212,6 @@ class OmnipodDashOverviewFragment : DaggerFragment() { } private fun updateUi() { - // TODO update bluetooth status updateBluetoothStatus() updateOmnipodStatus() updatePodActionButtons() @@ -296,6 +295,13 @@ class OmnipodDashOverviewFragment : DaggerFragment() { errors.add(resourceHelper.gs(R.string.omnipod_common_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name)) } */ + podStateManager.alarmType?.let { + errors.add(resourceHelper.gs( + R.string.omnipod_common_pod_status_pod_fault_description, + it.value, + it.toString()) + ) + } // base basal rate podInfoBinding.baseBasalRate.text = if (podStateManager.basalProgram != null && !podStateManager.isSuspended) {