update alerts
This commit is contained in:
parent
21b78562e2
commit
b845c06fca
|
@ -7,6 +7,7 @@ import dagger.android.HasAndroidInjector
|
|||
import info.nightscout.androidaps.activities.ErrorHelperActivity.Companion.runAlarm
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo
|
||||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange
|
||||
import info.nightscout.androidaps.events.EventProfileSwitchChanged
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
|
@ -25,10 +26,7 @@ import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.*
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ActivationProgress
|
||||
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.*
|
||||
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
|
||||
|
@ -40,13 +38,19 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.OmnipodDashOvervi
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram
|
||||
import info.nightscout.androidaps.queue.commands.Command
|
||||
import info.nightscout.androidaps.queue.commands.CustomCommand
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.TimeChangeType
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import org.json.JSONObject
|
||||
import java.time.Duration
|
||||
import java.time.ZonedDateTime
|
||||
import java.util.*
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import javax.inject.Inject
|
||||
|
@ -65,6 +69,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
private val pumpSync: PumpSync,
|
||||
private val rxBus: RxBusWrapper,
|
||||
private val context: Context,
|
||||
private val aapsSchedulers: AapsSchedulers,
|
||||
private val fabricPrivacy: FabricPrivacy,
|
||||
|
||||
injector: HasAndroidInjector,
|
||||
aapsLogger: AAPSLogger,
|
||||
|
@ -76,6 +82,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
private lateinit var statusChecker: Runnable
|
||||
var nextPodWarningCheck: Long = 0
|
||||
@Volatile var stopConnecting: CountDownLatch? = null
|
||||
private var disposables: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
companion object {
|
||||
private const val BOLUS_RETRY_INTERVAL_MS = 2000.toLong()
|
||||
|
@ -391,10 +398,25 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
super.onStart()
|
||||
podStateManager.onStart()
|
||||
handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS)
|
||||
disposables += rxBus
|
||||
.toObservable(EventPreferenceChange::class.java)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe(
|
||||
{
|
||||
if (it.isChanged(resourceHelper,
|
||||
R.string.key_omnipod_common_expiration_reminder_enabled) ||
|
||||
it.isChanged(resourceHelper,
|
||||
R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown)) {
|
||||
commandQueue.customCommand(CommandUpdateAlertConfiguration(), null)
|
||||
}
|
||||
},
|
||||
fabricPrivacy::logException
|
||||
)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
disposables.clear()
|
||||
handler.removeCallbacks(statusChecker)
|
||||
}
|
||||
|
||||
|
@ -451,7 +473,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
|
||||
try {
|
||||
aapsLogger.info(LTag.PUMP, "Delivering treatment: $detailedBolusInfo")
|
||||
aapsLogger.info(LTag.PUMP, "Delivering treatment: $detailedBolusInfo $bolusCanceled")
|
||||
val beepsConfigurationKey = if (detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB)
|
||||
R.string.key_omnipod_common_smb_beeps_enabled
|
||||
else
|
||||
|
@ -1020,8 +1042,62 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
private fun updateAlertConfiguration(): PumpEnactResult {
|
||||
// TODO
|
||||
return PumpEnactResult(injector).success(false).enacted(false).comment("NOT IMPLEMENTED")
|
||||
|
||||
val expirationReminderEnabled = sp.getBoolean(R.string.key_omnipod_common_expiration_reminder_enabled, true)
|
||||
val expirationHours = sp.getInt(R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown, 7)
|
||||
val lowReservoirAlertEnabled = sp.getBoolean(R.string.key_omnipod_common_low_reservoir_alert_enabled, true)
|
||||
val lowReservoirAlertUnits = sp.getInt(R.string.key_omnipod_common_low_reservoir_alert_units ,10)
|
||||
|
||||
if (!podStateManager.differentAlertSettings(
|
||||
expirationReminderEnabled,
|
||||
expirationHours,
|
||||
lowReservoirAlertEnabled,
|
||||
lowReservoirAlertUnits
|
||||
)) {
|
||||
return PumpEnactResult(injector).success(true).enacted(false)
|
||||
}
|
||||
|
||||
val podLifeLeft = Duration.between(ZonedDateTime.now(), podStateManager.expiry)
|
||||
val expiryAlertDelay = podLifeLeft.minus(Duration.ofHours(expirationHours.toLong()))
|
||||
if (expiryAlertDelay.isNegative) {
|
||||
aapsLogger.warn(LTag.PUMPBTCOMM, "updateAlertConfiguration negative " +
|
||||
"expiryAlertDuration=$expiryAlertDelay")
|
||||
PumpEnactResult(injector).success(false).enacted(false)
|
||||
}
|
||||
val alerts = listOf (
|
||||
AlertConfiguration(
|
||||
AlertType.LOW_RESERVOIR,
|
||||
enabled = lowReservoirAlertEnabled,
|
||||
durationInMinutes = 0,
|
||||
autoOff = false,
|
||||
AlertTrigger.ReservoirVolumeTrigger((lowReservoirAlertUnits * 10).toShort()),
|
||||
BeepType.FOUR_TIMES_BIP_BEEP,
|
||||
BeepRepetitionType.XXX
|
||||
),
|
||||
AlertConfiguration(
|
||||
AlertType.USER_SET_EXPIRATION,
|
||||
enabled = expirationReminderEnabled,
|
||||
durationInMinutes = 0,
|
||||
autoOff = false,
|
||||
AlertTrigger.TimerTrigger(
|
||||
expiryAlertDelay.toMinutes().toShort()
|
||||
),
|
||||
BeepType.FOUR_TIMES_BIP_BEEP,
|
||||
BeepRepetitionType.XXX2
|
||||
)
|
||||
)
|
||||
return executeProgrammingCommand(
|
||||
historyEntry = history.createRecord(OmnipodCommandType.CONFIGURE_ALERTS),
|
||||
command = omnipodManager.programAlerts(alerts).ignoreElements(),
|
||||
post = podStateManager.updateExpirationAlertSettings(
|
||||
expirationReminderEnabled,
|
||||
expirationHours).andThen(
|
||||
podStateManager.updateExpirationAlertSettings(
|
||||
lowReservoirAlertEnabled,
|
||||
lowReservoirAlertUnits
|
||||
)
|
||||
)
|
||||
).toPumpEnactResult()
|
||||
}
|
||||
|
||||
private fun playTestBeep(): PumpEnactResult {
|
||||
|
|
|
@ -15,7 +15,7 @@ interface OmnipodDashManager {
|
|||
|
||||
fun activatePodPart1(lowReservoirAlertTrigger: AlertTrigger.ReservoirVolumeTrigger?): Observable<PodEvent>
|
||||
|
||||
fun activatePodPart2(basalProgram: BasalProgram): Observable<PodEvent>
|
||||
fun activatePodPart2(basalProgram: BasalProgram, userConfiguredExpirationHours: Long?): Observable<PodEvent>
|
||||
|
||||
fun getStatus(type: ResponseType.StatusResponseType): Observable<PodEvent>
|
||||
|
||||
|
|
|
@ -8,12 +8,15 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.event.PodEven
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.*
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.GetVersionCommand.Companion.DEFAULT_UNIQUE_ID
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.*
|
||||
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.response.*
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.functions.Action
|
||||
import io.reactivex.functions.Consumer
|
||||
import java.time.Duration
|
||||
import java.time.ZonedDateTime
|
||||
import java.util.*
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
@ -340,11 +343,12 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
return observables.reversed()
|
||||
}
|
||||
|
||||
override fun activatePodPart2(basalProgram: BasalProgram): Observable<PodEvent> {
|
||||
override fun activatePodPart2(basalProgram: BasalProgram, userConfiguredExpirationHours:Long?):
|
||||
Observable<PodEvent> {
|
||||
return Observable.concat(
|
||||
observePodReadyForActivationPart2,
|
||||
observeConnectToPod,
|
||||
observeActivationPart2Commands(basalProgram)
|
||||
observeActivationPart2Commands(basalProgram, userConfiguredExpirationHours)
|
||||
).doOnComplete(ActivationProgressUpdater(ActivationProgress.COMPLETED))
|
||||
// TODO these would be common for any observable returned in a public function in this class
|
||||
.doOnNext(PodEventInterceptor())
|
||||
|
@ -352,8 +356,9 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
.subscribeOn(aapsSchedulers.io)
|
||||
}
|
||||
|
||||
private fun observeActivationPart2Commands(basalProgram: BasalProgram): Observable<PodEvent> {
|
||||
val observables = createActivationPart2Observables(basalProgram)
|
||||
private fun observeActivationPart2Commands(basalProgram: BasalProgram, userConfiguredExpirationHours: Long?):
|
||||
Observable<PodEvent> {
|
||||
val observables = createActivationPart2Observables(basalProgram, userConfiguredExpirationHours)
|
||||
|
||||
return if (observables.isEmpty()) {
|
||||
Observable.empty()
|
||||
|
@ -362,7 +367,9 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun createActivationPart2Observables(basalProgram: BasalProgram): List<Observable<PodEvent>> {
|
||||
private fun createActivationPart2Observables(basalProgram: BasalProgram,
|
||||
userConfiguredExpirationHours: Long?):
|
||||
List<Observable<PodEvent>> {
|
||||
val observables = ArrayList<Observable<PodEvent>>()
|
||||
|
||||
if (podStateManager.activationProgress.isBefore(ActivationProgress.CANNULA_INSERTED)) {
|
||||
|
@ -388,17 +395,17 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
)
|
||||
}
|
||||
if (podStateManager.activationProgress.isBefore(ActivationProgress.UPDATED_EXPIRATION_ALERTS)) {
|
||||
observables.add(
|
||||
observeSendProgramAlertsCommand(
|
||||
listOf(
|
||||
// FIXME use user configured expiration alert
|
||||
val podLifeLeft = Duration.between(ZonedDateTime.now(), podStateManager.expiry)
|
||||
|
||||
|
||||
val alerts = mutableListOf(
|
||||
AlertConfiguration(
|
||||
AlertType.EXPIRATION,
|
||||
enabled = true,
|
||||
durationInMinutes = TimeUnit.HOURS.toMinutes(7).toShort(),
|
||||
autoOff = false,
|
||||
AlertTrigger.TimerTrigger(
|
||||
TimeUnit.HOURS.toMinutes(73).toShort()
|
||||
TimeUnit.HOURS.toMinutes(72).toShort()
|
||||
), // FIXME use activation time
|
||||
BeepType.FOUR_TIMES_BIP_BEEP,
|
||||
BeepRepetitionType.XXX3
|
||||
|
@ -406,7 +413,7 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
AlertConfiguration(
|
||||
AlertType.EXPIRATION_IMMINENT,
|
||||
enabled = true,
|
||||
durationInMinutes = TimeUnit.HOURS.toMinutes(1).toShort(),
|
||||
durationInMinutes = 0,
|
||||
autoOff = false,
|
||||
AlertTrigger.TimerTrigger(
|
||||
TimeUnit.HOURS.toMinutes(79).toShort()
|
||||
|
@ -414,7 +421,29 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
BeepType.FOUR_TIMES_BIP_BEEP,
|
||||
BeepRepetitionType.XXX4
|
||||
)
|
||||
)
|
||||
val userExpiryAlertDelay = podLifeLeft.minus(
|
||||
Duration.ofHours(userConfiguredExpirationHours ?: MAX_POD_LIFETIME.toHours() + 1))
|
||||
if (userExpiryAlertDelay.isNegative) {
|
||||
logger.warn(LTag.PUMPBTCOMM, "createActivationPart2Observables negative " +
|
||||
"expiryAlertDuration=$userExpiryAlertDelay")
|
||||
} else {
|
||||
alerts.add( AlertConfiguration(
|
||||
AlertType.USER_SET_EXPIRATION,
|
||||
enabled = true,
|
||||
durationInMinutes = 0,
|
||||
autoOff = false,
|
||||
AlertTrigger.TimerTrigger(
|
||||
userExpiryAlertDelay.toMinutes().toShort()
|
||||
),
|
||||
BeepType.FOUR_TIMES_BIP_BEEP,
|
||||
BeepRepetitionType.XXX2
|
||||
))
|
||||
}
|
||||
|
||||
observables.add(
|
||||
observeSendProgramAlertsCommand(
|
||||
alerts,
|
||||
multiCommandFlag = true
|
||||
).doOnComplete(ActivationProgressUpdater(ActivationProgress.UPDATED_EXPIRATION_ALERTS))
|
||||
)
|
||||
|
|
|
@ -5,8 +5,8 @@ enum class BeepRepetitionType(
|
|||
val value: Byte
|
||||
) {
|
||||
|
||||
XXX(0x01.toByte()), // Used in lump of coal alert
|
||||
XXX2(0x03.toByte()), // Used in low reservoir alert
|
||||
XXX(0x01.toByte()), // Used in lump of coal alert, LOW_RESERVOIR
|
||||
XXX2(0x03.toByte()), // Used in USER_SET_EXPIRATION
|
||||
XXX3(0x05.toByte()), // Used in user pod expiration alert
|
||||
XXX4(0x06.toByte()), // Used in pod expiration alert
|
||||
XXX5(0x08.toByte()); // Used in imminent pod expiration alert
|
||||
|
|
|
@ -101,6 +101,9 @@ interface OmnipodDashPodStateManager {
|
|||
- after getPodStatus was successful(we have an up-to-date podStatus)
|
||||
*/
|
||||
fun recoverActivationFromPodStatus(): String?
|
||||
fun differentAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int, lowReservoirAlertEnabled: Boolean, lowReservoirAlertUnits: Int): Boolean
|
||||
fun updateExpirationAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int) : Completable
|
||||
fun updateLowReservoirAlertSettings(lowReservoirAlertEnabled: Boolean, lowReservoirAlertUnits: Int): Completable
|
||||
|
||||
data class ActiveCommand(
|
||||
val sequence: Short,
|
||||
|
|
|
@ -205,7 +205,6 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
}
|
||||
|
||||
override val expiry: ZonedDateTime?
|
||||
// TODO: Consider storing expiry datetime in pod state saving continuously recalculating to the same value
|
||||
get() {
|
||||
val podLifeInHours = podLifeInHours
|
||||
val minutesSinceActivation = podState.minutesSinceActivation
|
||||
|
@ -398,6 +397,32 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun differentAlertSettings(
|
||||
expirationReminderEnabled: Boolean,
|
||||
expirationHours: Int,
|
||||
lowReservoirAlertEnabled: Boolean,
|
||||
lowReservoirAlertUnits: Int
|
||||
): Boolean {
|
||||
return podState.expirationReminderEnabled == expirationReminderEnabled &&
|
||||
podState.expirationHours == expirationHours &&
|
||||
podState.lowReservoirAlertEnabled == lowReservoirAlertEnabled &&
|
||||
podState.lowReservoirAlertUnits == lowReservoirAlertUnits
|
||||
}
|
||||
|
||||
override fun updateExpirationAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int) :
|
||||
Completable = Completable.defer{
|
||||
podState.expirationReminderEnabled = expirationReminderEnabled
|
||||
podState.expirationHours = expirationHours
|
||||
Completable.complete()
|
||||
}
|
||||
|
||||
override fun updateLowReservoirAlertSettings(lowReservoirAlertEnabled: Boolean, lowReservoirAlertUnits: Int):
|
||||
Completable = Completable.defer {
|
||||
podState.lowReservoirAlertEnabled = lowReservoirAlertEnabled
|
||||
podState.lowReservoirAlertUnits = lowReservoirAlertUnits
|
||||
Completable.complete()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun getCommandConfirmationFromState(): CommandConfirmationFromState {
|
||||
return podState.activeCommand?.run {
|
||||
|
@ -618,6 +643,11 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
var firstPrimeBolusVolume: Short? = null
|
||||
var secondPrimeBolusVolume: Short? = null
|
||||
|
||||
var expirationReminderEnabled: Boolean? = null
|
||||
var expirationHours: Int? = null
|
||||
var lowReservoirAlertEnabled: Boolean? = null
|
||||
var lowReservoirAlertUnits: Int? = null
|
||||
|
||||
var pulsesDelivered: Short? = null
|
||||
var pulsesRemaining: Short? = null
|
||||
var podStatus: PodStatus? = null
|
||||
|
|
|
@ -9,6 +9,8 @@ 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.driver.OmnipodDashManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertTrigger
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.rxkotlin.subscribeBy
|
||||
import javax.inject.Inject
|
||||
|
@ -16,9 +18,10 @@ import javax.inject.Inject
|
|||
class DashInitializePodViewModel @Inject constructor(
|
||||
private val omnipodManager: OmnipodDashManager,
|
||||
injector: HasAndroidInjector,
|
||||
logger: AAPSLogger
|
||||
logger: AAPSLogger,
|
||||
private val sp: SP,
|
||||
private val podStateManager: OmnipodDashPodStateManager,
|
||||
) : InitializePodViewModel(injector, logger) {
|
||||
|
||||
override fun isPodInAlarm(): Boolean = false // TODO
|
||||
|
||||
override fun isPodActivationTimeExceeded(): Boolean = false // TODO
|
||||
|
@ -28,7 +31,14 @@ class DashInitializePodViewModel @Inject constructor(
|
|||
override fun doExecuteAction(): Single<PumpEnactResult> =
|
||||
Single.create { source ->
|
||||
// TODO use configured value for low reservoir trigger
|
||||
val disposable = omnipodManager.activatePodPart1(AlertTrigger.ReservoirVolumeTrigger(200)).subscribeBy(
|
||||
val lowReservoirAlertEnabled = sp.getBoolean(R.string.key_omnipod_common_low_reservoir_alert_enabled, true)
|
||||
val lowReservoirAlertUnits = sp.getInt(R.string.key_omnipod_common_low_reservoir_alert_units ,10)
|
||||
val lowReservoirAlertTrigger = if (lowReservoirAlertEnabled) {
|
||||
AlertTrigger.ReservoirVolumeTrigger((lowReservoirAlertUnits * 10).toShort())
|
||||
} else
|
||||
null
|
||||
|
||||
val disposable = omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy(
|
||||
onNext = { podEvent ->
|
||||
logger.debug(
|
||||
LTag.PUMP,
|
||||
|
@ -41,6 +51,7 @@ class DashInitializePodViewModel @Inject constructor(
|
|||
},
|
||||
onComplete = {
|
||||
logger.debug("Pod activation part 1 completed")
|
||||
podStateManager.updateLowReservoirAlertSettings(lowReservoirAlertEnabled, lowReservoirAlertUnits)
|
||||
source.onSuccess(PumpEnactResult(injector).success(true))
|
||||
}
|
||||
)
|
||||
|
|
|
@ -15,8 +15,10 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.action.InsertCannulaViewModel
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.R
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertTrigger
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.rxkotlin.subscribeBy
|
||||
import javax.inject.Inject
|
||||
|
@ -27,6 +29,7 @@ class DashInsertCannulaViewModel @Inject constructor(
|
|||
private val pumpSync: PumpSync,
|
||||
private val podStateManager: OmnipodDashPodStateManager,
|
||||
private val rxBus: RxBusWrapper,
|
||||
private val sp: SP,
|
||||
|
||||
injector: HasAndroidInjector,
|
||||
logger: AAPSLogger
|
||||
|
@ -50,7 +53,15 @@ class DashInsertCannulaViewModel @Inject constructor(
|
|||
profile,
|
||||
basalProgram
|
||||
)
|
||||
val disposable = omnipodManager.activatePodPart2(basalProgram).subscribeBy(
|
||||
val expirationReminderEnabled = sp.getBoolean(R.string.key_omnipod_common_expiration_reminder_enabled, true)
|
||||
val expirationHours = sp.getInt(R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown, 9)
|
||||
|
||||
val expirationHoursBeforeShutdown = if (expirationReminderEnabled)
|
||||
expirationHours.toLong()
|
||||
else
|
||||
null
|
||||
|
||||
val disposable = omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy(
|
||||
onNext = { podEvent ->
|
||||
logger.debug(
|
||||
LTag.PUMP,
|
||||
|
@ -82,6 +93,7 @@ class DashInsertCannulaViewModel @Inject constructor(
|
|||
pumpType = PumpType.OMNIPOD_DASH,
|
||||
pumpSerial = podStateManager.uniqueId?.toString() ?: "n/a"
|
||||
)
|
||||
podStateManager.updateExpirationAlertSettings(expirationReminderEnabled, expirationHours)
|
||||
rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_NOT_ATTACHED))
|
||||
source.onSuccess(PumpEnactResult(injector).success(true))
|
||||
}
|
||||
|
|
|
@ -70,7 +70,6 @@
|
|||
android:defaultValue="false"
|
||||
android:key="@string/key_omnipod_common_automatically_silence_alerts_enabled"
|
||||
android:title="@string/omnipod_common_preferences_automatically_silence_alerts" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
|
|
Loading…
Reference in a new issue