This commit is contained in:
Milos Kozak 2020-11-07 16:58:00 +01:00
commit 1b0483d476
6 changed files with 83 additions and 9 deletions

View file

@ -108,6 +108,7 @@ dependencies {
testImplementation "org.mockito:mockito-core:2.8.47" testImplementation "org.mockito:mockito-core:2.8.47"
testImplementation "org.powermock:powermock-api-mockito2:$powermockVersion" testImplementation "org.powermock:powermock-api-mockito2:$powermockVersion"
testImplementation "org.powermock:powermock-module-junit4:${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.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

View file

@ -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.AlertConfiguration;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus; 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.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.EventOmnipodPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodTbrChanged; import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodTbrChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager;
@ -497,9 +498,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
return 0.0d; return 0.0d;
} }
DateTime now = DateTime.now(); return podStateManager.getBasalSchedule().rateAt(TimeUtil.toDuration(DateTime.now()));
Duration offset = new Duration(now.withTimeAtStartOfDay(), now);
return podStateManager.getBasalSchedule().rateAt(offset);
} }
@Override @Override

View file

@ -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.OmnipodCrc;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus; 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.definition.schedule.BasalSchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.util.TimeUtil;
// TODO add nullchecks on some setters // TODO add nullchecks on some setters
public abstract class PodStateManager { public abstract class PodStateManager {
@ -365,8 +366,7 @@ public abstract class PodStateManager {
} }
public final Duration getScheduleOffset() { public final Duration getScheduleOffset() {
DateTime now = getTime(); return TimeUtil.toDuration(getTime());
return new Duration(now.withTimeAtStartOfDay(), now);
} }
public final BasalSchedule getBasalSchedule() { public final BasalSchedule getBasalSchedule() {
@ -503,7 +503,7 @@ public abstract class PodStateManager {
if (isTempBasalRunningAt(time)) { if (isTempBasalRunningAt(time)) {
return getTempBasalAmount(); return getTempBasalAmount();
} }
Duration offset = new Duration(time.withTimeAtStartOfDay(), time); Duration offset = TimeUtil.toDuration(time);
return basalSchedule.rateAt(offset); return basalSchedule.rateAt(offset);
} }

View file

@ -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());
}
}

View file

@ -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.OmnipodConstants
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus 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.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.EventOmnipodPumpValuesChanged
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager
import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.* import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.*
@ -54,6 +55,7 @@ import kotlin.collections.ArrayList
class OmnipodOverviewFragment : DaggerFragment() { class OmnipodOverviewFragment : DaggerFragment() {
companion object { companion object {
private val REFRESH_INTERVAL_MILLIS = 15 * 1000L // 15 seconds private val REFRESH_INTERVAL_MILLIS = 15 * 1000L // 15 seconds
private val PLACEHOLDER = "-" // 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)) errors.add(resourceHelper.gs(R.string.omnipod_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name))
} }
val now = DateTime.now()
// base basal rate // base basal rate
omnipod_overview_base_basal_rate.text = if (podStateManager.isPodActivationCompleted) { 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 { } else {
PLACEHOLDER PLACEHOLDER
} }
@ -598,6 +598,7 @@ class OmnipodOverviewFragment : DaggerFragment() {
} }
inner class DisplayResultDialogCallback(private val errorMessagePrefix: String, private val withSoundOnError: Boolean) : Callback() { inner class DisplayResultDialogCallback(private val errorMessagePrefix: String, private val withSoundOnError: Boolean) : Callback() {
private var messageOnSuccess: String? = null private var messageOnSuccess: String? = null
override fun run() { override fun run() {

View file

@ -0,0 +1,52 @@
package info.nightscout.androidaps.plugins.pump.omnipod.driver.util;
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 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));
assertEquals("dateTime can not be null", ex.getMessage());
}
}