format. remove duplication

This commit is contained in:
Andrei Vereha 2021-07-16 22:25:37 +02:00
parent 11fa4d842c
commit 32183aff37
8 changed files with 71 additions and 105 deletions

View file

@ -208,7 +208,6 @@ class OmnipodDashPumpPlugin @Inject constructor(
} }
override fun finishHandshaking() { override fun finishHandshaking() {
} }
override fun connect(reason: String) { override fun connect(reason: String) {
@ -400,10 +399,15 @@ class OmnipodDashPumpPlugin @Inject constructor(
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
.subscribe( .subscribe(
{ {
if (it.isChanged(resourceHelper, if (it.isChanged(
R.string.key_omnipod_common_expiration_reminder_enabled) || resourceHelper,
it.isChanged(resourceHelper, R.string.key_omnipod_common_expiration_reminder_enabled
R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown)) { ) ||
it.isChanged(
resourceHelper,
R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown
)
) {
commandQueue.customCommand(CommandUpdateAlertConfiguration(), null) commandQueue.customCommand(CommandUpdateAlertConfiguration(), null)
} }
}, },
@ -1050,15 +1054,19 @@ class OmnipodDashPumpPlugin @Inject constructor(
expirationHours, expirationHours,
lowReservoirAlertEnabled, lowReservoirAlertEnabled,
lowReservoirAlertUnits lowReservoirAlertUnits
)) { )
) {
return PumpEnactResult(injector).success(true).enacted(false) return PumpEnactResult(injector).success(true).enacted(false)
} }
val podLifeLeft = Duration.between(ZonedDateTime.now(), podStateManager.expiry) val podLifeLeft = Duration.between(ZonedDateTime.now(), podStateManager.expiry)
val expiryAlertDelay = podLifeLeft.minus(Duration.ofHours(expirationHours.toLong())) val expiryAlertDelay = podLifeLeft.minus(Duration.ofHours(expirationHours.toLong()))
if (expiryAlertDelay.isNegative) { if (expiryAlertDelay.isNegative) {
aapsLogger.warn(LTag.PUMPBTCOMM, "updateAlertConfiguration negative " + aapsLogger.warn(
"expiryAlertDuration=$expiryAlertDelay") LTag.PUMPBTCOMM,
"updateAlertConfiguration negative " +
"expiryAlertDuration=$expiryAlertDelay"
)
PumpEnactResult(injector).success(false).enacted(false) PumpEnactResult(injector).success(false).enacted(false)
} }
val alerts = listOf( val alerts = listOf(
@ -1088,7 +1096,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
command = omnipodManager.programAlerts(alerts).ignoreElements(), command = omnipodManager.programAlerts(alerts).ignoreElements(),
post = podStateManager.updateExpirationAlertSettings( post = podStateManager.updateExpirationAlertSettings(
expirationReminderEnabled, expirationReminderEnabled,
expirationHours).andThen( expirationHours
).andThen(
podStateManager.updateExpirationAlertSettings( podStateManager.updateExpirationAlertSettings(
lowReservoirAlertEnabled, lowReservoirAlertEnabled,
lowReservoirAlertUnits lowReservoirAlertUnits

View file

@ -84,10 +84,7 @@ class OmnipodDashManagerImpl @Inject constructor(
override fun connect(stop: CountDownLatch): Observable<PodEvent> { override fun connect(stop: CountDownLatch): Observable<PodEvent> {
return observeConnectToPodWithStop(stop) return observeConnectToPodWithStop(stop)
// TODO these would be common for any observable returned in a public function in this class .interceptPodEvents()
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
} }
private fun observeConnectToPodWithStop(stop: CountDownLatch): Observable<PodEvent> { private fun observeConnectToPodWithStop(stop: CountDownLatch): Observable<PodEvent> {
@ -244,10 +241,7 @@ class OmnipodDashManagerImpl @Inject constructor(
observeConnectToPod, observeConnectToPod,
observeActivationPart1Commands(lowReservoirAlertTrigger) observeActivationPart1Commands(lowReservoirAlertTrigger)
).doOnComplete(ActivationProgressUpdater(ActivationProgress.PHASE_1_COMPLETED)) ).doOnComplete(ActivationProgressUpdater(ActivationProgress.PHASE_1_COMPLETED))
// TODO these would be common for any observable returned in a public function in this class .interceptPodEvents()
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
} }
private fun observeActivationPart1Commands(lowReservoirAlertTrigger: AlertTrigger.ReservoirVolumeTrigger?): Observable<PodEvent> { private fun observeActivationPart1Commands(lowReservoirAlertTrigger: AlertTrigger.ReservoirVolumeTrigger?): Observable<PodEvent> {
@ -350,10 +344,7 @@ class OmnipodDashManagerImpl @Inject constructor(
observeConnectToPod, observeConnectToPod,
observeActivationPart2Commands(basalProgram, userConfiguredExpirationHours) observeActivationPart2Commands(basalProgram, userConfiguredExpirationHours)
).doOnComplete(ActivationProgressUpdater(ActivationProgress.COMPLETED)) ).doOnComplete(ActivationProgressUpdater(ActivationProgress.COMPLETED))
// TODO these would be common for any observable returned in a public function in this class .interceptPodEvents()
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
} }
private fun observeActivationPart2Commands(basalProgram: BasalProgram, userConfiguredExpirationHours: Long?): private fun observeActivationPart2Commands(basalProgram: BasalProgram, userConfiguredExpirationHours: Long?):
@ -367,8 +358,10 @@ class OmnipodDashManagerImpl @Inject constructor(
} }
} }
private fun createActivationPart2Observables(basalProgram: BasalProgram, private fun createActivationPart2Observables(
userConfiguredExpirationHours: Long?): basalProgram: BasalProgram,
userConfiguredExpirationHours: Long?
):
List<Observable<PodEvent>> { List<Observable<PodEvent>> {
val observables = ArrayList<Observable<PodEvent>>() val observables = ArrayList<Observable<PodEvent>>()
@ -397,7 +390,6 @@ class OmnipodDashManagerImpl @Inject constructor(
if (podStateManager.activationProgress.isBefore(ActivationProgress.UPDATED_EXPIRATION_ALERTS)) { if (podStateManager.activationProgress.isBefore(ActivationProgress.UPDATED_EXPIRATION_ALERTS)) {
val podLifeLeft = Duration.between(ZonedDateTime.now(), podStateManager.expiry) val podLifeLeft = Duration.between(ZonedDateTime.now(), podStateManager.expiry)
val alerts = mutableListOf( val alerts = mutableListOf(
AlertConfiguration( AlertConfiguration(
AlertType.EXPIRATION, AlertType.EXPIRATION,
@ -423,12 +415,17 @@ class OmnipodDashManagerImpl @Inject constructor(
) )
) )
val userExpiryAlertDelay = podLifeLeft.minus( val userExpiryAlertDelay = podLifeLeft.minus(
Duration.ofHours(userConfiguredExpirationHours ?: MAX_POD_LIFETIME.toHours() + 1)) Duration.ofHours(userConfiguredExpirationHours ?: MAX_POD_LIFETIME.toHours() + 1)
)
if (userExpiryAlertDelay.isNegative) { if (userExpiryAlertDelay.isNegative) {
logger.warn(LTag.PUMPBTCOMM, "createActivationPart2Observables negative " + logger.warn(
"expiryAlertDuration=$userExpiryAlertDelay") LTag.PUMPBTCOMM,
"createActivationPart2Observables negative " +
"expiryAlertDuration=$userExpiryAlertDelay"
)
} else { } else {
alerts.add( AlertConfiguration( alerts.add(
AlertConfiguration(
AlertType.USER_SET_EXPIRATION, AlertType.USER_SET_EXPIRATION,
enabled = true, enabled = true,
durationInMinutes = 0, durationInMinutes = 0,
@ -438,7 +435,8 @@ class OmnipodDashManagerImpl @Inject constructor(
), ),
BeepType.FOUR_TIMES_BIP_BEEP, BeepType.FOUR_TIMES_BIP_BEEP,
BeepRepetitionType.XXX2 BeepRepetitionType.XXX2
)) )
)
} }
observables.add( observables.add(
@ -463,11 +461,7 @@ class OmnipodDashManagerImpl @Inject constructor(
observeUniqueIdSet, observeUniqueIdSet,
observeConnectToPod, observeConnectToPod,
observeSendGetPodStatusCommand(type) observeSendGetPodStatusCommand(type)
) ).interceptPodEvents()
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
} }
override fun setBasalProgram(basalProgram: BasalProgram, hasBasalBeepEnabled: Boolean): Observable<PodEvent> { override fun setBasalProgram(basalProgram: BasalProgram, hasBasalBeepEnabled: Boolean): Observable<PodEvent> {
@ -475,11 +469,7 @@ class OmnipodDashManagerImpl @Inject constructor(
observePodRunning, observePodRunning,
observeConnectToPod, observeConnectToPod,
observeSendProgramBasalCommand(basalProgram, hasBasalBeepEnabled) observeSendProgramBasalCommand(basalProgram, hasBasalBeepEnabled)
) ).interceptPodEvents()
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
} }
private fun observeSendStopDeliveryCommand( private fun observeSendStopDeliveryCommand(
@ -510,11 +500,7 @@ class OmnipodDashManagerImpl @Inject constructor(
observePodRunning, observePodRunning,
observeConnectToPod, observeConnectToPod,
observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.ALL, hasBasalBeepEnabled) observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.ALL, hasBasalBeepEnabled)
) ).interceptPodEvents()
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
} }
override fun setTime(): Observable<PodEvent> { override fun setTime(): Observable<PodEvent> {
@ -544,11 +530,7 @@ class OmnipodDashManagerImpl @Inject constructor(
observePodRunning, observePodRunning,
observeConnectToPod, observeConnectToPod,
observeSendProgramTempBasalCommand(rate, durationInMinutes, tempBasalBeeps) observeSendProgramTempBasalCommand(rate, durationInMinutes, tempBasalBeeps)
) ).interceptPodEvents()
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
} }
override fun stopTempBasal(hasTempBasalBeepEnabled: Boolean): Observable<PodEvent> { override fun stopTempBasal(hasTempBasalBeepEnabled: Boolean): Observable<PodEvent> {
@ -556,11 +538,7 @@ class OmnipodDashManagerImpl @Inject constructor(
observePodRunning, observePodRunning,
observeConnectToPod, observeConnectToPod,
observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.TEMP_BASAL, hasTempBasalBeepEnabled) observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.TEMP_BASAL, hasTempBasalBeepEnabled)
) ).interceptPodEvents()
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
} }
override fun bolus(units: Double, confirmationBeeps: Boolean, completionBeeps: Boolean): Observable<PodEvent> { override fun bolus(units: Double, confirmationBeeps: Boolean, completionBeeps: Boolean): Observable<PodEvent> {
@ -573,11 +551,7 @@ class OmnipodDashManagerImpl @Inject constructor(
confirmationBeeps, confirmationBeeps,
completionBeeps completionBeeps
) )
) ).interceptPodEvents()
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
} }
override fun stopBolus(beep: Boolean): Observable<PodEvent> { override fun stopBolus(beep: Boolean): Observable<PodEvent> {
@ -585,11 +559,7 @@ class OmnipodDashManagerImpl @Inject constructor(
observePodRunning, observePodRunning,
observeConnectToPod, observeConnectToPod,
observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.BOLUS, beep) observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.BOLUS, beep)
) ).interceptPodEvents()
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
} }
private fun observeSendConfigureBeepsCommand( private fun observeSendConfigureBeepsCommand(
@ -618,11 +588,7 @@ class OmnipodDashManagerImpl @Inject constructor(
observePodRunning, observePodRunning,
observeConnectToPod, observeConnectToPod,
observeSendConfigureBeepsCommand(immediateBeepType = beepType) observeSendConfigureBeepsCommand(immediateBeepType = beepType)
) ).interceptPodEvents()
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
} }
override fun programAlerts(alertConfigurations: List<AlertConfiguration>): Observable<PodEvent> { override fun programAlerts(alertConfigurations: List<AlertConfiguration>): Observable<PodEvent> {
@ -630,11 +596,7 @@ class OmnipodDashManagerImpl @Inject constructor(
observePodRunning, observePodRunning,
observeConnectToPod, observeConnectToPod,
observeSendProgramAlertsCommand(alertConfigurations) observeSendProgramAlertsCommand(alertConfigurations)
) ).interceptPodEvents()
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
} }
private fun observeSendSilenceAlertsCommand(alertTypes: EnumSet<AlertType>): Observable<PodEvent> { private fun observeSendSilenceAlertsCommand(alertTypes: EnumSet<AlertType>): Observable<PodEvent> {
@ -656,11 +618,7 @@ class OmnipodDashManagerImpl @Inject constructor(
observePodRunning, observePodRunning,
observeConnectToPod, observeConnectToPod,
observeSendSilenceAlertsCommand(alertTypes) observeSendSilenceAlertsCommand(alertTypes)
) ).interceptPodEvents()
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
} }
private val observeSendDeactivateCommand: Observable<PodEvent> private val observeSendDeactivateCommand: Observable<PodEvent>
@ -679,11 +637,7 @@ class OmnipodDashManagerImpl @Inject constructor(
return Observable.concat( return Observable.concat(
observeConnectToPod, observeConnectToPod,
observeSendDeactivateCommand observeSendDeactivateCommand
) ).interceptPodEvents()
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
// //
.doOnComplete(podStateManager::reset) .doOnComplete(podStateManager::reset)
} }
@ -760,6 +714,12 @@ class OmnipodDashManagerImpl @Inject constructor(
} }
} }
private fun Observable<PodEvent>.interceptPodEvents(): Observable<PodEvent> {
return this.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
}
inner class ErrorInterceptor : Consumer<Throwable> { inner class ErrorInterceptor : Consumer<Throwable> {
override fun accept(throwable: Throwable) { override fun accept(throwable: Throwable) {

View file

@ -2,9 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io
import android.bluetooth.BluetoothGatt import android.bluetooth.BluetoothGatt
import android.bluetooth.BluetoothGattCharacteristic import android.bluetooth.BluetoothGattCharacteristic
import info.nightscout.androidaps.extensions.toHex
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.OmnipodDashBleManagerImpl import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.OmnipodDashBleManagerImpl
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.callbacks.BleCommCallbacks import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.callbacks.BleCommCallbacks
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.command.BleCommand import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.command.BleCommand

View file

@ -15,7 +15,6 @@ 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.common.ui.wizard.activation.viewmodel.action.InsertCannulaViewModel
import info.nightscout.androidaps.plugins.pump.omnipod.dash.R 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.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.driver.pod.state.OmnipodDashPodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP