From aa8e71e0f80f8a00c5949271b8af51ffdb6104f3 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Mon, 26 Oct 2020 15:26:16 +0100 Subject: [PATCH 1/4] Revert "Disable Omnipod plugin for upstream" This reverts commit 00a54b48c7c1c5d2e23ddb48ed4ee3bbea3099b2. --- .github/workflows/gradle-ci-workflow.yaml | 33 +++++++++++++++++++ app/build.gradle | 2 +- .../dependencyInjection/PluginsModule.kt | 7 ++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/gradle-ci-workflow.yaml diff --git a/.github/workflows/gradle-ci-workflow.yaml b/.github/workflows/gradle-ci-workflow.yaml new file mode 100644 index 0000000000..6ec6107b54 --- /dev/null +++ b/.github/workflows/gradle-ci-workflow.yaml @@ -0,0 +1,33 @@ +name: Gradle CI + +on: + - push + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Create NDK path + run: sudo mkdir -p /usr/local/lib/android/sdk/ndk && sudo chmod 777 /usr/local/lib/android/sdk/ndk + - name: Cache NDKs + id: cache-ndk + uses: actions/cache@v2 + with: + path: /usr/local/lib/android/sdk/ndk + key: ${{ runner.os }}-ndk-21.0.6113669-21.1.6352462 + - name: Install NDK 21.0.6113669 + run: echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;21.0.6113669" --sdk_root=${ANDROID_SDK_ROOT} + - name: Install NDK 21.1.6352462 + run: echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;21.1.6352462" --sdk_root=${ANDROID_SDK_ROOT} + - uses: eskatos/gradle-command-action@v1 + with: + arguments: assembleFullDebug + wrapper-cache-enabled: true + dependencies-cache-enabled: true + configuration-cache-enabled: true diff --git a/app/build.gradle b/app/build.gradle index 07139638fc..6ceb4d1e30 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -128,7 +128,7 @@ android { targetSdkVersion 28 multiDexEnabled true versionCode 1500 - version "2.7.0-dev" + version "2.7-omnipod-0.4.1-SNAPSHOT" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt index 892c9c36a8..b28073a055 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt @@ -42,6 +42,7 @@ import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin import info.nightscout.androidaps.plugins.pump.mdi.MDIPlugin import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin +import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin @@ -155,6 +156,12 @@ abstract class PluginsModule { @IntKey(150) abstract fun bindMedtronicPumpPlugin(plugin: MedtronicPumpPlugin): PluginBase + @Binds + @PumpDriver + @IntoMap + @IntKey(155) + abstract fun bindOmnipodPumpPlugin(plugin: OmnipodPumpPlugin): PluginBase + @Binds @NotNSClient @IntoMap From 6c879d6bba6272032b54f252d9cafa3c1f70bf00 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Mon, 26 Oct 2020 21:24:07 +0100 Subject: [PATCH 2/4] Attempt to fix Omnipod DST issues --- omnipod/build.gradle | 1 + .../pump/omnipod/OmnipodPumpPlugin.java | 5 +- .../driver/manager/PodStateManager.java | 6 +-- .../pump/omnipod/driver/util/TimeUtil.java | 21 +++++++++ .../omnipod/ui/OmnipodOverviewFragment.kt | 7 +-- .../omnipod/driver/util/TimeUtilTest.java | 47 +++++++++++++++++++ 6 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/util/TimeUtil.java create mode 100644 omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/util/TimeUtilTest.java diff --git a/omnipod/build.gradle b/omnipod/build.gradle index bea836e961..50f97665c2 100644 --- a/omnipod/build.gradle +++ b/omnipod/build.gradle @@ -108,6 +108,7 @@ dependencies { testImplementation "org.mockito:mockito-core:2.8.47" testImplementation "org.powermock:powermock-api-mockito2:$powermockVersion" testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}" + testImplementation 'joda-time:joda-time:2.10.6' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 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 15c775cc42..ec8626d19f 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 @@ -76,6 +76,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.Activat import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertConfiguration; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.util.TimeUtil; import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPumpValuesChanged; import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodTbrChanged; import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager; @@ -497,9 +498,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, return 0.0d; } - DateTime now = DateTime.now(); - Duration offset = new Duration(now.withTimeAtStartOfDay(), now); - return podStateManager.getBasalSchedule().rateAt(offset); + return podStateManager.getBasalSchedule().rateAt(TimeUtil.toDuration(DateTime.now())); } @Override diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/PodStateManager.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/PodStateManager.java index 764467e15e..34726daffb 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/PodStateManager.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/PodStateManager.java @@ -34,6 +34,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.Omnipod import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.OmnipodCrc; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.schedule.BasalSchedule; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.util.TimeUtil; // TODO add nullchecks on some setters public abstract class PodStateManager { @@ -365,8 +366,7 @@ public abstract class PodStateManager { } public final Duration getScheduleOffset() { - DateTime now = getTime(); - return new Duration(now.withTimeAtStartOfDay(), now); + return TimeUtil.toDuration(getTime()); } public final BasalSchedule getBasalSchedule() { @@ -503,7 +503,7 @@ public abstract class PodStateManager { if (isTempBasalRunningAt(time)) { return getTempBasalAmount(); } - Duration offset = new Duration(time.withTimeAtStartOfDay(), time); + Duration offset = TimeUtil.toDuration(time); return basalSchedule.rateAt(offset); } diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/util/TimeUtil.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/util/TimeUtil.java new file mode 100644 index 0000000000..dc37e42b54 --- /dev/null +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/util/TimeUtil.java @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.driver.util; + +import org.joda.time.DateTime; +import org.joda.time.Duration; + +public final class TimeUtil { + private TimeUtil() { + } + + /** + * @param dateTime DateTime to convert to duration + * @return duration from the start of the day, not taking DST into account + * (thus always having 24 hours in a day, not 23 or 25 in days where DST changes) + */ + public static Duration toDuration(DateTime dateTime) { + if (dateTime == null) { + throw new IllegalArgumentException("dateTime can not be null"); + } + return new Duration(dateTime.toLocalTime().getMillisOfDay()); + } +} diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodOverviewFragment.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodOverviewFragment.kt index 6370f4599d..0aec406de1 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodOverviewFragment.kt +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodOverviewFragment.kt @@ -27,6 +27,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.Activat import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.OmnipodConstants import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager +import info.nightscout.androidaps.plugins.pump.omnipod.driver.util.TimeUtil import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPumpValuesChanged import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.* @@ -54,6 +55,7 @@ import kotlin.collections.ArrayList class OmnipodOverviewFragment : DaggerFragment() { companion object { + private val REFRESH_INTERVAL_MILLIS = 15 * 1000L // 15 seconds private val PLACEHOLDER = "-" // 15 seconds } @@ -278,11 +280,9 @@ class OmnipodOverviewFragment : DaggerFragment() { errors.add(resourceHelper.gs(R.string.omnipod_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name)) } - val now = DateTime.now() - // base basal rate omnipod_overview_base_basal_rate.text = if (podStateManager.isPodActivationCompleted) { - resourceHelper.gs(R.string.pump_basebasalrate, omnipodPumpPlugin.model().determineCorrectBasalSize(podStateManager.basalSchedule.rateAt(Duration(now.withTimeAtStartOfDay(), now)))) + resourceHelper.gs(R.string.pump_basebasalrate, omnipodPumpPlugin.model().determineCorrectBasalSize(podStateManager.basalSchedule.rateAt(TimeUtil.toDuration(DateTime.now())))) } else { PLACEHOLDER } @@ -598,6 +598,7 @@ class OmnipodOverviewFragment : DaggerFragment() { } inner class DisplayResultDialogCallback(private val errorMessagePrefix: String, private val withSoundOnError: Boolean) : Callback() { + private var messageOnSuccess: String? = null override fun run() { diff --git a/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/util/TimeUtilTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/util/TimeUtilTest.java new file mode 100644 index 0000000000..49ee7c02ba --- /dev/null +++ b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/util/TimeUtilTest.java @@ -0,0 +1,47 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.driver.util; + +import net.danlew.android.joda.JodaTimeAndroid; + +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; + +public class TimeUtilTest { + + @Before + public void setUp() { + DateTimeZone.setDefault(DateTimeZone.forID("Europe/Amsterdam")); + } + + @Test + public void testDateTimeToDuration() { + DateTime dateTime = new DateTime(1991, 8, 13, 23, 5, 1); + + assertEquals(83101, TimeUtil.toDuration(dateTime).getStandardSeconds()); + } + + @Test + public void testDateTimeToDurationAtDstChange() { + DateTime dateTime = new DateTime(2020, 10, 25, 23, 5, 1); + + assertEquals(83101, TimeUtil.toDuration(dateTime).getStandardSeconds()); + } + + @Test + public void testDateTimeToDurationAtDstReverseChange() { + DateTime dateTime = new DateTime(2020, 3, 29, 23, 5, 1); + + assertEquals(83101, TimeUtil.toDuration(dateTime).getStandardSeconds()); + } + + @Test + public void testDateTimeToDurationWithNullDateTime() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> TimeUtil.toDuration(null)); + assertEquals("dateTime can not be null", ex.getMessage()); + } + +} \ No newline at end of file From 3cd0fd22e440133513d84a4721d87d04111f8182 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Mon, 26 Oct 2020 21:53:56 +0100 Subject: [PATCH 3/4] Add test --- .../plugins/pump/omnipod/driver/util/TimeUtilTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/util/TimeUtilTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/util/TimeUtilTest.java index 49ee7c02ba..6165de683d 100644 --- a/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/util/TimeUtilTest.java +++ b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/util/TimeUtilTest.java @@ -1,7 +1,5 @@ package info.nightscout.androidaps.plugins.pump.omnipod.driver.util; -import net.danlew.android.joda.JodaTimeAndroid; - import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.junit.Before; @@ -38,6 +36,13 @@ public class TimeUtilTest { assertEquals(83101, TimeUtil.toDuration(dateTime).getStandardSeconds()); } + @Test + public void testDateTimeInOtherZone() { + DateTime dateTime = new DateTime(2020, 3, 29, 23, 5, 1, DateTimeZone.forID("America/Los_Angeles")); + + assertEquals(83101, TimeUtil.toDuration(dateTime).getStandardSeconds()); + } + @Test public void testDateTimeToDurationWithNullDateTime() { IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> TimeUtil.toDuration(null)); From da8c231743a27a1f2f5aca3c2b7057920572cab5 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Wed, 28 Oct 2020 14:54:55 +0100 Subject: [PATCH 4/4] Disable Omnipod plugin for upstream This reverts commit aa8e71e0f80f8a00c5949271b8af51ffdb6104f3. --- .github/workflows/gradle-ci-workflow.yaml | 33 ------------------- app/build.gradle | 2 +- .../dependencyInjection/PluginsModule.kt | 7 ---- 3 files changed, 1 insertion(+), 41 deletions(-) delete mode 100644 .github/workflows/gradle-ci-workflow.yaml diff --git a/.github/workflows/gradle-ci-workflow.yaml b/.github/workflows/gradle-ci-workflow.yaml deleted file mode 100644 index 6ec6107b54..0000000000 --- a/.github/workflows/gradle-ci-workflow.yaml +++ /dev/null @@ -1,33 +0,0 @@ -name: Gradle CI - -on: - - push - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Create NDK path - run: sudo mkdir -p /usr/local/lib/android/sdk/ndk && sudo chmod 777 /usr/local/lib/android/sdk/ndk - - name: Cache NDKs - id: cache-ndk - uses: actions/cache@v2 - with: - path: /usr/local/lib/android/sdk/ndk - key: ${{ runner.os }}-ndk-21.0.6113669-21.1.6352462 - - name: Install NDK 21.0.6113669 - run: echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;21.0.6113669" --sdk_root=${ANDROID_SDK_ROOT} - - name: Install NDK 21.1.6352462 - run: echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;21.1.6352462" --sdk_root=${ANDROID_SDK_ROOT} - - uses: eskatos/gradle-command-action@v1 - with: - arguments: assembleFullDebug - wrapper-cache-enabled: true - dependencies-cache-enabled: true - configuration-cache-enabled: true diff --git a/app/build.gradle b/app/build.gradle index 6ceb4d1e30..07139638fc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -128,7 +128,7 @@ android { targetSdkVersion 28 multiDexEnabled true versionCode 1500 - version "2.7-omnipod-0.4.1-SNAPSHOT" + version "2.7.0-dev" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt index b28073a055..892c9c36a8 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt @@ -42,7 +42,6 @@ import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin import info.nightscout.androidaps.plugins.pump.mdi.MDIPlugin import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin -import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin @@ -156,12 +155,6 @@ abstract class PluginsModule { @IntKey(150) abstract fun bindMedtronicPumpPlugin(plugin: MedtronicPumpPlugin): PluginBase - @Binds - @PumpDriver - @IntoMap - @IntKey(155) - abstract fun bindOmnipodPumpPlugin(plugin: OmnipodPumpPlugin): PluginBase - @Binds @NotNSClient @IntoMap