Add pod expiration date and expose calculateBolusDuration method in OmnipodManager
This commit is contained in:
parent
27cf316dc7
commit
40487ffb06
|
@ -250,10 +250,6 @@ public class OmnipodManager {
|
||||||
return podState == null ? "null" : podState.toString();
|
return podState == null ? "null" : podState.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Duration calculateBolusDuration(double units, double deliveryRate) {
|
|
||||||
return Duration.standardSeconds((long) Math.ceil(units / deliveryRate));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void executeDelayed(Runnable r, Duration timeout) {
|
private void executeDelayed(Runnable r, Duration timeout) {
|
||||||
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
|
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
|
||||||
scheduledExecutorService.schedule(r, timeout.getMillis(), TimeUnit.MILLISECONDS);
|
scheduledExecutorService.schedule(r, timeout.getMillis(), TimeUnit.MILLISECONDS);
|
||||||
|
@ -318,6 +314,18 @@ public class OmnipodManager {
|
||||||
return CommandVerificationResult.SUCCESS;
|
return CommandVerificationResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isLoggingEnabled() {
|
||||||
|
return L.isEnabled(L.PUMP);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Duration calculateBolusDuration(double units) {
|
||||||
|
return calculateBolusDuration(units, OmnipodConst.POD_BOLUS_DELIVERY_RATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Duration calculateBolusDuration(double units, double deliveryRate) {
|
||||||
|
return Duration.standardSeconds((long) Math.ceil(units / deliveryRate));
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isCertainFailure(Exception ex) {
|
public static boolean isCertainFailure(Exception ex) {
|
||||||
return ex instanceof OmnipodException && ((OmnipodException) ex).isCertainFailure();
|
return ex instanceof OmnipodException && ((OmnipodException) ex).isCertainFailure();
|
||||||
}
|
}
|
||||||
|
@ -327,8 +335,4 @@ public class OmnipodManager {
|
||||||
CERTAIN_FAILURE,
|
CERTAIN_FAILURE,
|
||||||
UNCERTAIN_FAILURE
|
UNCERTAIN_FAILURE
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLoggingEnabled() {
|
|
||||||
return L.isEnabled(L.PUMP);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.defs.state;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
import org.joda.time.DateTimeComparator;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
|
|
||||||
|
@ -22,11 +23,13 @@ import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDevice
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmniCRC;
|
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmniCRC;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
|
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
|
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
|
||||||
public class PodSessionState extends PodState {
|
public class PodSessionState extends PodState {
|
||||||
private final Map<AlertSlot, AlertType> configuredAlerts;
|
private final Map<AlertSlot, AlertType> configuredAlerts;
|
||||||
private final DateTime activatedAt;
|
private DateTime activatedAt;
|
||||||
|
private DateTime expiresAt;
|
||||||
private final FirmwareVersion piVersion;
|
private final FirmwareVersion piVersion;
|
||||||
private final FirmwareVersion pmVersion;
|
private final FirmwareVersion pmVersion;
|
||||||
private final int lot;
|
private final int lot;
|
||||||
|
@ -80,6 +83,15 @@ public class PodSessionState extends PodState {
|
||||||
return activatedAt;
|
return activatedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DateTime getExpiresAt() {
|
||||||
|
return expiresAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExpiryDateAsString() {
|
||||||
|
return expiresAt == null ? "???" : DateUtil.dateAndTimeString(expiresAt.toDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public FirmwareVersion getPiVersion() {
|
public FirmwareVersion getPiVersion() {
|
||||||
return piVersion;
|
return piVersion;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +145,7 @@ public class PodSessionState extends PodState {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasActiveAlerts() {
|
public boolean hasActiveAlerts() {
|
||||||
return activeAlerts != null;
|
return activeAlerts != null && activeAlerts.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AlertSet getActiveAlerts() {
|
public AlertSet getActiveAlerts() {
|
||||||
|
@ -194,6 +206,15 @@ public class PodSessionState extends PodState {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateFromStatusResponse(StatusResponse statusResponse) {
|
public void updateFromStatusResponse(StatusResponse statusResponse) {
|
||||||
|
DateTime activatedAtCalculated = getTime().minus(statusResponse.getTimeActive());
|
||||||
|
if(activatedAt == null) {
|
||||||
|
activatedAt = activatedAtCalculated;
|
||||||
|
}
|
||||||
|
DateTime expiresAtCalculated = activatedAtCalculated.plus(OmnipodConst.NOMINAL_POD_LIFE);
|
||||||
|
if(expiresAt == null || expiresAtCalculated.isBefore(expiresAt) || expiresAtCalculated.isAfter(expiresAt.plusMinutes(1))) {
|
||||||
|
expiresAt = expiresAtCalculated;
|
||||||
|
}
|
||||||
|
|
||||||
suspended = (statusResponse.getDeliveryStatus() == DeliveryStatus.SUSPENDED);
|
suspended = (statusResponse.getDeliveryStatus() == DeliveryStatus.SUSPENDED);
|
||||||
activeAlerts = statusResponse.getAlerts();
|
activeAlerts = statusResponse.getAlerts();
|
||||||
lastDeliveryStatus = statusResponse.getDeliveryStatus();
|
lastDeliveryStatus = statusResponse.getDeliveryStatus();
|
||||||
|
@ -206,13 +227,6 @@ public class PodSessionState extends PodState {
|
||||||
OmnipodUtil.setPodSessionState(this);
|
OmnipodUtil.setPodSessionState(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExpiryDateAsString() {
|
|
||||||
// TODO
|
|
||||||
return "???";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "PodSessionState{" +
|
return "PodSessionState{" +
|
||||||
|
|
|
@ -36,9 +36,9 @@ public class OmnipodConst {
|
||||||
public static final int DEFAULT_ADDRESS = 0xffffffff;
|
public static final int DEFAULT_ADDRESS = 0xffffffff;
|
||||||
|
|
||||||
public static final Duration SERVICE_DURATION = Duration.standardHours(80);
|
public static final Duration SERVICE_DURATION = Duration.standardHours(80);
|
||||||
public static final Duration EXPIRATION_ALERT_WINDOW = Duration.standardHours(2);
|
|
||||||
public static final Duration EXPIRATION_ADVISORY_WINDOW = Duration.standardHours(2);
|
public static final Duration EXPIRATION_ADVISORY_WINDOW = Duration.standardHours(2);
|
||||||
public static final Duration END_OF_SERVICE_IMMINENT_WINDOW = Duration.standardHours(1);
|
public static final Duration END_OF_SERVICE_IMMINENT_WINDOW = Duration.standardHours(1);
|
||||||
|
public static final Duration NOMINAL_POD_LIFE = SERVICE_DURATION.minus(END_OF_SERVICE_IMMINENT_WINDOW).minus(EXPIRATION_ADVISORY_WINDOW);
|
||||||
|
|
||||||
public static final double POD_PRIME_BOLUS_UNITS = 2.6;
|
public static final double POD_PRIME_BOLUS_UNITS = 2.6;
|
||||||
public static final double POD_CANNULA_INSERTION_BOLUS_UNITS = 0.5;
|
public static final double POD_CANNULA_INSERTION_BOLUS_UNITS = 0.5;
|
||||||
|
|
Loading…
Reference in a new issue