From 72f819b80d9a00418ff4c567ee63a112c63b2cc6 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Fri, 15 Oct 2021 18:09:31 +0200 Subject: [PATCH] implement setTime. handle timezone changes --- .../omnipod/dash/OmnipodDashPumpPlugin.kt | 25 ++++++++++++------- .../dash/ui/OmnipodDashOverviewFragment.kt | 7 ++---- .../main/res/xml/omnipod_dash_preferences.xml | 3 +-- 3 files changed, 19 insertions(+), 16 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 a8e296aee6..89cb247d2b 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 @@ -1169,8 +1169,9 @@ class OmnipodDashPumpPlugin @Inject constructor( } private fun handleTimeChange(): PumpEnactResult { - // TODO - return PumpEnactResult(injector).success(false).enacted(false).comment("NOT IMPLEMENTED") + return profileFunction.getProfile()?.let { + setNewBasalProfile(it) + } ?: PumpEnactResult(injector).success(true).enacted(false).comment("No profile active") } private fun updateAlertConfiguration(): PumpEnactResult { @@ -1252,14 +1253,20 @@ class OmnipodDashPumpPlugin @Inject constructor( "Time, Date and/or TimeZone changed. [timeChangeType=" + timeChangeType.name + ", eventHandlingEnabled=" + eventHandlingEnabled + "]" ) - if (timeChangeType == TimeChangeType.TimeChanged) { - aapsLogger.info(LTag.PUMP, "Ignoring time change because it is not a DST or TZ change") - return - } else if (!podStateManager.isPodRunning) { - aapsLogger.info(LTag.PUMP, "Ignoring time change because no Pod is active") - return + when { + !eventHandlingEnabled -> { + aapsLogger.info(LTag.PUMP, "Ignoring time change because automatic time handling is disabled in configuration") + return + } + timeChangeType == TimeChangeType.TimeChanged -> { + aapsLogger.info(LTag.PUMP, "Ignoring time change because it is not a DST or TZ change") + return + } + !podStateManager.isPodRunning -> { + aapsLogger.info(LTag.PUMP, "Ignoring time change because no Pod is active") + return + } } - aapsLogger.info(LTag.PUMP, "Handling time change") commandQueue.customCommand(CommandHandleTimeChange(false), null) 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 446d29ac16..e74f87396e 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 @@ -631,15 +631,12 @@ class OmnipodDashOverviewFragment : DaggerFragment() { } private fun updateSetTimeButton() { - // TODO - /* - if (podStateManager.isPodRunning && (podStateManager.timeDeviatesMoreThan(Duration.standardMinutes(5)) || commandQueue.isCustomCommandInQueue(CommandHandleTimeChange::class.java))) { + if (podStateManager.isActivationCompleted && !podStateManager.sameTimeZone) { buttonBinding.buttonSetTime.visibility = View.VISIBLE - buttonBinding.buttonSetTime.isEnabled = !podStateManager.isSuspended && rileyLinkServiceData.rileyLinkServiceState.isReady && isQueueEmpty() + buttonBinding.buttonSetTime.isEnabled = !podStateManager.isSuspended && isQueueEmpty() } else { buttonBinding.buttonSetTime.visibility = View.GONE } - */ } private fun isAutomaticallySilenceAlertsEnabled(): Boolean { diff --git a/omnipod-dash/src/main/res/xml/omnipod_dash_preferences.xml b/omnipod-dash/src/main/res/xml/omnipod_dash_preferences.xml index a5aca72dab..0e812a9709 100644 --- a/omnipod-dash/src/main/res/xml/omnipod_dash_preferences.xml +++ b/omnipod-dash/src/main/res/xml/omnipod_dash_preferences.xml @@ -109,12 +109,11 @@ android:defaultValue="false" android:key="@string/key_omnipod_common_suspend_delivery_button_enabled" android:title="@string/omnipod_common_preferences_suspend_delivery_button_enabled" /> - \ No newline at end of file