From 6070b117f4f6d259228866179111907d4667cbc9 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Fri, 11 Sep 2020 02:25:48 +0200 Subject: [PATCH] Get Pod status after time change event and add notification when automatic time change fails --- .../pump/omnipod/OmnipodPumpPlugin.java | 30 ++++++++++++++----- omnipod/src/main/res/values/strings.xml | 1 + 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java index c416ae4e28..5fb940cceb 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java @@ -510,22 +510,38 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, } } } else if (this.hasTimeDateOrTimeZoneChanged) { - PumpEnactResult result = executeCommand(OmnipodCommandType.SET_TIME, aapsOmnipodManager::setTime); + PumpEnactResult result; + if (aapsOmnipodManager.isTimeChangeEventEnabled()) { + result = executeCommand(OmnipodCommandType.SET_TIME, aapsOmnipodManager::setTime); + } else { + // Even if automatically changing the time is disabled, we still want to at least do a GetStatus request, + // in order to update the Pod's activation time, which we need for calculating the time on the Pod + result = executeCommand(OmnipodCommandType.GET_POD_STATUS, aapsOmnipodManager::getPodStatus); + } if (result.success) { this.hasTimeDateOrTimeZoneChanged = false; timeChangeRetries = 0; - Notification notification = new Notification( - Notification.TIME_OR_TIMEZONE_CHANGE, - resourceHelper.gs(R.string.omnipod_time_or_timezone_change), - Notification.INFO, 60); - rxBus.send(new EventNewNotification(notification)); + if (aapsOmnipodManager.isTimeChangeEventEnabled()) { + Notification notification = new Notification( + Notification.TIME_OR_TIMEZONE_CHANGE, + resourceHelper.gs(R.string.omnipod_time_or_timezone_change), + Notification.INFO, 60); + rxBus.send(new EventNewNotification(notification)); + } } else { timeChangeRetries++; if (timeChangeRetries > 3) { + if (aapsOmnipodManager.isTimeChangeEventEnabled()) { + Notification notification = new Notification( + Notification.TIME_OR_TIMEZONE_CHANGE, + resourceHelper.gs(R.string.omnipod_time_or_timezone_change_failed), + Notification.INFO, 60); + rxBus.send(new EventNewNotification(notification)); + } this.hasTimeDateOrTimeZoneChanged = false; timeChangeRetries = 0; } @@ -806,7 +822,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, public void timezoneOrDSTChanged(TimeChangeType timeChangeType) { aapsLogger.warn(LTag.PUMP, "Time, Date and/or TimeZone changed. [changeType=" + timeChangeType.name() + ", eventHandlingEnabled=" + aapsOmnipodManager.isTimeChangeEventEnabled() + "]"); - if (aapsOmnipodManager.isTimeChangeEventEnabled() && podStateManager.isPodRunning()) { + if (podStateManager.isPodRunning()) { aapsLogger.info(LTag.PUMP, "Time, Date and/or TimeZone changed event received and will be consumed by driver."); this.hasTimeDateOrTimeZoneChanged = true; } diff --git a/omnipod/src/main/res/values/strings.xml b/omnipod/src/main/res/values/strings.xml index e2b9ad0b55..3a1034eaa1 100644 --- a/omnipod/src/main/res/values/strings.xml +++ b/omnipod/src/main/res/values/strings.xml @@ -162,6 +162,7 @@ Basal profile is the same, so it will not be set again. Reset RileyLink config Time and/or time zone changed on the Pod + Failed to automatically change time and/or time zone on the Pod. You can manually synchronise the time on the Omnipod tab. %1$s and %2$s %1$s ago Waiting for RileyLink connection...