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 connect(reason: String) {
@ -400,10 +399,15 @@ class OmnipodDashPumpPlugin @Inject constructor(
.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)) {
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)
}
},
@ -1050,15 +1054,19 @@ class OmnipodDashPumpPlugin @Inject constructor(
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")
aapsLogger.warn(
LTag.PUMPBTCOMM,
"updateAlertConfiguration negative " +
"expiryAlertDuration=$expiryAlertDelay"
)
PumpEnactResult(injector).success(false).enacted(false)
}
val alerts = listOf(
@ -1088,7 +1096,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
command = omnipodManager.programAlerts(alerts).ignoreElements(),
post = podStateManager.updateExpirationAlertSettings(
expirationReminderEnabled,
expirationHours).andThen(
expirationHours
).andThen(
podStateManager.updateExpirationAlertSettings(
lowReservoirAlertEnabled,
lowReservoirAlertUnits

View file

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