Dash: Add option to disable pod expiration alarm
This commit is contained in:
parent
a7d330e87f
commit
512541b484
|
@ -9,6 +9,8 @@
|
|||
<string name="key_omnipod_common_time_change_event_enabled" translatable="false">AAPS.Omnipod.time_change_enabled</string>
|
||||
<string name="key_omnipod_common_expiration_reminder_enabled" translatable="false">AAPS.Omnipod.expiration_reminder_enabled</string>
|
||||
<string name="key_omnipod_common_expiration_reminder_hours_before_shutdown" translatable="false">AAPS.Omnipod.expiration_reminder_hours_before_shutdown</string>
|
||||
<string name="key_omnipod_common_expiration_alarm_enabled" translatable="false">AAPS.Omnipod.expiration_alarm_enabled</string>
|
||||
<string name="key_omnipod_common_expiration_alarm_hours_before_shutdown" translatable="false">AAPS.Omnipod.expiration_alarm_hours_before_shutdown</string>
|
||||
<string name="key_omnipod_common_low_reservoir_alert_enabled" translatable="false">AAPS.Omnipod.low_reservoir_alert_enabled</string>
|
||||
<string name="key_omnipod_common_low_reservoir_alert_units" translatable="false">AAPS.Omnipod.low_reservoir_alert_units</string>
|
||||
<string name="key_omnipod_common_automatically_silence_alerts_enabled" translatable="false">AAPS.Omnipod.automatically_acknowledge_alerts_enabled</string>
|
||||
|
@ -129,7 +131,9 @@
|
|||
<string name="omnipod_common_preferences_suspend_delivery_button_enabled">Show Suspend Delivery button in Omnipod tab</string>
|
||||
<string name="omnipod_common_preferences_time_change_enabled">DST/Time zone detection enabled</string>
|
||||
<string name="omnipod_common_preferences_expiration_reminder_enabled">Expiration reminder enabled</string>
|
||||
<string name="omnipod_common_preferences_expiration_reminder_hours_before_shutdown">Hours before shutdown</string>
|
||||
<string name="omnipod_common_preferences_expiration_reminder_hours_before_shutdown">Reminder at hours before shutdown</string>
|
||||
<string name="omnipod_common_preferences_expiration_alarm_enabled">Expiration alarm enabled</string>
|
||||
<string name="omnipod_common_preferences_expiration_alarm_hours_before_shutdown">Alarm at hours before shutdown</string>
|
||||
<string name="omnipod_common_preferences_low_reservoir_alert_enabled">Low reservoir alert enabled</string>
|
||||
<string name="omnipod_common_preferences_low_reservoir_alert_units">Number of units</string>
|
||||
<string name="omnipod_common_preferences_automatically_silence_alerts">Automatically silence Pod alerts</string>
|
||||
|
|
|
@ -22,6 +22,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definitio
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BeepType
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.DeliveryStatus
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.POD_EXPIRATION_IMMINENT_ALERT_HOURS_REMAINING
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.ResponseType
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.CommandConfirmed
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
||||
|
@ -84,6 +85,7 @@ import java.time.Duration
|
|||
import java.time.ZonedDateTime
|
||||
import java.util.Date
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlin.concurrent.thread
|
||||
|
@ -481,6 +483,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
{
|
||||
if (it.isChanged(rh.gs(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_expiration_reminder_enabled)) ||
|
||||
it.isChanged(rh.gs(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown)) ||
|
||||
it.isChanged(rh.gs(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_expiration_alarm_enabled)) ||
|
||||
it.isChanged(rh.gs(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_expiration_alarm_hours_before_shutdown)) ||
|
||||
it.isChanged(rh.gs(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_low_reservoir_alert_enabled)) ||
|
||||
it.isChanged(rh.gs(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_low_reservoir_alert_units))
|
||||
) {
|
||||
|
@ -1102,16 +1106,22 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
return when (customCommand) {
|
||||
is CommandSilenceAlerts ->
|
||||
silenceAlerts()
|
||||
|
||||
is CommandResumeDelivery ->
|
||||
resumeDelivery()
|
||||
|
||||
is CommandDeactivatePod ->
|
||||
deactivatePod()
|
||||
|
||||
is CommandHandleTimeChange ->
|
||||
handleTimeChange()
|
||||
|
||||
is CommandUpdateAlertConfiguration ->
|
||||
updateAlertConfiguration()
|
||||
|
||||
is CommandPlayTestBeep ->
|
||||
playTestBeep()
|
||||
|
||||
is CommandDisableSuspendAlerts ->
|
||||
disableSuspendAlerts()
|
||||
|
||||
|
@ -1214,14 +1224,18 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
private fun updateAlertConfiguration(): PumpEnactResult {
|
||||
|
||||
val expirationReminderEnabled = sp.getBoolean(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_expiration_reminder_enabled, true)
|
||||
val expirationHours = sp.getInt(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown, 7)
|
||||
val expirationReminderHours = sp.getInt(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown, 7)
|
||||
val expirationAlarmEnabled = sp.getBoolean(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_expiration_alarm_enabled, true)
|
||||
val expirationAlarmHours = sp.getInt(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_expiration_alarm_hours_before_shutdown, 8)
|
||||
val lowReservoirAlertEnabled = sp.getBoolean(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_low_reservoir_alert_enabled, true)
|
||||
val lowReservoirAlertUnits = sp.getInt(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_low_reservoir_alert_units, 10)
|
||||
|
||||
when {
|
||||
podStateManager.sameAlertSettings(
|
||||
expirationReminderEnabled,
|
||||
expirationHours,
|
||||
expirationReminderHours,
|
||||
expirationAlarmEnabled,
|
||||
expirationAlarmHours,
|
||||
lowReservoirAlertEnabled,
|
||||
lowReservoirAlertUnits
|
||||
) -> {
|
||||
|
@ -1236,7 +1250,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
val podLifeLeft = Duration.between(ZonedDateTime.now(), podStateManager.expiry)
|
||||
val expiryAlertDelay = podLifeLeft.minus(Duration.ofHours(expirationHours.toLong()))
|
||||
val expiryAlertDelay = podLifeLeft.minus(Duration.ofHours(expirationReminderHours.toLong()))
|
||||
if (expiryAlertDelay.isNegative) {
|
||||
aapsLogger.warn(
|
||||
LTag.PUMPBTCOMM,
|
||||
|
@ -1245,6 +1259,24 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
)
|
||||
PumpEnactResult(injector).success(false).enacted(false)
|
||||
}
|
||||
val expiryAlarmDelay = podLifeLeft.minus(Duration.ofHours(expirationAlarmHours.toLong()))
|
||||
if (expiryAlarmDelay.isNegative) {
|
||||
aapsLogger.warn(
|
||||
LTag.PUMPBTCOMM,
|
||||
"updateAlertConfiguration negative " +
|
||||
"expiryAlarmDuration=$expiryAlarmDelay"
|
||||
)
|
||||
PumpEnactResult(injector).success(false).enacted(false)
|
||||
}
|
||||
val expiryImminentDelay = podLifeLeft.minus(Duration.ofHours(POD_EXPIRATION_IMMINENT_ALERT_HOURS_REMAINING))
|
||||
if (expiryImminentDelay.isNegative) {
|
||||
aapsLogger.warn(
|
||||
LTag.PUMPBTCOMM,
|
||||
"updateAlertConfiguration negative " +
|
||||
"expiryImminentDuration=$expiryImminentDelay"
|
||||
)
|
||||
PumpEnactResult(injector).success(false).enacted(false)
|
||||
}
|
||||
val alerts = listOf(
|
||||
AlertConfiguration(
|
||||
AlertType.LOW_RESERVOIR,
|
||||
|
@ -1265,14 +1297,39 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
),
|
||||
BeepType.FOUR_TIMES_BIP_BEEP,
|
||||
BeepRepetitionType.EVERY_MINUTE_AND_EVERY_15_MIN
|
||||
),
|
||||
AlertConfiguration(
|
||||
AlertType.EXPIRATION,
|
||||
enabled = expirationAlarmEnabled,
|
||||
durationInMinutes = TimeUnit.HOURS.toMinutes(expirationAlarmHours.toLong()).toShort(),
|
||||
autoOff = false,
|
||||
AlertTrigger.TimerTrigger(
|
||||
expiryAlarmDelay.toMinutes().toShort()
|
||||
),
|
||||
BeepType.FOUR_TIMES_BIP_BEEP,
|
||||
BeepRepetitionType.XXX3
|
||||
),
|
||||
AlertConfiguration(
|
||||
AlertType.EXPIRATION_IMMINENT,
|
||||
enabled = expirationAlarmEnabled,
|
||||
durationInMinutes = 0,
|
||||
autoOff = false,
|
||||
AlertTrigger.TimerTrigger(
|
||||
expiryImminentDelay.toMinutes().toShort()
|
||||
),
|
||||
BeepType.FOUR_TIMES_BIP_BEEP,
|
||||
BeepRepetitionType.XXX3
|
||||
)
|
||||
)
|
||||
|
||||
return executeProgrammingCommand(
|
||||
historyEntry = history.createRecord(OmnipodCommandType.CONFIGURE_ALERTS),
|
||||
command = omnipodManager.programAlerts(alerts).ignoreElements(),
|
||||
post = podStateManager.updateExpirationAlertSettings(
|
||||
expirationReminderEnabled,
|
||||
expirationHours
|
||||
expirationReminderHours,
|
||||
expirationAlarmEnabled,
|
||||
expirationAlarmHours
|
||||
).andThen(
|
||||
podStateManager.updateLowReservoirAlertSettings(
|
||||
lowReservoirAlertEnabled,
|
||||
|
@ -1513,10 +1570,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
// Cancel TBR running on Pump
|
||||
return@defer observeNoActiveTempBasal()
|
||||
.concatWith(podStateManager.updateActiveCommand()
|
||||
.map { handleCommandConfirmation(it) }
|
||||
.ignoreElement())
|
||||
.map { handleCommandConfirmation(it) }
|
||||
.ignoreElement())
|
||||
}
|
||||
|
||||
|
||||
return@defer Completable.complete()
|
||||
}
|
||||
|
||||
|
@ -1537,10 +1594,13 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
return when (notificationType) {
|
||||
Notification.OMNIPOD_TBR_ALERTS ->
|
||||
sp.getBoolean(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_notification_uncertain_tbr_sound_enabled, true)
|
||||
|
||||
Notification.OMNIPOD_UNCERTAIN_SMB ->
|
||||
sp.getBoolean(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_notification_uncertain_smb_sound_enabled, true)
|
||||
|
||||
Notification.OMNIPOD_POD_SUSPENDED ->
|
||||
sp.getBoolean(R.string.key_omnipod_common_notification_delivery_suspended_sound_enabled, true)
|
||||
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ interface OmnipodDashManager {
|
|||
|
||||
fun activatePodPart1(lowReservoirAlertTrigger: AlertTrigger.ReservoirVolumeTrigger?): Observable<PodEvent>
|
||||
|
||||
fun activatePodPart2(basalProgram: BasalProgram, userConfiguredExpirationHours: Long?): Observable<PodEvent>
|
||||
fun activatePodPart2(basalProgram: BasalProgram, userConfiguredExpirationReminderHours: Long?, userConfiguredExpirationAlarmHours: Long?): Observable<PodEvent>
|
||||
|
||||
fun getStatus(type: ResponseType.StatusResponseType): Observable<PodEvent>
|
||||
|
||||
|
|
|
@ -23,11 +23,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definitio
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BasalProgram
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BeepRepetitionType
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BeepType
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.MAX_POD_LIFETIME
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.POD_EXPIRATION_ALERT_HOURS
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.POD_EXPIRATION_ALERT_HOURS_DURATION
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.POD_EXPIRATION_IMMINENT_ALERT_HOURS
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.POD_EXPIRATION_ALERT_HOURS_REMAINING_DEFAULT
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.POD_EXPIRATION_IMMINENT_ALERT_HOURS_REMAINING
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.POD_PULSE_BOLUS_UNITS
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodStatus
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ProgramReminder
|
||||
|
@ -161,9 +159,9 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
// TODO move somewhere else
|
||||
val expectedResponseType = when (type) {
|
||||
ResponseType.StatusResponseType.DEFAULT_STATUS_RESPONSE -> DefaultStatusResponse::class
|
||||
ResponseType.StatusResponseType.ALARM_STATUS -> AlarmStatusResponse::class
|
||||
ResponseType.StatusResponseType.ALARM_STATUS -> AlarmStatusResponse::class
|
||||
|
||||
else -> return Observable.error(UnsupportedOperationException("No response type to class mapping for ${type.name}"))
|
||||
else -> return Observable.error(UnsupportedOperationException("No response type to class mapping for ${type.name}"))
|
||||
}
|
||||
|
||||
return Observable.defer {
|
||||
|
@ -368,19 +366,19 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
return observables.reversed()
|
||||
}
|
||||
|
||||
override fun activatePodPart2(basalProgram: BasalProgram, userConfiguredExpirationHours: Long?):
|
||||
override fun activatePodPart2(basalProgram: BasalProgram, userConfiguredExpirationReminderHours: Long?, userConfiguredExpirationAlarmHours: Long?):
|
||||
Observable<PodEvent> {
|
||||
return Observable.concat(
|
||||
observePodReadyForActivationPart2,
|
||||
observeConnectToPod,
|
||||
observeActivationPart2Commands(basalProgram, userConfiguredExpirationHours)
|
||||
observeActivationPart2Commands(basalProgram, userConfiguredExpirationReminderHours, userConfiguredExpirationAlarmHours)
|
||||
).doOnComplete(ActivationProgressUpdater(ActivationProgress.COMPLETED))
|
||||
.interceptPodEvents()
|
||||
}
|
||||
|
||||
private fun observeActivationPart2Commands(basalProgram: BasalProgram, userConfiguredExpirationHours: Long?):
|
||||
private fun observeActivationPart2Commands(basalProgram: BasalProgram, userConfiguredExpirationReminderHours: Long?, userConfiguredExpirationAlarmHours: Long?):
|
||||
Observable<PodEvent> {
|
||||
val observables = createActivationPart2Observables(basalProgram, userConfiguredExpirationHours)
|
||||
val observables = createActivationPart2Observables(basalProgram, userConfiguredExpirationReminderHours, userConfiguredExpirationAlarmHours)
|
||||
|
||||
return if (observables.isEmpty()) {
|
||||
Observable.empty()
|
||||
|
@ -391,7 +389,8 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
|
||||
private fun createActivationPart2Observables(
|
||||
basalProgram: BasalProgram,
|
||||
userConfiguredExpirationHours: Long?
|
||||
userConfiguredExpirationReminderHours: Long?,
|
||||
userConfiguredExpirationAlarmHours: Long?
|
||||
):
|
||||
List<Observable<PodEvent>> {
|
||||
val observables = ArrayList<Observable<PodEvent>>()
|
||||
|
@ -422,32 +421,42 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
if (podStateManager.activationProgress.isBefore(ActivationProgress.UPDATED_EXPIRATION_ALERTS)) {
|
||||
val podLifeLeft = Duration.between(ZonedDateTime.now(), podStateManager.expiry)
|
||||
|
||||
val expirationAlarmEnabled = userConfiguredExpirationAlarmHours != null && userConfiguredExpirationAlarmHours > 0
|
||||
val expirationAlarmDelay = podLifeLeft.minus(
|
||||
Duration.ofHours(userConfiguredExpirationAlarmHours ?: POD_EXPIRATION_ALERT_HOURS_REMAINING_DEFAULT)
|
||||
)
|
||||
val expirationImminnentDelay = podLifeLeft.minus(
|
||||
Duration.ofHours(POD_EXPIRATION_IMMINENT_ALERT_HOURS_REMAINING)
|
||||
)
|
||||
|
||||
val alerts = mutableListOf(
|
||||
AlertConfiguration(
|
||||
AlertType.EXPIRATION,
|
||||
enabled = true,
|
||||
durationInMinutes = TimeUnit.HOURS.toMinutes(POD_EXPIRATION_ALERT_HOURS_DURATION).toShort(),
|
||||
enabled = expirationAlarmEnabled,
|
||||
durationInMinutes = TimeUnit.HOURS.toMinutes(
|
||||
userConfiguredExpirationAlarmHours ?: POD_EXPIRATION_ALERT_HOURS_REMAINING_DEFAULT
|
||||
).toShort(),
|
||||
autoOff = false,
|
||||
AlertTrigger.TimerTrigger(
|
||||
TimeUnit.HOURS.toMinutes(POD_EXPIRATION_ALERT_HOURS).toShort()
|
||||
), // FIXME use activation time
|
||||
expirationAlarmDelay.toMinutes().toShort()
|
||||
),
|
||||
BeepType.FOUR_TIMES_BIP_BEEP,
|
||||
BeepRepetitionType.XXX3
|
||||
),
|
||||
AlertConfiguration(
|
||||
AlertType.EXPIRATION_IMMINENT,
|
||||
enabled = true,
|
||||
enabled = expirationAlarmEnabled,
|
||||
durationInMinutes = 0,
|
||||
autoOff = false,
|
||||
AlertTrigger.TimerTrigger(
|
||||
TimeUnit.HOURS.toMinutes(POD_EXPIRATION_IMMINENT_ALERT_HOURS).toShort()
|
||||
), // FIXME use activation time
|
||||
expirationImminnentDelay.toMinutes().toShort()
|
||||
),
|
||||
BeepType.FOUR_TIMES_BIP_BEEP,
|
||||
BeepRepetitionType.XXX4
|
||||
)
|
||||
)
|
||||
val userExpiryAlertDelay = podLifeLeft.minus(
|
||||
Duration.ofHours(userConfiguredExpirationHours ?: MAX_POD_LIFETIME.toHours() + 1)
|
||||
Duration.ofHours(userConfiguredExpirationReminderHours ?: MAX_POD_LIFETIME.toHours() + 1)
|
||||
)
|
||||
if (userExpiryAlertDelay.isNegative) {
|
||||
logger.warn(
|
||||
|
@ -693,16 +702,16 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
logger.debug(LTag.PUMP, "Intercepted PodEvent in OmnipodDashManagerImpl: ${event.javaClass.simpleName}")
|
||||
|
||||
when (event) {
|
||||
is PodEvent.AlreadyConnected -> {
|
||||
is PodEvent.AlreadyConnected -> {
|
||||
}
|
||||
|
||||
is PodEvent.BluetoothConnected -> {
|
||||
is PodEvent.BluetoothConnected -> {
|
||||
}
|
||||
|
||||
is PodEvent.Connected -> {
|
||||
is PodEvent.Connected -> {
|
||||
}
|
||||
|
||||
is PodEvent.CommandSent -> {
|
||||
is PodEvent.CommandSent -> {
|
||||
logger.debug(LTag.PUMP, "Command sent: ${event.command.commandType}")
|
||||
podStateManager.activeCommand?.let {
|
||||
if (it.sequence == event.command.sequenceNumber) {
|
||||
|
@ -721,16 +730,16 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
podStateManager.increaseMessageSequenceNumber()
|
||||
}
|
||||
|
||||
is PodEvent.ResponseReceived -> {
|
||||
is PodEvent.ResponseReceived -> {
|
||||
podStateManager.increaseMessageSequenceNumber()
|
||||
handleResponse(event.response)
|
||||
}
|
||||
|
||||
is PodEvent.Paired -> {
|
||||
is PodEvent.Paired -> {
|
||||
podStateManager.uniqueId = event.uniqueId.toLong()
|
||||
}
|
||||
|
||||
else -> {
|
||||
else -> {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
@ -738,11 +747,11 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
|
||||
private fun handleResponse(response: Response) {
|
||||
when (response) {
|
||||
is VersionResponse -> {
|
||||
is VersionResponse -> {
|
||||
podStateManager.updateFromVersionResponse(response)
|
||||
}
|
||||
|
||||
is SetUniqueIdResponse -> {
|
||||
is SetUniqueIdResponse -> {
|
||||
podStateManager.updateFromSetUniqueIdResponse(response)
|
||||
}
|
||||
|
||||
|
@ -750,7 +759,7 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
podStateManager.updateFromDefaultStatusResponse(response)
|
||||
}
|
||||
|
||||
is AlarmStatusResponse -> {
|
||||
is AlarmStatusResponse -> {
|
||||
podStateManager.updateFromAlarmStatusResponse(response)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,11 @@ class PodConstants {
|
|||
companion object {
|
||||
val MAX_POD_LIFETIME: Duration = Duration.ofHours(80)
|
||||
|
||||
// Expiration alert time in minutes since activation and duration in minutes
|
||||
const val POD_EXPIRATION_ALERT_HOURS = 72L
|
||||
const val POD_EXPIRATION_ALERT_HOURS_DURATION = 7L
|
||||
// Expiration alert time in hours before lifetime end
|
||||
const val POD_EXPIRATION_ALERT_HOURS_REMAINING_DEFAULT = 7L
|
||||
|
||||
// Expiration eminent alert time in minutes since activation
|
||||
const val POD_EXPIRATION_IMMINENT_ALERT_HOURS = 79L
|
||||
// Imminent expiration alert time in hours before lifetime end
|
||||
const val POD_EXPIRATION_IMMINENT_ALERT_HOURS_REMAINING = 1L
|
||||
|
||||
// Bolus & Priming units
|
||||
const val POD_PULSE_BOLUS_UNITS = 0.05
|
||||
|
|
|
@ -112,8 +112,20 @@ interface OmnipodDashPodStateManager {
|
|||
- after getPodStatus was successful(we have an up-to-date podStatus)
|
||||
*/
|
||||
fun recoverActivationFromPodStatus(): String?
|
||||
fun sameAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int, lowReservoirAlertEnabled: Boolean, lowReservoirAlertUnits: Int): Boolean
|
||||
fun updateExpirationAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int): Completable
|
||||
fun sameAlertSettings(
|
||||
expirationReminderEnabled: Boolean,
|
||||
expirationReminderHours: Int,
|
||||
expirationAlarmEnabled: Boolean,
|
||||
expirationAlarmHours: Int,
|
||||
lowReservoirAlertEnabled: Boolean,
|
||||
lowReservoirAlertUnits: Int
|
||||
): Boolean
|
||||
fun updateExpirationAlertSettings(
|
||||
expirationReminderEnabled: Boolean,
|
||||
expirationReminderHours: Int,
|
||||
expirationAlarmEnabled: Boolean,
|
||||
expirationAlarmHours: Int
|
||||
): Completable
|
||||
fun updateLowReservoirAlertSettings(lowReservoirAlertEnabled: Boolean, lowReservoirAlertUnits: Int): Completable
|
||||
|
||||
data class ActiveCommand(
|
||||
|
|
|
@ -415,19 +415,25 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
|
||||
override fun recoverActivationFromPodStatus(): String? {
|
||||
val newActivationProgress = when (podState.podStatus) {
|
||||
PodStatus.FILLED ->
|
||||
PodStatus.FILLED ->
|
||||
ActivationProgress.NOT_STARTED
|
||||
PodStatus.UID_SET ->
|
||||
|
||||
PodStatus.UID_SET ->
|
||||
ActivationProgress.SET_UNIQUE_ID
|
||||
PodStatus.ENGAGING_CLUTCH_DRIVE, PodStatus.PRIMING ->
|
||||
|
||||
PodStatus.ENGAGING_CLUTCH_DRIVE, PodStatus.PRIMING ->
|
||||
return "Busy"
|
||||
PodStatus.CLUTCH_DRIVE_ENGAGED ->
|
||||
|
||||
PodStatus.CLUTCH_DRIVE_ENGAGED ->
|
||||
ActivationProgress.PRIME_COMPLETED
|
||||
PodStatus.BASAL_PROGRAM_SET ->
|
||||
|
||||
PodStatus.BASAL_PROGRAM_SET ->
|
||||
ActivationProgress.PROGRAMMED_BASAL
|
||||
|
||||
PodStatus.RUNNING_ABOVE_MIN_VOLUME, PodStatus.RUNNING_BELOW_MIN_VOLUME ->
|
||||
ActivationProgress.CANNULA_INSERTED
|
||||
else ->
|
||||
|
||||
else ->
|
||||
null
|
||||
}
|
||||
newActivationProgress?.let {
|
||||
|
@ -447,7 +453,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
val cmdConfirmation = getCommandConfirmationFromState()
|
||||
logger.info(LTag.PUMPCOMM, "Update active command with confirmation: $cmdConfirmation")
|
||||
when (cmdConfirmation) {
|
||||
CommandSendingFailure -> {
|
||||
CommandSendingFailure -> {
|
||||
podState.activeCommand = null
|
||||
source.onError(
|
||||
activeCommand.sendError
|
||||
|
@ -463,7 +469,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
source.onComplete()
|
||||
}
|
||||
|
||||
CommandConfirmationDenied -> {
|
||||
CommandConfirmationDenied -> {
|
||||
podState.activeCommand = null
|
||||
source.onSuccess(CommandConfirmed(activeCommand, false))
|
||||
}
|
||||
|
@ -474,7 +480,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
source.onSuccess(CommandConfirmed(activeCommand, true))
|
||||
}
|
||||
|
||||
NoActiveCommand -> {
|
||||
NoActiveCommand -> {
|
||||
source.onComplete()
|
||||
}
|
||||
}
|
||||
|
@ -482,20 +488,30 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
|
||||
override fun sameAlertSettings(
|
||||
expirationReminderEnabled: Boolean,
|
||||
expirationHours: Int,
|
||||
expirationReminderHours: Int,
|
||||
expirationAlarmEnabled: Boolean,
|
||||
expirationAlarmHours: Int,
|
||||
lowReservoirAlertEnabled: Boolean,
|
||||
lowReservoirAlertUnits: Int
|
||||
): Boolean {
|
||||
return podState.expirationReminderEnabled == expirationReminderEnabled &&
|
||||
podState.expirationHours == expirationHours &&
|
||||
podState.expirationReminderHours == expirationReminderHours &&
|
||||
podState.expirationAlarmEnabled == expirationAlarmEnabled &&
|
||||
podState.expirationAlarmHours == expirationAlarmHours &&
|
||||
podState.lowReservoirAlertEnabled == lowReservoirAlertEnabled &&
|
||||
podState.lowReservoirAlertUnits == lowReservoirAlertUnits
|
||||
}
|
||||
|
||||
override fun updateExpirationAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int):
|
||||
Completable = Completable.defer {
|
||||
override fun updateExpirationAlertSettings(
|
||||
expirationReminderEnabled: Boolean,
|
||||
expirationReminderHours: Int,
|
||||
expirationAlarmEnabled: Boolean,
|
||||
expirationAlarmHours: Int
|
||||
): Completable = Completable.defer {
|
||||
podState.expirationReminderEnabled = expirationReminderEnabled
|
||||
podState.expirationHours = expirationHours
|
||||
podState.expirationReminderHours = expirationReminderHours
|
||||
podState.expirationAlarmEnabled = expirationAlarmEnabled
|
||||
podState.expirationAlarmHours = expirationAlarmHours
|
||||
Completable.complete()
|
||||
}
|
||||
|
||||
|
@ -520,15 +536,18 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
createdRealtime <= podState.lastStatusResponseReceived &&
|
||||
sequence == podState.sequenceNumberOfLastProgrammingCommand ->
|
||||
CommandConfirmationSuccess
|
||||
|
||||
createdRealtime <= podState.lastStatusResponseReceived &&
|
||||
sequence != podState.sequenceNumberOfLastProgrammingCommand ->
|
||||
CommandConfirmationDenied
|
||||
// no response received after this point
|
||||
createdRealtime <= sentRealtime ->
|
||||
createdRealtime <= sentRealtime ->
|
||||
CommandSendingNotConfirmed
|
||||
createdRealtime > sentRealtime ->
|
||||
|
||||
createdRealtime > sentRealtime ->
|
||||
CommandSendingFailure
|
||||
else -> // this can't happen, see the previous two conditions
|
||||
|
||||
else -> // this can't happen, see the previous two conditions
|
||||
NoActiveCommand
|
||||
}
|
||||
} ?: NoActiveCommand
|
||||
|
@ -555,7 +574,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
podState.activeCommand = newCommand
|
||||
}
|
||||
|
||||
CommandSendingNotConfirmed -> {
|
||||
CommandSendingNotConfirmed -> {
|
||||
val now = SystemClock.elapsedRealtime()
|
||||
val newCommand = podState.activeCommand?.copy(
|
||||
createdRealtime = now,
|
||||
|
@ -565,7 +584,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
podState.lastStatusResponseReceived = 0
|
||||
}
|
||||
|
||||
CommandSendingFailure, NoActiveCommand -> {
|
||||
CommandSendingFailure, NoActiveCommand -> {
|
||||
podState.activeCommand = null
|
||||
podState.lastStatusResponseReceived = 0
|
||||
}
|
||||
|
@ -745,7 +764,9 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
var secondPrimeBolusVolume: Short? = null,
|
||||
|
||||
var expirationReminderEnabled: Boolean? = null,
|
||||
var expirationHours: Int? = null,
|
||||
var expirationReminderHours: Int? = null,
|
||||
var expirationAlarmEnabled: Boolean? = null,
|
||||
var expirationAlarmHours: Int? = null,
|
||||
var lowReservoirAlertEnabled: Boolean? = null,
|
||||
var lowReservoirAlertUnits: Int? = null,
|
||||
|
||||
|
|
|
@ -67,16 +67,24 @@ class DashInsertCannulaViewModel @Inject constructor(
|
|||
basalProgram
|
||||
)
|
||||
val expirationReminderEnabled = sp.getBoolean(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_expiration_reminder_enabled, true)
|
||||
val expirationHours = sp.getInt(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown, 9)
|
||||
val expirationReminderHours = sp.getInt(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown, 9)
|
||||
|
||||
val expirationHoursBeforeShutdown = if (expirationReminderEnabled)
|
||||
expirationHours.toLong()
|
||||
val expirationReminderHoursBeforeShutdown = if (expirationReminderEnabled)
|
||||
expirationReminderHours.toLong()
|
||||
else
|
||||
null
|
||||
|
||||
super.disposable += omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown)
|
||||
val expirationAlarmEnabled = sp.getBoolean(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_expiration_alarm_enabled, true)
|
||||
val expirationAlarmHours = sp.getInt(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.key_omnipod_common_expiration_alarm_hours_before_shutdown, 8)
|
||||
|
||||
val expirationAlarmHoursBeforeShutdown = if (expirationAlarmEnabled)
|
||||
expirationAlarmHours.toLong()
|
||||
else
|
||||
null
|
||||
|
||||
super.disposable += omnipodManager.activatePodPart2(basalProgram, expirationReminderHoursBeforeShutdown, expirationAlarmHoursBeforeShutdown)
|
||||
.ignoreElements()
|
||||
.andThen(podStateManager.updateExpirationAlertSettings(expirationReminderEnabled, expirationHours))
|
||||
.andThen(podStateManager.updateExpirationAlertSettings(expirationReminderEnabled, expirationReminderHours, expirationAlarmEnabled, expirationAlarmHours))
|
||||
.andThen(
|
||||
history.createRecord(
|
||||
OmnipodCommandType.INSERT_CANNULA,
|
||||
|
|
|
@ -50,6 +50,22 @@
|
|||
validate:minNumber="2"
|
||||
validate:testType="numericRange" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="@string/key_omnipod_common_expiration_alarm_enabled"
|
||||
android:title="@string/omnipod_common_preferences_expiration_alarm_enabled" />
|
||||
|
||||
<info.nightscout.core.validators.ValidatingEditTextPreference
|
||||
android:defaultValue="8"
|
||||
android:dependency="@string/key_omnipod_common_expiration_alarm_enabled"
|
||||
android:digits="0123456789"
|
||||
android:inputType="number"
|
||||
android:key="@string/key_omnipod_common_expiration_alarm_hours_before_shutdown"
|
||||
android:title="@string/omnipod_common_preferences_expiration_alarm_hours_before_shutdown"
|
||||
validate:maxNumber="24"
|
||||
validate:minNumber="1"
|
||||
validate:testType="numericRange" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="@string/key_omnipod_common_low_reservoir_alert_enabled"
|
||||
|
|
Loading…
Reference in a new issue