From 32183aff373436887ea53d061fb0b21494812f61 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Fri, 16 Jul 2021 22:25:37 +0200 Subject: [PATCH] format. remove duplication --- .../omnipod/dash/OmnipodDashPumpPlugin.kt | 31 ++-- .../dash/driver/OmnipodDashManagerImpl.kt | 132 ++++++------------ .../dash/driver/comm/ServiceDiscoverer.kt | 2 +- .../omnipod/dash/driver/comm/io/CmdBleIO.kt | 2 - .../pod/state/OmnipodDashPodStateManager.kt | 2 +- .../state/OmnipodDashPodStateManagerImpl.kt | 4 +- .../action/DashInitializePodViewModel.kt | 2 +- .../action/DashInsertCannulaViewModel.kt | 1 - 8 files changed, 71 insertions(+), 105 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt index d90c04b8f7..73a6ce6ded 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt @@ -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 diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt index 5e6ff425dd..24004f4de6 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt @@ -84,10 +84,7 @@ class OmnipodDashManagerImpl @Inject constructor( override fun connect(stop: CountDownLatch): Observable { 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 { @@ -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 { @@ -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 { 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> { val observables = ArrayList>() @@ -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,27 +415,33 @@ 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( - AlertType.USER_SET_EXPIRATION, - enabled = true, - durationInMinutes = 0, - autoOff = false, - AlertTrigger.TimerTrigger( - userExpiryAlertDelay.toMinutes().toShort() - ), - BeepType.FOUR_TIMES_BIP_BEEP, - BeepRepetitionType.XXX2 - )) + 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, + alerts, multiCommandFlag = true ).doOnComplete(ActivationProgressUpdater(ActivationProgress.UPDATED_EXPIRATION_ALERTS)) ) @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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): Observable { @@ -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): Observable { @@ -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 @@ -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.interceptPodEvents(): Observable { + return this.doOnNext(PodEventInterceptor()) + .doOnError(ErrorInterceptor()) + .subscribeOn(aapsSchedulers.io) + } + inner class ErrorInterceptor : Consumer { override fun accept(throwable: Throwable) { diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/ServiceDiscoverer.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/ServiceDiscoverer.kt index c3c38e0030..2fc1c42704 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/ServiceDiscoverer.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/ServiceDiscoverer.kt @@ -36,7 +36,7 @@ class ServiceDiscoverer( } connectionWaitCond.stopConnection?.let { while (!bleCallbacks.waitForServiceDiscovery(STOP_CONNECTING_CHECK_INTERVAL_MS)) { - if (it.count == 0L || connection.connectionState() !is Connected) { + if (it.count == 0L || connection.connectionState() !is Connected) { throw ConnectException("stopConnecting called") } } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/CmdBleIO.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/CmdBleIO.kt index d524fa6668..8421a6f1d3 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/CmdBleIO.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/CmdBleIO.kt @@ -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 diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt index cada0148c8..af833c4552 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt @@ -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( diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt index 0d57d2e976..f71aa63bcc 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt @@ -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() diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt index b39a2213be..cbdce8ab5a 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt @@ -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 diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt index 0f66c247e9..4f5f2f06c9 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt @@ -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