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)
}
},
@ -1043,25 +1047,29 @@ class OmnipodDashPumpPlugin @Inject constructor(
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)
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")
aapsLogger.warn(
LTag.PUMPBTCOMM,
"updateAlertConfiguration negative " +
"expiryAlertDuration=$expiryAlertDelay"
)
PumpEnactResult(injector).success(false).enacted(false)
}
val alerts = listOf (
val alerts = listOf(
AlertConfiguration(
AlertType.LOW_RESERVOIR,
enabled = lowReservoirAlertEnabled,
@ -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> {
@ -343,17 +337,14 @@ class OmnipodDashManagerImpl @Inject constructor(
return observables.reversed()
}
override fun activatePodPart2(basalProgram: BasalProgram, userConfiguredExpirationHours:Long?):
override fun activatePodPart2(basalProgram: BasalProgram, userConfiguredExpirationHours: Long?):
Observable<PodEvent> {
return Observable.concat(
observePodReadyForActivationPart2,
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

@ -102,7 +102,7 @@ interface OmnipodDashPodStateManager {
*/
fun recoverActivationFromPodStatus(): String?
fun differentAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int, lowReservoirAlertEnabled: Boolean, lowReservoirAlertUnits: Int): Boolean
fun updateExpirationAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int) : Completable
fun updateExpirationAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int): Completable
fun updateLowReservoirAlertSettings(lowReservoirAlertEnabled: Boolean, lowReservoirAlertUnits: Int): Completable
data class ActiveCommand(

View file

@ -409,8 +409,8 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
podState.lowReservoirAlertUnits == lowReservoirAlertUnits
}
override fun updateExpirationAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int) :
Completable = Completable.defer{
override fun updateExpirationAlertSettings(expirationReminderEnabled: Boolean, expirationHours: Int):
Completable = Completable.defer {
podState.expirationReminderEnabled = expirationReminderEnabled
podState.expirationHours = expirationHours
Completable.complete()

View file

@ -32,7 +32,7 @@ class DashInitializePodViewModel @Inject constructor(
Single.create { source ->
// TODO use configured value for low reservoir trigger
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 lowReservoirAlertUnits = sp.getInt(R.string.key_omnipod_common_low_reservoir_alert_units, 10)
val lowReservoirAlertTrigger = if (lowReservoirAlertEnabled) {
AlertTrigger.ReservoirVolumeTrigger((lowReservoirAlertUnits * 10).toShort())
} else

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