From 613e7963f2f573a2e70d937d789b93a1baa16f41 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Wed, 15 Sep 2021 20:36:53 +0200 Subject: [PATCH 01/11] translate exceptions. Display expiration 8h before the real expiration --- .../state/OmnipodDashPodStateManagerImpl.kt | 1 + .../action/DashInitializePodViewModel.kt | 9 +++++++- .../action/DashInsertCannulaViewModel.kt | 5 ++++- .../plugins/pump/omnipod/dash/util/I8n.kt | 21 +++++++++++++++++++ omnipod-dash/src/main/res/values/strings.xml | 6 ++++++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/I8n.kt 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 2aa7ec3220..0195dbeb67 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 @@ -241,6 +241,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( .plusHours(podLifeInHours.toLong()) .minusMinutes(minutesSinceActivation.toLong()) .minus(Duration.ofMillis(System.currentTimeMillis() - lastUpdatedSystem)) + .minusHours(8) } return null } 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 4862dc6a46..782157be74 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 @@ -10,6 +10,8 @@ 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.I8n +import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.Single import io.reactivex.rxkotlin.subscribeBy @@ -21,6 +23,7 @@ class DashInitializePodViewModel @Inject constructor( logger: AAPSLogger, private val sp: SP, private val podStateManager: OmnipodDashPodStateManager, + private val resourceHelper: ResourceHelper ) : InitializePodViewModel(injector, logger) { override fun isPodInAlarm(): Boolean = false // TODO @@ -46,7 +49,11 @@ class DashInitializePodViewModel @Inject constructor( }, onError = { throwable -> logger.error(LTag.PUMP, "Error in Pod activation part 1", throwable) - source.onSuccess(PumpEnactResult(injector).success(false).comment(throwable.toString())) + source.onSuccess( + PumpEnactResult(injector) + .success(false) + .comment(I8n.textFromException(throwable, resourceHelper)) + ) }, onComplete = { logger.debug("Pod activation part 1 completed") 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 4173fcd4c7..9d39d434ed 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 @@ -16,7 +16,9 @@ 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.state.OmnipodDashPodStateManager +import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram +import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.Single import io.reactivex.rxkotlin.subscribeBy @@ -29,6 +31,7 @@ class DashInsertCannulaViewModel @Inject constructor( private val podStateManager: OmnipodDashPodStateManager, private val rxBus: RxBusWrapper, private val sp: SP, + private val resourceHelper: ResourceHelper, injector: HasAndroidInjector, logger: AAPSLogger @@ -69,7 +72,7 @@ class DashInsertCannulaViewModel @Inject constructor( }, onError = { throwable -> logger.error(LTag.PUMP, "Error in Pod activation part 2", throwable) - source.onSuccess(PumpEnactResult(injector).success(false).comment(throwable.toString())) + source.onSuccess(PumpEnactResult(injector).success(false).comment(I8n.textFromException(throwable, resourceHelper))) }, onComplete = { logger.debug("Pod activation part 2 completed") diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/I8n.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/I8n.kt new file mode 100644 index 0000000000..ae137fcca6 --- /dev/null +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/I8n.kt @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.dash.util + +import info.nightscout.androidaps.plugins.pump.omnipod.dash.R +import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.FailedToConnectException +import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.ScanException +import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.ScanFailFoundTooManyException +import info.nightscout.androidaps.utils.resources.ResourceHelper + +class I8n { + companion object { + fun textFromException(exception: Throwable, rs: ResourceHelper): String { + return when (exception) { + is FailedToConnectException -> rs.gs(R.string.omnipod_dash_failed_to_connect) + is ScanFailFoundTooManyException -> rs.gs(R.string.omnipod_dash_found_too_many_pods) + is ScanException -> rs.gs(R.string.omnipod_dash_scan_failed) + else -> + rs.gs(R.string.omnipod_dash_generic_error, exception.toString()) + } + } + } +} \ No newline at end of file diff --git a/omnipod-dash/src/main/res/values/strings.xml b/omnipod-dash/src/main/res/values/strings.xml index ff58c9073f..d760dd1b74 100644 --- a/omnipod-dash/src/main/res/values/strings.xml +++ b/omnipod-dash/src/main/res/values/strings.xml @@ -24,4 +24,10 @@ common_preferences_category_other AAPS.Omnipod.notification_delivery_suspended_sound_enabled Sound when delivery suspended notification enabled + + + Failed to connect to pod + Found too many pods when scanning + Could not find any available pod for activation + Generic error: %1$s From 6b441b515e33b8bca7d7b413645f83a72b24eaae Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Tue, 21 Sep 2021 20:34:27 +0200 Subject: [PATCH 02/11] more translation --- .../dash/ui/OmnipodDashOverviewFragment.kt | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt index cae91a955f..dfce49f4bf 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt @@ -30,6 +30,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.R import info.nightscout.androidaps.plugins.pump.omnipod.dash.databinding.OmnipodDashOverviewBinding import info.nightscout.androidaps.plugins.pump.omnipod.dash.databinding.OmnipodDashOverviewBluetoothStatusBinding import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ActivationProgress +import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertType import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.events.EventQueueChanged @@ -389,7 +390,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() { } podInfoBinding.podActiveAlerts.text = podStateManager.activeAlerts?.let { it -> - it.joinToString(",") { it.toString() } + it.joinToString(System.lineSeparator()) { t -> translatedActiveAlert(t) } } ?: PLACEHOLDER } @@ -402,6 +403,24 @@ class OmnipodDashOverviewFragment : DaggerFragment() { } } + private fun translatedActiveAlert(alert: AlertType): String { + val id = when (alert) { + AlertType.LOW_RESERVOIR -> + R.string.omnipod_common_alert_low_reservoir + AlertType.EXPIRATION -> + R.string.omnipod_common_alert_expiration_advisory + AlertType.EXPIRATION_IMMINENT -> + R.string.omnipod_common_alert_expiration + AlertType.USER_SET_EXPIRATION -> + R.string.omnipod_common_alert_expiration_advisory + AlertType.AUTO_OFF -> + R.string.omnipod_common_alert_shutdown_imminent + else -> + R.string.omnipod_common_alert_unknown_alert + } + return resourceHelper.gs(id) + } + private fun updateLastConnection() { if (podStateManager.isUniqueIdSet) { podInfoBinding.lastConnection.text = readableDuration( From 8767065fda8bba927fdbfbd44a0c155a0ba2a292 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Tue, 21 Sep 2021 20:44:15 +0200 Subject: [PATCH 03/11] format --- .../pump/omnipod/dash/driver/comm/message/MessageIO.kt | 2 +- .../androidaps/plugins/pump/omnipod/dash/util/I8n.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/MessageIO.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/MessageIO.kt index 7292efa785..6e750069bc 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/MessageIO.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/MessageIO.kt @@ -177,7 +177,7 @@ class MessageIO( } BleCommandSuccess -> { - if (index == packets.size-1) + if (index == packets.size - 1) MessageSendSuccess else MessageSendErrorSending("Received SUCCESS before sending all the data. $index") diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/I8n.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/I8n.kt index ae137fcca6..b34fbf0b1a 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/I8n.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/I8n.kt @@ -10,12 +10,12 @@ class I8n { companion object { fun textFromException(exception: Throwable, rs: ResourceHelper): String { return when (exception) { - is FailedToConnectException -> rs.gs(R.string.omnipod_dash_failed_to_connect) + is FailedToConnectException -> rs.gs(R.string.omnipod_dash_failed_to_connect) is ScanFailFoundTooManyException -> rs.gs(R.string.omnipod_dash_found_too_many_pods) - is ScanException -> rs.gs(R.string.omnipod_dash_scan_failed) + is ScanException -> rs.gs(R.string.omnipod_dash_scan_failed) else -> rs.gs(R.string.omnipod_dash_generic_error, exception.toString()) } } } -} \ No newline at end of file +} From 2dee60b4e0f7a57828020463f62ffde7bdfc33c4 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Tue, 21 Sep 2021 21:05:29 +0200 Subject: [PATCH 04/11] update bluetooth status. fix warnings. --- .../insulin/program/util/ProgramBasalUtil.kt | 4 ++-- .../dash/ui/OmnipodDashOverviewFragment.kt | 24 ++++++++++++------- .../action/DashInitializePodViewModel.kt | 2 +- .../action/DashInsertCannulaViewModel.kt | 2 +- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/command/insulin/program/util/ProgramBasalUtil.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/command/insulin/program/util/ProgramBasalUtil.kt index 5ce3028b0c..5e6e00d015 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/command/insulin/program/util/ProgramBasalUtil.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/command/insulin/program/util/ProgramBasalUtil.kt @@ -189,7 +189,7 @@ object ProgramBasalUtil { return pulsesPerSlot } - fun calculateCurrentSlot(pulsesPerSlot: ShortArray?, currentTime: Date?): CurrentSlot { + fun calculateCurrentSlot(pulsesPerSlot: ShortArray?, currentTime: Date): CurrentSlot { val instance = Calendar.getInstance() instance.time = currentTime val hourOfDay = instance[Calendar.HOUR_OF_DAY] @@ -205,7 +205,7 @@ object ProgramBasalUtil { fun calculateCurrentLongInsulinProgramElement( elements: List, - currentTime: Date? + currentTime: Date ): CurrentBasalInsulinProgramElement { val instance = Calendar.getInstance() instance.time = currentTime diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt index dfce49f4bf..371df19101 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt @@ -13,6 +13,7 @@ import dagger.android.support.DaggerFragment import info.nightscout.androidaps.Constants import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.events.EventPreferenceChange +import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -206,6 +207,16 @@ class OmnipodDashOverviewFragment : DaggerFragment() { }, fabricPrivacy::logException ) + + disposables += rxBus + .toObservable(EventPumpStatusChanged::class.java) + .observeOn(aapsSchedulers.main) + .subscribe( + { + updateBluetoothConnectionStatus(it) + }, + fabricPrivacy::logException + ) updateUi() } @@ -231,18 +242,13 @@ class OmnipodDashOverviewFragment : DaggerFragment() { updateQueueStatus() } + private fun updateBluetoothConnectionStatus(event: EventPumpStatusChanged) { + bluetoothStatusBinding.omnipodDashBluetoothStatus.text = event.getStatus(resourceHelper) + } + private fun updateBluetoothStatus() { bluetoothStatusBinding.omnipodDashBluetoothAddress.text = podStateManager.bluetoothAddress ?: PLACEHOLDER - bluetoothStatusBinding.omnipodDashBluetoothStatus.text = - when (podStateManager.bluetoothConnectionState) { - OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTED -> - "{fa-bluetooth}" - OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED -> - "{fa-bluetooth-b}" - OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING -> - "{fa-bluetooth-b spin}" - } val connectionSuccessPercentage = podStateManager.connectionSuccessRatio() * 100 val successPercentageString = String.format("%.2f %%", connectionSuccessPercentage) 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 782157be74..a6faa187f4 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 @@ -40,7 +40,7 @@ class DashInitializePodViewModel @Inject constructor( } else null - val disposable = omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy( + omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy( onNext = { podEvent -> logger.debug( LTag.PUMP, 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 9d39d434ed..9a3530f443 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 @@ -63,7 +63,7 @@ class DashInsertCannulaViewModel @Inject constructor( else null - val disposable = omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy( + omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy( onNext = { podEvent -> logger.debug( LTag.PUMP, From 8184500467a6a7a6d8f7fe2ec2a6b0f7507056c0 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Tue, 21 Sep 2021 21:17:34 +0200 Subject: [PATCH 05/11] fix warnings --- .../driver/pod/command/ProgramBasalCommand.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/command/ProgramBasalCommand.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/command/ProgramBasalCommand.kt index f8a15f7178..aeb12e5953 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/command/ProgramBasalCommand.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/command/ProgramBasalCommand.kt @@ -100,22 +100,23 @@ class ProgramBasalCommand private constructor( } override fun buildCommand(): ProgramBasalCommand { - requireNotNull(basalProgram) { "basalProgram can not be null" } - requireNotNull(programReminder) { "programReminder can not be null" } - requireNotNull(currentTime) { "currentTime can not be null" } - val pulsesPerSlot = ProgramBasalUtil.mapBasalProgramToPulsesPerSlot(basalProgram!!) - val currentSlot = ProgramBasalUtil.calculateCurrentSlot(pulsesPerSlot, currentTime) + val program = requireNotNull(basalProgram) { "basalProgram can not be null" } + val reminder = requireNotNull(programReminder) { "programReminder can not be null" } + val time = requireNotNull(currentTime) { "currentTime can not be null" } + + val pulsesPerSlot = ProgramBasalUtil.mapBasalProgramToPulsesPerSlot(program) + val currentSlot = ProgramBasalUtil.calculateCurrentSlot(pulsesPerSlot, time) val checksum = ProgramBasalUtil.calculateChecksum(pulsesPerSlot, currentSlot) val longInsulinProgramElements: List = mapTenthPulsesPerSlotToLongInsulinProgramElements( - ProgramBasalUtil.mapBasalProgramToTenthPulsesPerSlot(basalProgram!!) + ProgramBasalUtil.mapBasalProgramToTenthPulsesPerSlot(program) ) val shortInsulinProgramElements = ProgramBasalUtil.mapPulsesPerSlotToShortInsulinProgramElements( pulsesPerSlot ) val currentBasalInsulinProgramElement = ProgramBasalUtil.calculateCurrentLongInsulinProgramElement( longInsulinProgramElements, - currentTime + time ) val interlockCommand = ProgramInsulinCommand( uniqueId!!, sequenceNumber!!, multiCommandFlag, nonce!!, @@ -128,7 +129,7 @@ class ProgramBasalCommand private constructor( sequenceNumber!!, multiCommandFlag, longInsulinProgramElements, - programReminder!!, + reminder, currentBasalInsulinProgramElement.index, currentBasalInsulinProgramElement.remainingTenthPulses, currentBasalInsulinProgramElement.delayUntilNextTenthPulseInUsec From 7f24933f4db1c9c2c65a11ad4b7136b5c7b1fbfb Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 21 Sep 2021 15:16:19 +0200 Subject: [PATCH 06/11] finish removing Objective8 --- .../objectives/ObjectivesPlugin.kt | 33 +++++++------------ .../interfaces/ConstraintsCheckerTest.kt | 10 ------ .../objectives/ObjectivesPluginTest.kt | 8 ----- .../general/automation/AutomationEvent.kt | 1 - .../automation/triggers/TriggerConnector.kt | 2 +- .../androidaps/interfaces/Constraints.kt | 1 - .../configBuilder/ConstraintChecker.kt | 13 -------- 7 files changed, 13 insertions(+), 55 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt index 74fa37901d..224a89a888 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt @@ -54,9 +54,8 @@ class ObjectivesPlugin @Inject constructor( const val MAXIOB_ZERO_CL_OBJECTIVE = 5 @Suppress("unused") const val MAXIOB_OBJECTIVE = 6 const val AUTOSENS_OBJECTIVE = 7 - const val AMA_OBJECTIVE = 8 - const val SMB_OBJECTIVE = 9 - const val AUTO_OBJECTIVE = 10 + const val SMB_OBJECTIVE = 8 + const val AUTO_OBJECTIVE = 9 } public override fun onStart() { @@ -64,9 +63,8 @@ class ObjectivesPlugin @Inject constructor( setupObjectives() } - override fun specialEnableCondition(): Boolean { - return activePlugin.activePump.pumpDescription.isTempBasalCapable - } + override fun specialEnableCondition(): Boolean = + activePlugin.activePump.pumpDescription.isTempBasalCapable private fun setupObjectives() { objectives.clear() @@ -80,6 +78,7 @@ class ObjectivesPlugin @Inject constructor( objectives.add(Objective7(injector)) objectives.add(Objective9(injector)) objectives.add(Objective10(injector)) + // edit companion object if you remove/add Objective } fun reset() { @@ -115,8 +114,6 @@ class ObjectivesPlugin @Inject constructor( sp.putLong("Objectives_" + "maxiob" + "_accomplished", dateUtil.now()) sp.putLong("Objectives_" + "autosens" + "_started", dateUtil.now()) sp.putLong("Objectives_" + "autosens" + "_accomplished", dateUtil.now()) - sp.putLong("Objectives_" + "ama" + "_started", dateUtil.now()) - sp.putLong("Objectives_" + "ama" + "_accomplished", dateUtil.now()) sp.putLong("Objectives_" + "smb" + "_started", dateUtil.now()) sp.putLong("Objectives_" + "smb" + "_accomplished", dateUtil.now()) sp.putLong("Objectives_" + "auto" + "_started", dateUtil.now()) @@ -142,49 +139,43 @@ class ObjectivesPlugin @Inject constructor( */ override fun isLoopInvocationAllowed(value: Constraint): Constraint { if (!objectives[FIRST_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), FIRST_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, FIRST_OBJECTIVE + 1), this) return value } override fun isLgsAllowed(value: Constraint): Constraint { if (!objectives[MAXBASAL_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), MAXBASAL_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, MAXBASAL_OBJECTIVE + 1), this) return value } override fun isClosedLoopAllowed(value: Constraint): Constraint { if (!objectives[MAXIOB_ZERO_CL_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), MAXIOB_ZERO_CL_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, MAXIOB_ZERO_CL_OBJECTIVE + 1), this) return value } override fun isAutosensModeEnabled(value: Constraint): Constraint { if (!objectives[AUTOSENS_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), AUTOSENS_OBJECTIVE + 1), this) - return value - } - - override fun isAMAModeEnabled(value: Constraint): Constraint { - if (!objectives[AMA_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), AMA_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, AUTOSENS_OBJECTIVE + 1), this) return value } override fun isSMBModeEnabled(value: Constraint): Constraint { if (!objectives[SMB_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), SMB_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, SMB_OBJECTIVE + 1), this) return value } override fun applyMaxIOBConstraints(maxIob: Constraint): Constraint { if (objectives[MAXIOB_ZERO_CL_OBJECTIVE].isStarted && !objectives[MAXIOB_ZERO_CL_OBJECTIVE].isAccomplished) - maxIob.set(aapsLogger, 0.0, String.format(resourceHelper.gs(R.string.objectivenotfinished), MAXIOB_ZERO_CL_OBJECTIVE + 1), this) + maxIob.set(aapsLogger, 0.0, resourceHelper.gs(R.string.objectivenotfinished, MAXIOB_ZERO_CL_OBJECTIVE + 1), this) return maxIob } override fun isAutomationEnabled(value: Constraint): Constraint { if (!objectives[AUTO_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), AUTO_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, AUTO_OBJECTIVE + 1), this) return value } } diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt index 3235a110c0..874175a2be 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt @@ -198,16 +198,6 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { Assert.assertEquals(java.lang.Boolean.FALSE, c.value()) } - // Objectives - @Test - fun isAMAModeEnabledTest() { - objectivesPlugin.objectives[ObjectivesPlugin.AMA_OBJECTIVE].startedOn = 0 - val c = constraintChecker.isAMAModeEnabled() - Assert.assertEquals(true, c.reasonList.size == 1) // Objectives - Assert.assertEquals(true, c.mostLimitedReasonList.size == 1) // Objectives - Assert.assertEquals(java.lang.Boolean.FALSE, c.value()) - } - // Safety @Test fun isAdvancedFilteringEnabledTest() { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt index 270753e9a4..c08f4c9033 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt @@ -74,14 +74,6 @@ class ObjectivesPluginTest : TestBase() { Assert.assertEquals(false, c.value()) } - @Test fun notStartedObjective9ShouldLimitAMAMode() { - objectivesPlugin.objectives[ObjectivesPlugin.AMA_OBJECTIVE].startedOn = 0 - var c = Constraint(true) - c = objectivesPlugin.isAMAModeEnabled(c) - Assert.assertEquals(true, c.getReasons(aapsLogger).contains("Objective 9 not started")) - Assert.assertEquals(false, c.value()) - } - @Test fun notStartedObjective10ShouldLimitSMBMode() { objectivesPlugin.objectives[ObjectivesPlugin.SMB_OBJECTIVE].startedOn = 0 var c = Constraint(true) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt index f0e8bffd89..b02dfb0dd3 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt @@ -72,7 +72,6 @@ class AutomationEvent(private val injector: HasAndroidInjector) { readOnly = d.optBoolean("readOnly", false) autoRemove = d.optBoolean("autoRemove", false) trigger = TriggerDummy(injector).instantiate(JSONObject(d.getString("trigger"))) - ?: TriggerConnector(injector) val array = d.getJSONArray("actions") actions.clear() for (i in 0 until array.length()) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt index 105f91fe3b..91311a84da 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt @@ -95,7 +95,7 @@ class TriggerConnector(injector: HasAndroidInjector) : Trigger(injector) { val array = d.getJSONArray("triggerList") list.clear() for (i in 0 until array.length()) { - instantiate(JSONObject(array.getString(i)))?.let { + instantiate(JSONObject(array.getString(i))).let { list.add(it) } } diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/Constraints.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/Constraints.kt index 95a901f626..709b4c037b 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/Constraints.kt +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/Constraints.kt @@ -17,7 +17,6 @@ interface Constraints { fun isClosedLoopAllowed(value: Constraint): Constraint = value fun isLgsAllowed(value: Constraint): Constraint = value fun isAutosensModeEnabled(value: Constraint): Constraint = value - fun isAMAModeEnabled(value: Constraint): Constraint = value fun isSMBModeEnabled(value: Constraint): Constraint = value fun isUAMEnabled(value: Constraint): Constraint = value fun isAdvancedFilteringEnabled(value: Constraint): Constraint = value diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt b/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt index 99476dff8f..718956c90b 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt @@ -24,9 +24,6 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug fun isAutosensModeEnabled(): Constraint = isAutosensModeEnabled(Constraint(true)) - fun isAMAModeEnabled(): Constraint = - isAMAModeEnabled(Constraint(true)) - fun isSMBModeEnabled(): Constraint = isSMBModeEnabled(Constraint(true)) @@ -100,16 +97,6 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug return value } - override fun isAMAModeEnabled(value: Constraint): Constraint { - val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java) - for (p in constraintsPlugins) { - val constrain = p as Constraints - if (!p.isEnabled(PluginType.CONSTRAINTS)) continue - constrain.isAMAModeEnabled(value) - } - return value - } - override fun isSMBModeEnabled(value: Constraint): Constraint { val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java) for (p in constraintsPlugins) { From 9d5b4c99976c64484b5154f47ad0de1279533888 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 21 Sep 2021 15:35:59 +0200 Subject: [PATCH 07/11] lints --- .../androidaps/plugins/general/actions/ActionsFragment.kt | 2 +- .../androidaps/plugins/general/overview/OverviewFragment.kt | 2 +- .../androidaps/plugins/profile/local/LocalProfileFragment.kt | 4 ++-- .../info/nightscout/androidaps/setupwizard/SWDefinition.kt | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt index ada8f9eab0..3688f1a55f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt @@ -156,7 +156,7 @@ class ActionsFragment : DaggerFragment() { pbLevelLabel = view.findViewById(R.id.pb_level_label) profileSwitch?.setOnClickListener { - ProfileSwitchDialog().show(childFragmentManager, "Actions") + ProfileSwitchDialog().show(childFragmentManager, "ProfileSwitchDialog") } tempTarget?.setOnClickListener { TempTargetDialog().show(childFragmentManager, "Actions") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 981881ffa3..9da0246b70 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -377,7 +377,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } R.id.temp_target -> v.performClick() - R.id.active_profile -> activity?.let { activity -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { ProfileSwitchDialog().show(childFragmentManager, "Overview") }) } + R.id.active_profile -> activity?.let { activity -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { ProfileSwitchDialog().show(childFragmentManager, "ProfileSwitchDialog") }) } } return false diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt index d166348713..989ef9dbdb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt @@ -212,7 +212,7 @@ class LocalProfileFragment : DaggerFragment() { binding.profileswitch.setOnClickListener { ProfileSwitchDialog() .also { it.arguments = Bundle().also { bundle -> bundle.putInt("profileIndex", localProfilePlugin.currentProfileIndex) } } - .show(childFragmentManager, "NewNSTreatmentDialog") + .show(childFragmentManager, "ProfileSwitchDialog") } binding.reset.setOnClickListener { @@ -259,7 +259,7 @@ class LocalProfileFragment : DaggerFragment() { updateGUI() } - fun updateGUI() { + private fun updateGUI() { if (_binding == null) return val isValid = localProfilePlugin.isValidEditState() val isEdited = localProfilePlugin.isEdited diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt index 8d640afc75..8b526b97bd 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt @@ -267,7 +267,7 @@ class SWDefinition @Inject constructor( .label(R.string.profileswitch_ismissing)) .add(SWButton(injector) .text(R.string.doprofileswitch) - .action { ProfileSwitchDialog().show(activity.supportFragmentManager, "SetupWizard") }) + .action { ProfileSwitchDialog().show(activity.supportFragmentManager, "ProfileSwitchDialog") }) .validator { profileFunction.getProfile() != null } .visibility { profileFunction.getProfile() == null } private val screenPump = SWScreen(injector, R.string.configbuilder_pump) From 89578b44231aef5a1e4bb5bc7b84af6802ed5b22 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 21 Sep 2021 16:46:12 +0200 Subject: [PATCH 08/11] unify trend arrow AAPS <-> watch --- .../wearintegration/WatchUpdaterService.java | 42 ++------ .../database/entities/GlucoseValue.kt | 102 ++++++++++-------- 2 files changed, 64 insertions(+), 80 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java index d18d9e96bb..1e5c4364e6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java @@ -29,12 +29,9 @@ import java.util.stream.Collectors; import javax.inject.Inject; import dagger.android.AndroidInjection; -import info.nightscout.androidaps.interfaces.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.IobTotal; -import info.nightscout.androidaps.interfaces.GlucoseUnit; -import info.nightscout.androidaps.interfaces.Profile; import info.nightscout.androidaps.database.AppRepository; import info.nightscout.androidaps.database.entities.Bolus; import info.nightscout.androidaps.database.entities.GlucoseValue; @@ -42,8 +39,11 @@ import info.nightscout.androidaps.database.entities.TemporaryBasal; import info.nightscout.androidaps.extensions.GlucoseValueExtensionKt; import info.nightscout.androidaps.extensions.TemporaryBasalExtensionKt; import info.nightscout.androidaps.interfaces.ActivePlugin; +import info.nightscout.androidaps.interfaces.Config; +import info.nightscout.androidaps.interfaces.GlucoseUnit; import info.nightscout.androidaps.interfaces.IobCobCalculator; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.Profile; import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; @@ -59,7 +59,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProv import info.nightscout.androidaps.receivers.ReceiverStatusStore; import info.nightscout.androidaps.utils.DecimalFormatter; import info.nightscout.androidaps.utils.DefaultValueHelper; -import info.nightscout.androidaps.utils.ToastUtils; +import info.nightscout.androidaps.utils.TrendCalculator; import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.sharedPreferences.SP; @@ -79,6 +79,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog @Inject public AppRepository repository; @Inject ReceiverStatusStore receiverStatusStore; @Inject Config config; + @Inject public TrendCalculator trendCalculator; public static final String ACTION_RESEND = WatchUpdaterService.class.getName().concat(".Resend"); public static final String ACTION_OPEN_SETTINGS = WatchUpdaterService.class.getName().concat(".OpenSettings"); @@ -322,7 +323,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog dataMap.putString("delta", "--"); dataMap.putString("avgDelta", "--"); } else { - dataMap.putString("slopeArrow", slopeArrow(glucoseStatus.getDelta())); + dataMap.putString("slopeArrow", trendCalculator.getTrendArrow(lastBG).getSymbol()); dataMap.putString("delta", deltastring(glucoseStatus.getDelta(), glucoseStatus.getDelta() * Constants.MGDL_TO_MMOLL, units)); dataMap.putString("avgDelta", deltastring(glucoseStatus.getShortAvgDelta(), glucoseStatus.getShortAvgDelta() * Constants.MGDL_TO_MMOLL, units)); } @@ -358,25 +359,6 @@ public class WatchUpdaterService extends WearableListenerService implements Goog return deltastring; } - private String slopeArrow(double delta) { - if (delta <= (-3.5 * 5)) { - return "\u21ca"; - } else if (delta <= (-2 * 5)) { - return "\u2193"; - } else if (delta <= (-1 * 5)) { - return "\u2198"; - } else if (delta <= (1 * 5)) { - return "\u2192"; - } else if (delta <= (2 * 5)) { - return "\u2197"; - } else if (delta <= (3.5 * 5)) { - return "\u2191"; - } else { - return "\u21c8"; - } - } - - private void resendData() { if (googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) { googleApiConnect(); @@ -391,16 +373,10 @@ public class WatchUpdaterService extends WearableListenerService implements Goog if (!graph_bgs.isEmpty()) { DataMap entries = dataMapSingleBG(last_bg, glucoseStatus); - if (entries == null) { - ToastUtils.showToastInUiThread(this, resourceHelper.gs(R.string.noprofile)); - return; - } final ArrayList dataMaps = new ArrayList<>(graph_bgs.size()); for (GlucoseValue bg : graph_bgs) { DataMap dataMap = dataMapSingleBG(bg, glucoseStatus); - if (dataMap != null) { - dataMaps.add(dataMap); - } + dataMaps.add(dataMap); } entries.putDataMapArrayList("entries", dataMaps); (new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient)).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, entries); @@ -505,7 +481,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog tb2 = iobCobCalculator.getTempBasalIncludingConvertedExtended(now); //use "now" to express current situation if (tb2 == null) { //express the cancelled temp by painting it down one minute early - temps.add(tempDatamap(tb_start, tb_before, now - 1 * 60 * 1000, endBasalValue, tb_amount)); + temps.add(tempDatamap(tb_start, tb_before, now - 60 * 1000, endBasalValue, tb_amount)); } else { //express currently running temp by painting it a bit into the future Profile profileNow = profileFunction.getProfile(now); @@ -523,7 +499,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog //onset at the end Profile profileTB = profileFunction.getProfile(runningTime); double currentAmount = TemporaryBasalExtensionKt.convertedToAbsolute(tb2, runningTime, profileTB); - temps.add(tempDatamap(now - 1 * 60 * 1000, endBasalValue, runningTime + 5 * 60 * 1000, currentAmount, currentAmount)); + temps.add(tempDatamap(now - 60 * 1000, endBasalValue, runningTime + 5 * 60 * 1000, currentAmount, currentAmount)); } } diff --git a/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt b/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt index d7140a7900..d101681a7b 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt @@ -1,25 +1,31 @@ package info.nightscout.androidaps.database.entities -import com.google.gson.annotations.SerializedName -import androidx.room.* +import androidx.room.Embedded +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.Index +import androidx.room.PrimaryKey import info.nightscout.androidaps.database.TABLE_GLUCOSE_VALUES import info.nightscout.androidaps.database.embedments.InterfaceIDs import info.nightscout.androidaps.database.interfaces.DBEntryWithTime import info.nightscout.androidaps.database.interfaces.TraceableDBEntry -import java.util.TimeZone +import java.util.* -@Entity(tableName = TABLE_GLUCOSE_VALUES, +@Entity( + tableName = TABLE_GLUCOSE_VALUES, foreignKeys = [ForeignKey( entity = GlucoseValue::class, parentColumns = ["id"], - childColumns = ["referenceId"])], + childColumns = ["referenceId"] + )], indices = [ Index("id"), Index("nightscoutId"), Index("sourceSensor"), Index("referenceId"), Index("timestamp") - ]) + ] +) data class GlucoseValue( @PrimaryKey(autoGenerate = true) override var id: Long = 0, @@ -51,53 +57,55 @@ data class GlucoseValue( fun isRecordDeleted(other: GlucoseValue): Boolean = isValid && !other.isValid - enum class TrendArrow (val text:String, val symbol:String){ - @SerializedName("NONE") NONE("NONE", "??"), - @SerializedName("TripleUp")TRIPLE_UP("TripleUp", "X"), - @SerializedName("DoubleUp")DOUBLE_UP("DoubleUp", "\u21c8"), - @SerializedName("SingleUp")SINGLE_UP("SingleUp", "\u2191"), - @SerializedName("FortyFiveUp")FORTY_FIVE_UP("FortyFiveUp", "\u2197"), - @SerializedName("Flat")FLAT("Flat", "\u2192"), - @SerializedName("FortyFiveDown")FORTY_FIVE_DOWN("FortyFiveDown", "\u2198"), - @SerializedName("SingleDown")SINGLE_DOWN("SingleDown", "\u2193"), - @SerializedName("DoubleDown")DOUBLE_DOWN("DoubleDown", "\u21ca"), - @SerializedName("TripleDown")TRIPLE_DOWN("TripleDown", "X") + enum class TrendArrow(val text: String, val symbol: String) { + NONE("NONE", "??"), + TRIPLE_UP("TripleUp", "X"), + DOUBLE_UP("DoubleUp", "\u21c8"), + SINGLE_UP("SingleUp", "\u2191"), + FORTY_FIVE_UP("FortyFiveUp", "\u2197"), + FLAT("Flat", "\u2192"), + FORTY_FIVE_DOWN("FortyFiveDown", "\u2198"), + SINGLE_DOWN("SingleDown", "\u2193"), + DOUBLE_DOWN("DoubleDown", "\u21ca"), + TRIPLE_DOWN("TripleDown", "X") ; companion object { - fun fromString(direction : String?) = values().firstOrNull {it.text == direction} ?: NONE + + fun fromString(direction: String?) = + values().firstOrNull { it.text == direction } ?: NONE } } - enum class SourceSensor(val text : String) { - @SerializedName("AndroidAPS-Dexcom") DEXCOM_NATIVE_UNKNOWN("AndroidAPS-Dexcom"), - @SerializedName("AndroidAPS-DexcomG6") DEXCOM_G6_NATIVE("AndroidAPS-DexcomG6"), - @SerializedName("AndroidAPS-DexcomG5") DEXCOM_G5_NATIVE("AndroidAPS-DexcomG5"), - @SerializedName("Bluetooth Wixel") DEXCOM_G4_WIXEL("Bluetooth Wixel"), - @SerializedName("xBridge Wixel") DEXCOM_G4_XBRIDGE("xBridge Wixel"), - @SerializedName("G4 Share Receiver") DEXCOM_G4_NATIVE("G4 Share Receiver"), - @SerializedName("Medtrum A6") MEDTRUM_A6("Medtrum A6"), - @SerializedName("Network G4") DEXCOM_G4_NET("Network G4"), - @SerializedName("Network G4 and xBridge") DEXCOM_G4_NET_XBRIDGE("Network G4 and xBridge"), - @SerializedName("Network G4 and Classic xDrip") DEXCOM_G4_NET_CLASSIC("Network G4 and Classic xDrip"), - @SerializedName("DexcomG5") DEXCOM_G5_XDRIP("DexcomG5"), - @SerializedName("G6 Native") DEXCOM_G6_NATIVE_XDRIP("G6 Native"), - @SerializedName("G5 Native") DEXCOM_G5_NATIVE_XDRIP("G5 Native"), - @SerializedName("G6 Native / G5 Native") DEXCOM_G6_G5_NATIVE_XDRIP("G6 Native / G5 Native"), - @SerializedName("Network libre") LIBRE_1_NET("Network libre"), - @SerializedName("BlueReader") LIBRE_1_BLUE("BlueReader"), - @SerializedName("Transmiter PL") LIBRE_1_PL("Transmiter PL"), - @SerializedName("Blucon") LIBRE_1_BLUCON("Blucon"), - @SerializedName("Tomato") LIBRE_1_TOMATO("Tomato"), - @SerializedName("Rfduino") LIBRE_1_RF("Rfduino"), - @SerializedName("LimiTTer") LIBRE_1_LIMITTER("LimiTTer"), - @SerializedName("Glimp") GLIMP("Glimp"), - @SerializedName("Libre2") LIBRE_2_NATIVE("Libre2"), - @SerializedName("Poctech") POCTECH_NATIVE("Poctech"), - @SerializedName("MM600Series") MM_600_SERIES("MM600Series"), - @SerializedName("Eversense") EVERSENSE("Eversense"), - @SerializedName("Random") RANDOM("Random"), - @SerializedName("Unknown") UNKNOWN("Unknown"), + enum class SourceSensor(val text: String) { + DEXCOM_NATIVE_UNKNOWN("AndroidAPS-Dexcom"), + DEXCOM_G6_NATIVE("AndroidAPS-DexcomG6"), + DEXCOM_G5_NATIVE("AndroidAPS-DexcomG5"), + DEXCOM_G4_WIXEL("Bluetooth Wixel"), + DEXCOM_G4_XBRIDGE("xBridge Wixel"), + DEXCOM_G4_NATIVE("G4 Share Receiver"), + MEDTRUM_A6("Medtrum A6"), + DEXCOM_G4_NET("Network G4"), + DEXCOM_G4_NET_XBRIDGE("Network G4 and xBridge"), + DEXCOM_G4_NET_CLASSIC("Network G4 and Classic xDrip"), + DEXCOM_G5_XDRIP("DexcomG5"), + DEXCOM_G6_NATIVE_XDRIP("G6 Native"), + DEXCOM_G5_NATIVE_XDRIP("G5 Native"), + DEXCOM_G6_G5_NATIVE_XDRIP("G6 Native / G5 Native"), + LIBRE_1_NET("Network libre"), + LIBRE_1_BLUE("BlueReader"), + LIBRE_1_PL("Transmiter PL"), + LIBRE_1_BLUCON("Blucon"), + LIBRE_1_TOMATO("Tomato"), + LIBRE_1_RF("Rfduino"), + LIBRE_1_LIMITTER("LimiTTer"), + GLIMP("Glimp"), + LIBRE_2_NATIVE("Libre2"), + POCTECH_NATIVE("Poctech"), + MM_600_SERIES("MM600Series"), + EVERSENSE("Eversense"), + RANDOM("Random"), + UNKNOWN("Unknown"), IOB_PREDICTION("IOBPrediction"), A_COB_PREDICTION("aCOBPrediction"), From 12fc4175dc65a39e9850102196f2e9d0839a821a Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Tue, 21 Sep 2021 21:26:56 +0200 Subject: [PATCH 09/11] update default bluetooth status text --- .../main/res/layout/omnipod_dash_overview_bluetooth_status.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/omnipod-dash/src/main/res/layout/omnipod_dash_overview_bluetooth_status.xml b/omnipod-dash/src/main/res/layout/omnipod_dash_overview_bluetooth_status.xml index 6c9c33b5e0..04822f68d3 100644 --- a/omnipod-dash/src/main/res/layout/omnipod_dash_overview_bluetooth_status.xml +++ b/omnipod-dash/src/main/res/layout/omnipod_dash_overview_bluetooth_status.xml @@ -73,7 +73,6 @@ android:gravity="start" android:paddingStart="5dp" android:paddingEnd="5dp" - android:text="{fa-bluetooth-b} " android:textSize="14sp" tools:ignore="HardcodedText" /> From b84f68c934620aa20de905e9c92e656f6863e211 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Tue, 21 Sep 2021 21:37:04 +0200 Subject: [PATCH 10/11] display disconnected status --- .../pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt index 371df19101..dfdc2410c9 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt @@ -243,7 +243,12 @@ class OmnipodDashOverviewFragment : DaggerFragment() { } private fun updateBluetoothConnectionStatus(event: EventPumpStatusChanged) { - bluetoothStatusBinding.omnipodDashBluetoothStatus.text = event.getStatus(resourceHelper) + var status = event.getStatus(resourceHelper) + if (status.isEmpty()) { + status = resourceHelper.gs(R.string.disconnected) + } + bluetoothStatusBinding.omnipodDashBluetoothStatus.text = status + } private fun updateBluetoothStatus() { From a8e3934b7a3a72b4b4e99486f54fa3e11ba06c69 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Tue, 21 Sep 2021 21:43:11 +0200 Subject: [PATCH 11/11] update error messages --- omnipod-dash/src/main/res/values/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/omnipod-dash/src/main/res/values/strings.xml b/omnipod-dash/src/main/res/values/strings.xml index d760dd1b74..16c21fa8db 100644 --- a/omnipod-dash/src/main/res/values/strings.xml +++ b/omnipod-dash/src/main/res/values/strings.xml @@ -27,7 +27,7 @@ Failed to connect to pod - Found too many pods when scanning - Could not find any available pod for activation + Found too many pods for activation + Could not find an available pod for activation Generic error: %1$s