From 680a3922b8da5a023b98913d62030b832abf0b54 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Sun, 8 Dec 2019 17:16:04 +0100 Subject: [PATCH] Fix bug in alert configurations --- .../comm/action/service/InsertCannulaService.java | 1 - .../pump/omnipod/defs/AlertConfiguration.java | 2 +- .../pump/omnipod/defs/AlertConfigurationFactory.java | 4 ++-- .../pump/omnipod/driver/comm/AapsOmnipodManager.java | 5 +++-- .../message/command/ConfigureAlertsCommandTest.java | 12 +++++------- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/service/InsertCannulaService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/service/InsertCannulaService.java index 2df5305342..4a6c6a4093 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/service/InsertCannulaService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/service/InsertCannulaService.java @@ -26,7 +26,6 @@ public class InsertCannulaService { public StatusResponse executeExpirationRemindersAlertCommand(OmnipodCommunicationService communicationService, PodSessionState podState) { - AlertConfiguration lowReservoirAlertConfiguration = AlertConfigurationFactory.createLowReservoirAlertConfiguration(OmnipodConst.LOW_RESERVOIR_ALERT); DateTime endOfServiceTime = podState.getActivatedAt().plus(OmnipodConst.SERVICE_DURATION); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/AlertConfiguration.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/AlertConfiguration.java index c02255bd99..6c48954cfe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/AlertConfiguration.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/AlertConfiguration.java @@ -63,8 +63,8 @@ public class AlertConfiguration { encodedData = ByteUtil.concat(encodedData, ByteUtil.getBytesFromInt16(durationInMinutes)); } - encodedData = ByteUtil.concat(encodedData, beepType.getValue()); encodedData = ByteUtil.concat(encodedData, beepRepeat.getValue()); + encodedData = ByteUtil.concat(encodedData, beepType.getValue()); return encodedData; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/AlertConfigurationFactory.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/AlertConfigurationFactory.java index de6bcb9f4b..400fe18875 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/AlertConfigurationFactory.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/AlertConfigurationFactory.java @@ -5,12 +5,12 @@ import org.joda.time.Duration; public class AlertConfigurationFactory { public static AlertConfiguration createLowReservoirAlertConfiguration(Double units) { return new AlertConfiguration(AlertType.LOW_RESERVOIR_ALERT, AlertSlot.SLOT4, true, false, Duration.ZERO, - new UnitsRemainingAlertTrigger(units), BeepType.BIP_BEEP_BIP_BEEP_BIP_BEEP_BIP_BEEP, BeepRepeat.EVERY_15_MINUTES); + new UnitsRemainingAlertTrigger(units), BeepType.BIP_BEEP_BIP_BEEP_BIP_BEEP_BIP_BEEP, BeepRepeat.EVERY_MINUTE_FOR_3_MINUTES_REPEAT_EVERY_60_MINUTES); } public static AlertConfiguration createExpirationAdvisoryAlertConfiguration(Duration timeUntilAlert, Duration duration) { return new AlertConfiguration(AlertType.EXPIRATION_ADVISORY_ALERT, AlertSlot.SLOT7, true, false, duration, - new TimerAlertTrigger(timeUntilAlert), BeepType.BIP_BEEP_BIP_BEEP_BIP_BEEP_BIP_BEEP, BeepRepeat.EVERY_60_MINUTES); + new TimerAlertTrigger(timeUntilAlert), BeepType.BIP_BEEP_BIP_BEEP_BIP_BEEP_BIP_BEEP, BeepRepeat.EVERY_MINUTE_FOR_3_MINUTES_REPEAT_EVERY_15_MINUTES); } public static AlertConfiguration createShutdownImminentAlertConfiguration(Duration timeUntilAlert) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java index c4e801de4c..89680c6ebe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.driver.comm; import android.text.TextUtils; +import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.joda.time.DateTime; import org.joda.time.Duration; @@ -92,9 +93,9 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface sendEvent(new EventOmnipodAcknowledgeAlertsChanged()); } } else { - if (pumpStatus.ackAlertsAvailable) { + if (pumpStatus.ackAlertsAvailable || StringUtils.isNotEmpty(pumpStatus.ackAlertsText)) { + pumpStatus.ackAlertsText = null; pumpStatus.ackAlertsAvailable = false; - sendEvent(new EventOmnipodAcknowledgeAlertsChanged()); } } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigureAlertsCommandTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigureAlertsCommandTest.java index a7c1579635..b1df7932f1 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigureAlertsCommandTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigureAlertsCommandTest.java @@ -20,8 +20,6 @@ import static org.junit.Assert.assertArrayEquals; public class ConfigureAlertsCommandTest { @Test public void testEncoding() { - // from https://github.com/ps2/rileylink_ios/blob/master/OmniKitTests/MessageTests.swift - Duration softExpirationTime = Duration.standardHours(72).minus(Duration.standardMinutes(1)); AlertConfiguration alertConfiguration1 = new AlertConfiguration( // AlertType.EXPIRATION_ADVISORY_ALERT, @@ -34,7 +32,7 @@ public class ConfigureAlertsCommandTest { BeepRepeat.EVERY_MINUTE_FOR_15_MINUTES); assertArrayEquals( // - ByteUtil.fromHexString("79a410df0502"), // + ByteUtil.fromHexString("79a410df0205"), // alertConfiguration1.getRawData()); Duration hardExpirationTime = Duration.standardHours(79).minus(Duration.standardMinutes(1)); @@ -49,7 +47,7 @@ public class ConfigureAlertsCommandTest { BeepRepeat.EVERY_MINUTE_FOR_15_MINUTES); assertArrayEquals( // - ByteUtil.fromHexString("280012830602"), // + ByteUtil.fromHexString("280012830206"), // alertConfiguration2.getRawData()); AlertConfiguration alertConfiguration3 = new AlertConfiguration( // @@ -71,7 +69,7 @@ public class ConfigureAlertsCommandTest { Arrays.asList(alertConfiguration1, alertConfiguration2, alertConfiguration3)); assertArrayEquals( // - ByteUtil.fromHexString("1916feb6268b79a410df0502280012830602020f00000202"), // + ByteUtil.fromHexString("1916feb6268b79a410df0205280012830206020f00000202"), // configureAlertsCommand.getRawData()); } @@ -84,8 +82,8 @@ public class ConfigureAlertsCommandTest { false, // Duration.ZERO, // new UnitsRemainingAlertTrigger(10.0), // - BeepType.BEEP_BEEP_BEEP_BEEP, // - BeepRepeat.EVERY_MINUTE_FOR_15_MINUTES); + BeepType.BIP_BEEP_BIP_BEEP_BIP_BEEP_BIP_BEEP, // + BeepRepeat.EVERY_MINUTE_FOR_3_MINUTES_REPEAT_EVERY_60_MINUTES); ConfigureAlertsCommand configureAlertsCommand = new ConfigureAlertsCommand( // 0xae01a66c, //