handle Pod Alarm
This commit is contained in:
parent
909eae3f3f
commit
aa719e0b9f
4 changed files with 55 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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<AlertType>?
|
||||
val alarmType: AlarmType?
|
||||
|
||||
var tempBasal: TempBasal?
|
||||
val tempBasalActive: Boolean
|
||||
|
|
|
@ -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<AlertType>?
|
||||
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<AlertType>? = null
|
||||
var alarmType: AlarmType? = null
|
||||
|
||||
var basalProgram: BasalProgram? = null
|
||||
var tempBasal: OmnipodDashPodStateManager.TempBasal? = null
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue