Remove OmnipodPumpStatus

This commit is contained in:
Bart Sopers 2020-08-23 10:58:48 +02:00
parent c52987ab6c
commit 2745aed31a
15 changed files with 237 additions and 483 deletions

View file

@ -23,7 +23,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodAcknowledgeAlertsChanged
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil
@ -163,10 +162,6 @@ class OmnipodFragment : DaggerFragment() {
.toObservable(EventOmnipodPumpValuesChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateOmipodUiElements() }, { fabricPrivacy.logException(it) })
disposables += rxBus
.toObservable(EventOmnipodAcknowledgeAlertsChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateAcknowledgeAlertsUiElements() }, { fabricPrivacy.logException(it) })
disposables += rxBus
.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())

View file

@ -11,13 +11,13 @@ import android.os.SystemClock;
import androidx.annotation.NonNull;
import org.jetbrains.annotations.NotNull;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import javax.inject.Inject;
@ -53,8 +53,6 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNo
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
@ -70,7 +68,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCustomActionT
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPumpPluginInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodStatusRequest;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIComm;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUITask;
@ -99,7 +96,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
private final PodStateManager podStateManager;
private final RileyLinkServiceData rileyLinkServiceData;
private final ServiceTaskExecutor serviceTaskExecutor;
private final OmnipodPumpStatus omnipodPumpStatus;
private final AapsOmnipodManager aapsOmnipodManager;
private final OmnipodUtil omnipodUtil;
private final AAPSLogger aapsLogger;
@ -129,10 +125,9 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
private RileyLinkOmnipodService rileyLinkOmnipodService;
private boolean busy = false;
private int timeChangeRetries;
private Profile currentProfile;
private long nextPodCheck;
private boolean sentIdToFirebase;
private long lastConnectionMillis;
private long lastConnectionTimeMillis;
@Inject
public OmnipodPumpPlugin(
@ -143,7 +138,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
ResourceHelper resourceHelper,
ActivePluginProvider activePlugin,
SP sp,
OmnipodPumpStatus omnipodPumpStatus,
PodStateManager podStateManager,
AapsOmnipodManager aapsOmnipodManager,
CommandQueueProvider commandQueue,
@ -172,7 +166,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
this.podStateManager = podStateManager;
this.rileyLinkServiceData = rileyLinkServiceData;
this.serviceTaskExecutor = serviceTaskExecutor;
this.omnipodPumpStatus = omnipodPumpStatus;
this.aapsOmnipodManager = aapsOmnipodManager;
this.omnipodUtil = omnipodUtil;
@ -222,7 +215,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
// When PodStateManager is created, which causes an IllegalArgumentException for DateTimeZones not being recognized
podStateManager.loadPodState();
lastConnectionMillis = sp.getLong(
lastConnectionTimeMillis = sp.getLong(
RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
Intent intent = new Intent(context, RileyLinkOmnipodService.class);
@ -312,17 +305,37 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
}
}
public PumpStatus getPumpStatusData() {
return this.omnipodPumpStatus;
}
private boolean isServiceSet() {
return rileyLinkOmnipodService != null;
// TODO is this correct?
@Override
public boolean isInitialized() {
return isConnected() && podStateManager.isPodActivationCompleted();
}
@Override
public boolean isInitialized() {
return isServiceSet() && isInitialized;
public boolean isConnected() {
return rileyLinkOmnipodService != null && rileyLinkOmnipodService.isInitialized();
}
@Override
public boolean isConnecting() {
return rileyLinkOmnipodService == null || !rileyLinkOmnipodService.isInitialized();
}
@Override
public boolean isHandshakeInProgress() {
if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "isHandshakeInProgress [OmnipodPumpPlugin] - default (empty) implementation.");
return false;
}
// TODO is this correct?
@Override
public boolean isBusy() {
return busy || rileyLinkOmnipodService == null || !podStateManager.isPodRunning();
}
@Override public void setBusy(boolean busy) {
this.busy = busy;
}
@Override
@ -331,16 +344,24 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
}
@Override
public boolean isBusy() {
if (isServiceSet()) {
return busy || !podStateManager.isPodRunning();
public void finishHandshaking() {
if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "finishHandshaking [OmnipodPumpPlugin] - default (empty) implementation.");
}
return false;
@Override public void connect(String reason) {
if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "connect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason);
}
@Override public void setBusy(boolean busy) {
this.busy = busy;
@Override public void disconnect(String reason) {
if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "disconnect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason);
}
@Override public void stopConnecting() {
if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "stopConnecting [PumpPluginAbstract] - default (empty) implementation.");
}
@Override
@ -371,7 +392,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
* For getting the last time a command was successfully executed, use PodStateManager.getLastSuccessfulCommunication
*/
@Override public long getLastConnectionTimeMillis() {
return omnipodPumpStatus.lastConnection;
return lastConnectionTimeMillis;
}
// Required by RileyLinkPumpDevice interface.
@ -383,45 +404,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
* For setting the last time a command was successfully executed, use PodStateManager.setLastSuccessfulCommunication
*/
@Override public void setLastCommunicationToNow() {
omnipodPumpStatus.setLastCommunicationToNow();
}
@Override
public boolean isConnected() {
return isServiceSet() && rileyLinkOmnipodService.isInitialized();
}
@Override
public boolean isConnecting() {
return !isServiceSet() || !rileyLinkOmnipodService.isInitialized();
}
@Override
public boolean isHandshakeInProgress() {
if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "isHandshakeInProgress [OmnipodPumpPlugin] - default (empty) implementation.");
return false;
}
@Override
public void finishHandshaking() {
if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "finishHandshaking [OmnipodPumpPlugin] - default (empty) implementation.");
}
@Override public void connect(String reason) {
if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "connect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason);
}
@Override public void disconnect(String reason) {
if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "disconnect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason);
}
@Override public void stopConnecting() {
if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "stopConnecting [PumpPluginAbstract] - default (empty) implementation.");
lastConnectionTimeMillis = System.currentTimeMillis();
}
// TODO seems that this abused to squeeze commands in the queue
@ -490,14 +473,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
@NotNull
@Override
public PumpEnactResult setNewBasalProfile(Profile profile) {
// this shouldn't be needed, but let's do check if profile setting we are setting is same as current one
if (this.currentProfile != null && this.currentProfile.areProfileBasalPatternsSame(profile)) {
return new PumpEnactResult(getInjector()) //
.success(true) //
.enacted(false) //
.comment(resourceHelper.gs(R.string.omnipod_cmd_basal_profile_not_set_is_same));
}
setRefreshButtonEnabled(false);
OmnipodUITask responseTask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.SetBasalProfile,
@ -508,8 +483,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
aapsLogger.info(LTag.PUMP, "Basal Profile was set: " + result.success);
if (result.success) {
this.currentProfile = profile;
Notification notification = new Notification(Notification.PROFILE_SET_OK,
resourceHelper.gs(R.string.profile_set_ok),
Notification.INFO, 60);
@ -526,38 +499,42 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
@Override
public boolean isThisProfileSet(Profile profile) {
// TODO status was not yet read from pod
// TODO maybe not possible, need to see how we will handle that
if (currentProfile == null) {
this.currentProfile = profile;
return true;
if (!podStateManager.isPodActivationCompleted()) {
return true; // Return true, because otherwise AAPS will try setting a Basal schedule while no Pod is active
}
return (currentProfile.areProfileBasalPatternsSame(profile));
return podStateManager.getBasalSchedule().equals(AapsOmnipodManager.mapProfileToBasalSchedule(profile));
}
@Override
public long lastDataTime() {
return lastConnectionMillis;
return lastConnectionTimeMillis;
}
@Override
public double getBaseBasalRate() {
if (currentProfile != null) {
int hour = (new GregorianCalendar()).get(Calendar.HOUR_OF_DAY);
return currentProfile.getBasalTimeFromMidnight(DateTimeUtil.getTimeInS(hour * 60));
} else {
if (!podStateManager.isPodRunning()) {
return 0.0d;
}
DateTime now = DateTime.now();
Duration offset = new Duration(now.withTimeAtStartOfDay(), now);
return podStateManager.getBasalSchedule().rateAt(offset);
}
@Override
public double getReservoirLevel() {
return omnipodPumpStatus.reservoirRemainingUnits;
if (!podStateManager.isPodRunning()) {
return 0.0d;
}
Double reservoirLevel = podStateManager.getReservoirLevel();
return reservoirLevel == null ? 75.0 : reservoirLevel;
}
@Override
public int getBatteryLevel() {
if (!podStateManager.isPodRunning()) {
return 0;
}
return 75;
}
@ -605,21 +582,22 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
// if enforceNew===true current temp basal is canceled and new TBR set (duration is prolonged),
// if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer
durationInMinutes, Profile profile, boolean enforceNew) {
setRefreshButtonEnabled(false);
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes);
// read current TBR
TempBasalPair tbrCurrent = readTBR();
TemporaryBasal tbrCurrent = readTBR();
if (tbrCurrent != null) {
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute: Current Basal: duration: {} min, rate={}",
tbrCurrent.getDurationMinutes(), tbrCurrent.getInsulinRate());
tbrCurrent.durationInMinutes, tbrCurrent.absoluteRate);
}
if (tbrCurrent != null && !enforceNew) {
if (Round.isSame(tbrCurrent.getInsulinRate(), absoluteRate)) {
if (Round.isSame(tbrCurrent.absoluteRate, absoluteRate)) {
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - No enforceNew and same rate. Exiting.");
finishAction("TBR");
return new PumpEnactResult(getInjector()).success(true).enacted(false);
@ -642,12 +620,14 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
return result;
}
@NotNull @Override public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
@NotNull @Override public PumpEnactResult setTempBasalPercent(Integer percent, Integer
durationInMinutes, Profile profile, boolean enforceNew) {
aapsLogger.debug(LTag.PUMP, "setTempBasalPercent [OmnipodPumpPlugin] - Not implemented.");
return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver);
}
@NotNull @Override public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
@NotNull @Override public PumpEnactResult setExtendedBolus(Double insulin, Integer
durationInMinutes) {
aapsLogger.debug(LTag.PUMP, "setExtendedBolus [OmnipodPumpPlugin] - Not implemented.");
return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver);
}
@ -656,7 +636,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
setRefreshButtonEnabled(false);
TempBasalPair tbrCurrent = readTBR();
TemporaryBasal tbrCurrent = readTBR();
if (tbrCurrent == null) {
aapsLogger.info(LTag.PUMP, "cancelTempBasal - TBR already canceled.");
@ -688,10 +668,11 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver);
}
// TODO improve (i8n and more)
@NonNull @Override
public JSONObject getJSONStatus(Profile profile, String profileName, String version) {
if ((getPumpStatusData().lastConnection + 60 * 60 * 1000L) < System.currentTimeMillis()) {
if (!podStateManager.isPodActivationCompleted() || lastConnectionTimeMillis + 60 * 60 * 1000L < System.currentTimeMillis()) {
return new JSONObject();
}
@ -700,15 +681,18 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
JSONObject status = new JSONObject();
JSONObject extended = new JSONObject();
try {
battery.put("percent", getPumpStatusData().batteryRemaining);
status.put("status", getPumpStatusData().pumpStatusType != null ? getPumpStatusData().pumpStatusType.getStatus() : "normal");
status.put("status", podStateManager.isPodRunning() ? "normal" : "error");
status.put("timestamp", DateUtil.toISOString(new Date()));
battery.put("percent", getBatteryLevel());
extended.put("Version", version);
try {
extended.put("ActiveProfile", profileName);
} catch (Exception ignored) {
}
TemporaryBasal tb = activePlugin.getActiveTreatments().getTempBasalFromHistory(System.currentTimeMillis());
TemporaryBasal tb = activePlugin.getActiveTreatments().getRealTempBasalFromHistory(System.currentTimeMillis());
if (tb != null) {
extended.put("TempBasalAbsoluteRate",
tb.tempBasalConvertedToAbsolute(System.currentTimeMillis(), profile));
@ -728,10 +712,10 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
pump.put("battery", battery);
pump.put("status", status);
pump.put("extended", extended);
pump.put("reservoir", getPumpStatusData().reservoirRemainingUnits);
pump.put("reservoir", getReservoirLevel());
pump.put("clock", DateUtil.toISOString(new Date()));
} catch (JSONException e) {
aapsLogger.error("Unhandled exception", e);
aapsLogger.error(LTag.PUMP, "Unhandled exception", e);
}
return pump;
}
@ -758,15 +742,18 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
// FIXME i18n, null checks: iob, TDD
@NonNull @Override
public String shortStatus(boolean veryShort) {
if (!podStateManager.isPodActivationCompleted()) {
return "No active pod";
}
String ret = "";
if (getPumpStatusData().lastConnection != 0) {
long agoMsec = System.currentTimeMillis() - getPumpStatusData().lastConnection;
if (lastConnectionTimeMillis != 0) {
long agoMsec = System.currentTimeMillis() - lastConnectionTimeMillis;
int agoMin = (int) (agoMsec / 60d / 1000d);
ret += "LastConn: " + agoMin + " min ago\n";
}
if (getPumpStatusData().lastBolusTime != null && getPumpStatusData().lastBolusTime.getTime() != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(getPumpStatusData().lastBolusAmount) + "U @" + //
android.text.format.DateFormat.format("HH:mm", getPumpStatusData().lastBolusTime) + "\n";
if (podStateManager.getLastBolusStartTime() != null) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(podStateManager.getLastBolusAmount()) + "U @" + //
android.text.format.DateFormat.format("HH:mm", podStateManager.getLastBolusStartTime().toDate()) + "\n";
}
TemporaryBasal activeTemp = activePlugin.getActiveTreatments().getRealTempBasalFromHistory(System.currentTimeMillis());
if (activeTemp != null) {
@ -777,9 +764,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
if (activeExtendedBolus != null) {
ret += "Extended: " + activeExtendedBolus.toString() + "\n";
}
ret += "IOB: " + getPumpStatusData().iob + "U\n";
ret += "Reserv: " + DecimalFormatter.to0Decimal(getPumpStatusData().reservoirRemainingUnits) + "U\n";
ret += "Batt: " + getPumpStatusData().batteryRemaining + "\n";
ret += "Reserv: " + DecimalFormatter.to0Decimal(getReservoirLevel()) + "U\n";
ret += "Batt: " + getBatteryLevel();
return ret;
}
@ -830,17 +816,18 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
@Override
public boolean isUnreachableAlertTimeoutExceeded(long unreachableTimeoutMilliseconds) {
long rileyLinkInitializationTimeout = 3 * 60 * 1000L; // 3 minutes
if (podStateManager.isPodRunning() && podStateManager.getLastSuccessfulCommunication() != null) { // Null check for backwards compatibility
if (podStateManager.isPodActivationCompleted() && podStateManager.getLastSuccessfulCommunication() != null) { // Null check for backwards compatibility
if (podStateManager.getLastSuccessfulCommunication().getMillis() + unreachableTimeoutMilliseconds < System.currentTimeMillis()) {
// TODO update comment
// We exceeded the alert threshold, and either our last command failed or we cannot reach the RL
// We should show an alert
return (podStateManager.getLastFailedCommunication() != null && podStateManager.getLastSuccessfulCommunication().isBefore(podStateManager.getLastFailedCommunication())) ||
// Don't trigger an alert when we exceeded the thresholds, but the last communication was successful & the RL is reachable
// This happens when we simply didn't need to send any commands to the pump
return !podStateManager.isPodRunning() ||
(podStateManager.getLastFailedCommunication() != null && podStateManager.getLastSuccessfulCommunication().isBefore(podStateManager.getLastFailedCommunication())) ||
rileyLinkServiceData.rileyLinkServiceState.isError() ||
// The below clause is a hack for working around the RL service state forever staying in connecting state on startup if the RL is switched off / unreachable
(rileyLinkServiceData.getRileyLinkServiceState().isConnecting() && rileyLinkServiceData.getLastServiceStateChange() + rileyLinkInitializationTimeout < System.currentTimeMillis());
// Don't trigger an alert when we exceeded the thresholds, but the last communication was successful & the RL is reachable
// This happens when we simply didn't need to send any commands to the pump
}
}
@ -875,6 +862,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
rxBus.send(new EventOmnipodRefreshButtonState(enabled));
}
// FIXME strange
private void initializePump(boolean realInit) {
setRefreshButtonEnabled(false);
@ -937,16 +925,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
sp.putLong(statsKey, currentCount);
}
protected TempBasalPair readTBR() {
// TODO we can do it like this or read status from pod ??
if (omnipodPumpStatus.tempBasalEnd < System.currentTimeMillis()) {
// TBR done
omnipodPumpStatus.clearTemporaryBasal();
return null;
}
return omnipodPumpStatus.getTemporaryBasal();
protected TemporaryBasal readTBR() {
return activePlugin.getActiveTreatments().getTempBasalFromHistory(System.currentTimeMillis());
}
protected void finishAction(String overviewKey) {

View file

@ -2,9 +2,11 @@ package info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule;
import org.joda.time.Duration;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class BasalSchedule {
private final List<BasalScheduleEntry> entries;
@ -15,7 +17,7 @@ public class BasalSchedule {
} else if (!entries.get(0).getStartTime().isEqual(Duration.ZERO)) {
throw new IllegalArgumentException("First basal schedule entry should have 0 offset");
}
this.entries = entries;
this.entries = new ArrayList<>(entries);
}
public double rateAt(Duration offset) {
@ -91,6 +93,17 @@ public class BasalSchedule {
'}';
}
@Override public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BasalSchedule that = (BasalSchedule) o;
return entries.equals(that.entries);
}
@Override public int hashCode() {
return Objects.hash(entries);
}
public static class BasalScheduleDurationEntry {
private final double rate;
private final Duration duration;

View file

@ -2,6 +2,8 @@ package info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule;
import org.joda.time.Duration;
import java.util.Objects;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
public class BasalScheduleEntry {
@ -37,4 +39,16 @@ public class BasalScheduleEntry {
", startTime=" + startTime.getStandardSeconds() + "s" +
'}';
}
@Override public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BasalScheduleEntry that = (BasalScheduleEntry) o;
return Double.compare(that.rate, rate) == 0 &&
Objects.equals(startTime, that.startTime);
}
@Override public int hashCode() {
return Objects.hash(rate, startTime);
}
}

View file

@ -31,6 +31,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedu
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmniCRC;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
// TODO add nullchecks on some setters
public abstract class PodStateManager {
private final AAPSLogger aapsLogger;

View file

@ -1,110 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.driver;
import java.util.Arrays;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
/**
* Created by andy on 4.8.2019
*/
@Singleton
@Deprecated
public class OmnipodPumpStatus extends PumpStatus {
// TODO remove all fields that can also be obtained via PodStateManager
// We can probably get rid of this class altogether
private final SP sp;
public boolean inPreInit = true;
// statuses
public double currentBasal = 0;
public long tempBasalStart;
public long tempBasalEnd;
public Double tempBasalAmount = 0.0d;
public Integer tempBasalLength;
public long tempBasalPumpId;
public PumpType pumpType;
@Inject
public OmnipodPumpStatus(SP sp) {
super(PumpType.Insulet_Omnipod);
this.sp = sp;
initSettings();
}
@Override
public void initSettings() {
this.activeProfileName = "";
this.reservoirRemainingUnits = 75d;
this.batteryRemaining = 75;
this.lastConnection = sp.getLong(OmnipodConst.Statistics.LastGoodPumpCommunicationTime, 0L);
this.pumpType = PumpType.Insulet_Omnipod;
}
@Override
public String getErrorInfo() {
return null;
}
public void clearTemporaryBasal() {
this.tempBasalStart = 0L;
this.tempBasalEnd = 0L;
this.tempBasalAmount = 0.0d;
this.tempBasalLength = 0;
}
public TempBasalPair getTemporaryBasal() {
TempBasalPair tbr = new TempBasalPair();
tbr.setDurationMinutes(tempBasalLength);
tbr.setInsulinRate(tempBasalAmount);
tbr.setStartTime(tempBasalStart);
tbr.setEndTime(tempBasalEnd);
return tbr;
}
@Override
public String toString() {
return "OmnipodPumpStatus{" +
"inPreInit=" + inPreInit +
", tempBasalStart=" + tempBasalStart +
", tempBasalEnd=" + tempBasalEnd +
", tempBasalAmount=" + tempBasalAmount +
", tempBasalLength=" + tempBasalLength +
", lastDataTime=" + lastDataTime +
", lastConnection=" + lastConnection +
", previousConnection=" + previousConnection +
", lastBolusTime=" + lastBolusTime +
", lastBolusAmount=" + lastBolusAmount +
", activeProfileName='" + activeProfileName + '\'' +
", reservoirRemainingUnits=" + reservoirRemainingUnits +
", reservoirFullUnits=" + reservoirFullUnits +
", batteryRemaining=" + batteryRemaining +
", batteryVoltage=" + batteryVoltage +
", iob='" + iob + '\'' +
", dailyTotalUnits=" + dailyTotalUnits +
", maxDailyTotalUnits='" + maxDailyTotalUnits + '\'' +
", validBasalRateProfileSelectedOnPump=" + validBasalRateProfileSelectedOnPump +
", pumpType=" + pumpType +
", profileStore=" + profileStore +
", units='" + units + '\'' +
", pumpStatusType=" + pumpStatusType +
", basalsByHour=" + Arrays.toString(basalsByHour) +
", currentBasal=" + currentBasal +
", tempBasalInProgress=" + tempBasalInProgress +
", tempBasalRatio=" + tempBasalRatio +
", tempBasalRemainMin=" + tempBasalRemainMin +
", tempBasalStart=" + tempBasalStart +
", pumpType=" + pumpType +
"} ";
}
}

View file

@ -35,7 +35,6 @@ import info.nightscout.androidaps.plugins.general.overview.notifications.Notific
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.R;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodManager;
@ -68,7 +67,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalScheduleEntry;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodHistoryEntryType;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
@ -88,7 +86,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
private final ResourceHelper resourceHelper;
private final HasAndroidInjector injector;
private final ActivePluginProvider activePlugin;
private final OmnipodPumpStatus pumpStatus;
private final Context context;
private final SP sp;
private final OmnipodManager delegate;
@ -104,7 +101,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
@Inject
public AapsOmnipodManager(OmnipodCommunicationManager communicationService,
PodStateManager podStateManager,
OmnipodPumpStatus pumpStatus,
OmnipodUtil omnipodUtil,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
@ -124,7 +120,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
this.resourceHelper = resourceHelper;
this.injector = injector;
this.activePlugin = activePlugin;
this.pumpStatus = pumpStatus;
this.context = context;
this.databaseHelper = databaseHelper;
this.sp = sp;
@ -391,12 +386,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
long pumpId = addSuccessToHistory(time, PodHistoryEntryType.SetTemporaryBasal, tempBasalPair);
pumpStatus.tempBasalStart = time;
pumpStatus.tempBasalAmount = tempBasalPair.getInsulinRate();
pumpStatus.tempBasalLength = tempBasalPair.getDurationMinutes();
pumpStatus.tempBasalEnd = DateTimeUtil.getTimeInFutureFromMinutes(time, tempBasalPair.getDurationMinutes());
pumpStatus.tempBasalPumpId = pumpId;
TemporaryBasal tempStart = new TemporaryBasal(injector) //
.date(time) //
.duration(tempBasalPair.getDurationMinutes()) //
@ -558,7 +547,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
TemporaryBasal temporaryBasal = new TemporaryBasal(injector) //
.date(time) //
.duration(0) //
.pumpId(pumpStatus.tempBasalPumpId)
.source(Source.PUMP);
plugin.addToHistoryTempBasal(temporaryBasal);
@ -716,7 +704,7 @@ public class AapsOmnipodManager implements IOmnipodManager {
return resourceHelper.gs(id, args);
}
static BasalSchedule mapProfileToBasalSchedule(Profile profile) {
public static BasalSchedule mapProfileToBasalSchedule(Profile profile) {
if (profile == null) {
throw new IllegalArgumentException("Profile can not be null");
}

View file

@ -1,34 +1,26 @@
package info.nightscout.androidaps.plugins.pump.omnipod.driver.comm;
import java.util.Date;
import java.util.Objects;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.events.Event;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpStatusType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@Singleton
public class AapsPodStateManager extends PodStateManager {
private final AAPSLogger aapsLogger;
private final SP sp;
private final OmnipodPumpStatus omnipodPumpStatus;
private final RxBusWrapper rxBus;
@Inject
public AapsPodStateManager(AAPSLogger aapsLogger, SP sp, OmnipodPumpStatus omnipodPumpStatus,
RxBusWrapper rxBus) {
public AapsPodStateManager(AAPSLogger aapsLogger, SP sp, RxBusWrapper rxBus) {
super(aapsLogger);
if (aapsLogger == null) {
@ -37,16 +29,12 @@ public class AapsPodStateManager extends PodStateManager {
if (sp == null) {
throw new IllegalArgumentException("sp can not be null");
}
if (omnipodPumpStatus == null) {
throw new IllegalArgumentException("omnipodPumpStatus can not be null");
}
if (rxBus == null) {
throw new IllegalArgumentException("rxBus can not be null");
}
this.aapsLogger = aapsLogger;
this.sp = sp;
this.omnipodPumpStatus = omnipodPumpStatus;
this.rxBus = rxBus;
}
@ -62,44 +50,11 @@ public class AapsPodStateManager extends PodStateManager {
@Override
protected void notifyPodStateChanged() {
if (!hasPodState()) {
omnipodPumpStatus.lastBolusTime = null;
omnipodPumpStatus.lastBolusAmount = null;
omnipodPumpStatus.reservoirRemainingUnits = 0.0;
// TODO this does not seem to set the pump status to suspended anymore
// Also, verify that AAPS is aware that no insulin is delivered anymore at this point
omnipodPumpStatus.pumpStatusType = PumpStatusType.Suspended;
sendEvent(new EventRefreshOverview("Omnipod Pump", false));
} else {
Date lastBolusStartTime = getLastBolusStartTime() == null ? null : getLastBolusStartTime().toDate();
Double lastBolusAmount = getLastBolusAmount();
aapsLogger.debug(LTag.PUMP, "Pod State changed. Sending events.");
// Update other info: last bolus, units remaining, suspended
boolean suspended = isSuspended() || !isPodRunning();
if (Objects.equals(lastBolusStartTime, omnipodPumpStatus.lastBolusTime) //
|| !Objects.equals(lastBolusAmount, omnipodPumpStatus.lastBolusAmount) //
|| !isReservoirStatusUpToDate(omnipodPumpStatus, getReservoirLevel())
|| suspended != PumpStatusType.Suspended.equals(omnipodPumpStatus.pumpStatusType)) {
omnipodPumpStatus.lastBolusTime = lastBolusStartTime;
omnipodPumpStatus.lastBolusAmount = lastBolusAmount;
omnipodPumpStatus.reservoirRemainingUnits = getReservoirLevel() == null ? 75.0 : getReservoirLevel();
boolean sendRefreshOverviewEvent = suspended != PumpStatusType.Suspended.equals(omnipodPumpStatus.pumpStatusType);
// TODO this does not seem to set the pump status to suspended anymore
// Also, verify that AAPS is aware that no insulin is delivered anymore at this point
omnipodPumpStatus.pumpStatusType = suspended ? PumpStatusType.Suspended : PumpStatusType.Running;
if (sendRefreshOverviewEvent) {
sendEvent(new EventRefreshOverview("Omnipod Pump", false));
}
}
}
sendEvent(new EventOmnipodPumpValuesChanged());
}
private static boolean isReservoirStatusUpToDate(OmnipodPumpStatus pumpStatus, Double unitsRemaining) {
double expectedUnitsRemaining = unitsRemaining == null ? 75.0 : unitsRemaining;
return Math.abs(expectedUnitsRemaining - pumpStatus.reservoirRemainingUnits) < 0.000001;
// TODO is this necessary?
sendEvent(new EventRefreshOverview("Omnipod Pump", true));
}
private void sendEvent(Event event) {

View file

@ -15,27 +15,23 @@ public class OmnipodUIComm {
private final HasAndroidInjector injector;
private final AAPSLogger aapsLogger;
private final OmnipodUIPostprocessor omnipodUIPostprocessor;
private final IOmnipodManager omnipodCommunicationManager;
private RileyLinkUtil rileyLinkUtil;
public OmnipodUIComm(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
OmnipodUIPostprocessor omnipodUIPostprocessor,
IOmnipodManager omnipodCommunicationManager,
RileyLinkUtil rileyLinkUtil
) {
this.injector = injector;
this.aapsLogger = aapsLogger;
this.omnipodUIPostprocessor = omnipodUIPostprocessor;
this.omnipodCommunicationManager = omnipodCommunicationManager;
this.rileyLinkUtil = rileyLinkUtil;
}
public OmnipodUITask executeCommand(OmnipodCommandType commandType, Object... parameters) {
aapsLogger.warn(LTag.PUMP, "Execute Command: " + commandType.name());
OmnipodUITask task = new OmnipodUITask(injector, commandType, parameters);
@ -48,10 +44,7 @@ public class OmnipodUIComm {
aapsLogger.warn(LTag.PUMP, "Reply not received for " + commandType);
}
task.postProcess(omnipodUIPostprocessor);
return task;
}
}

View file

@ -1,64 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui;
import java.util.Date;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
/**
* Created by andy on 4.8.2019
*/
// TODO remove once OmnipodPumpStatus has been removed
@Singleton
public class OmnipodUIPostprocessor {
private final AAPSLogger aapsLogger;
private final OmnipodPumpStatus pumpStatus;
@Inject
public OmnipodUIPostprocessor(AAPSLogger aapsLogger, OmnipodPumpStatus pumpStatus) {
this.aapsLogger = aapsLogger;
this.pumpStatus = pumpStatus;
}
// this is mostly intended for command that return certain statuses (Remaining Insulin, ...), and
// where responses won't be directly used
public void postProcessData(OmnipodUITask uiTask) {
switch (uiTask.commandType) {
case SetBolus:
if (uiTask.returnData != null) {
PumpEnactResult result = uiTask.returnData;
DetailedBolusInfo detailedBolusInfo = (DetailedBolusInfo) uiTask.getObjectFromParameters(0);
if (result.success) {
boolean isSmb = detailedBolusInfo.isSMB;
if (!isSmb) {
pumpStatus.lastBolusAmount = detailedBolusInfo.insulin;
pumpStatus.lastBolusTime = new Date();
}
}
}
break;
case CancelTemporaryBasal:
pumpStatus.tempBasalStart = 0;
pumpStatus.tempBasalEnd = 0;
pumpStatus.tempBasalAmount = null;
pumpStatus.tempBasalLength = null;
break;
default:
aapsLogger.debug(LTag.PUMP, "Post-processing not implemented for {}.", uiTask.commandType.name());
}
}
}

View file

@ -8,59 +8,36 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodResponseType;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
/**
* Created by andy on 4.8.2019
*/
public class OmnipodUITask {
@Inject RxBusWrapper rxBus;
@Inject AAPSLogger aapsLogger;
@Inject OmnipodPumpStatus omnipodPumpStatus;
@Inject OmnipodUtil omnipodUtil;
private final HasAndroidInjector injector;
public OmnipodCommandType commandType;
public PumpEnactResult returnData;
private String errorDescription;
private Object[] parameters;
public PodResponseType responseType;
public Object returnDataObject;
public OmnipodUITask(HasAndroidInjector injector, OmnipodCommandType commandType) {
this.injector = injector;
this.injector.androidInjector().inject(this);
this.commandType = commandType;
}
public OmnipodUITask(HasAndroidInjector injector, OmnipodCommandType commandType, Object... parameters) {
this.injector = injector;
this.injector.androidInjector().inject(this);
injector.androidInjector().inject(this);
this.commandType = commandType;
this.parameters = parameters;
}
public void execute(IOmnipodManager communicationManager) {
aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ In execute. {}", commandType);
switch (commandType) {
case PairAndPrimePod:
returnData = communicationManager.initPod((PodInitActionType) parameters[0], (PodInitReceiver) parameters[1], null);
break;
@ -149,75 +126,26 @@ public class OmnipodUITask {
}
private TempBasalPair getTBRSettings() {
return new TempBasalPair(getDoubleFromParameters(0), //
false, //
getIntegerFromParameters(1));
}
private Float getFloatFromParameters(int index) {
return (Float) parameters[index];
}
public Object getObjectFromParameters(int index) {
return parameters[index];
}
public Double getDoubleFromParameters(int index) {
return (Double) parameters[index];
}
public boolean getBooleanFromParameters(int index) {
return (boolean) parameters[index];
}
public Integer getIntegerFromParameters(int index) {
return (Integer) parameters[index];
}
public <T> T getResult() {
return (T) returnData;
}
public boolean isReceived() {
return (returnData != null || errorDescription != null);
}
// FIXME remove once OmnipodPumpStatus has been removed
public void postProcess(OmnipodUIPostprocessor postprocessor) {
aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ postProcess. {}", commandType);
aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ postProcess. responseType={}", responseType);
if (responseType == PodResponseType.Data || responseType == PodResponseType.Acknowledgment) {
postprocessor.postProcessData(this);
}
aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ postProcess. responseType={}", responseType);
if (!responseType.isError()) {
omnipodPumpStatus.setLastCommunicationToNow();
}
}
public boolean hasData() {
return (responseType == PodResponseType.Data || responseType == PodResponseType.Acknowledgment);
}
public Object getParameter(int index) {
return parameters[index];
}
public PodResponseType getResponseType() {
return this.responseType;
return returnData != null;
}
public boolean wasCommandSuccessful() {
@ -226,6 +154,4 @@ public class OmnipodUITask {
}
return returnData.success;
}
}

View file

@ -1,9 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.events
import info.nightscout.androidaps.events.Event
/**
* Created by andy on 04.06.2018.
*/
// FIXME can be removed, we should just use EventOmnipodPumpValuesChanged
class EventOmnipodAcknowledgeAlertsChanged : Event()

View file

@ -24,8 +24,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunication
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIComm;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIPostprocessor;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
@ -39,7 +37,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
@Inject OmnipodPumpPlugin omnipodPumpPlugin;
@Inject OmnipodUtil omnipodUtil;
@Inject OmnipodUIPostprocessor omnipodUIPostprocessor;
@Inject PodStateManager podStateManager;
@Inject DatabaseHelperInterface databaseHelper;
@Inject AapsOmnipodManager aapsOmnipodManager;
@ -73,31 +70,18 @@ public class RileyLinkOmnipodService extends RileyLinkService {
return RileyLinkEncodingType.Manchester;
}
/**
* If you have customized RileyLinkServiceData you need to override this
*/
@Override
public void initRileyLinkServiceData() {
rileyLinkServiceData.targetDevice = RileyLinkTargetDevice.Omnipod;
rileyLinkServiceData.rileyLinkTargetFrequency = RileyLinkTargetFrequency.Omnipod;
// get most recently used RileyLink address
rileyLinkServiceData.rileylinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
rfspy.startReader();
initializeErosOmnipodManager();
omnipodUIComm = new OmnipodUIComm(injector, aapsLogger, aapsOmnipodManager, rileyLinkUtil);
aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkOmnipodService newly constructed");
//omnipodPumpStatus = (OmnipodPumpStatus) omnipodPumpPlugin.getPumpStatusData();
}
private void initializeErosOmnipodManager() {
if (omnipodUIComm == null) {
omnipodUIComm = new OmnipodUIComm(injector, aapsLogger, omnipodUIPostprocessor, aapsOmnipodManager, rileyLinkUtil);
}
rxBus.send(new EventOmnipodPumpValuesChanged());
}
public OmnipodUIComm getDeviceCommandExecutor() {

View file

@ -0,0 +1,90 @@
package info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule;
import org.joda.time.Duration;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class BasalScheduleTest {
@Test
public void testRateAt() {
List<BasalScheduleEntry> entries = new ArrayList<>();
entries.add(new BasalScheduleEntry(1.0d, Duration.ZERO));
entries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6)));
entries.add(new BasalScheduleEntry(3.0d, Duration.standardHours(7)));
entries.add(new BasalScheduleEntry(4.0d, Duration.standardHours(20)));
BasalSchedule schedule = new BasalSchedule(entries);
assertEquals(1.0d, schedule.rateAt(Duration.ZERO), 0.00001);
assertEquals(1.0d, schedule.rateAt(Duration.standardHours(6).minus(Duration.standardSeconds(1))), 0.00001);
assertEquals(2.0d, schedule.rateAt(Duration.standardHours(6)), 0.00001);
assertEquals(2.0d, schedule.rateAt(Duration.standardHours(6).plus(Duration.standardMinutes(30))), 0.00001);
assertEquals(2.0d, schedule.rateAt(Duration.standardHours(7).minus(Duration.standardSeconds(1))), 0.00001);
assertEquals(3.0d, schedule.rateAt(Duration.standardHours(7)), 0.00001);
assertEquals(3.0d, schedule.rateAt(Duration.standardHours(19)), 0.00001);
assertEquals(3.0d, schedule.rateAt(Duration.standardHours(20).minus(Duration.standardSeconds(1))), 0.00001);
assertEquals(4.0d, schedule.rateAt(Duration.standardHours(20)), 0.00001);
assertEquals(4.0d, schedule.rateAt(Duration.standardHours(24).minus(Duration.standardSeconds(1))), 0.00001);
}
@Test
public void testEquals() {
List<BasalScheduleEntry> entries = new ArrayList<>();
entries.add(new BasalScheduleEntry(1.0d, Duration.ZERO));
entries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6)));
entries.add(new BasalScheduleEntry(3.0d, Duration.standardHours(7)));
entries.add(new BasalScheduleEntry(4.0d, Duration.standardHours(20)));
BasalSchedule schedule = new BasalSchedule(entries);
List<BasalScheduleEntry> otherEntries = new ArrayList<>();
otherEntries.add(new BasalScheduleEntry(1.0d, Duration.ZERO));
otherEntries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6)));
otherEntries.add(new BasalScheduleEntry(3.0d, Duration.standardHours(7)));
otherEntries.add(new BasalScheduleEntry(4.0d, Duration.standardHours(20)));
BasalSchedule otherschedule = new BasalSchedule(otherEntries);
assertEquals(schedule, otherschedule);
}
@Test
public void testNotEquals() {
List<BasalScheduleEntry> entries = new ArrayList<>();
entries.add(new BasalScheduleEntry(1.0d, Duration.ZERO));
entries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6)));
entries.add(new BasalScheduleEntry(3.0d, Duration.standardHours(7)));
entries.add(new BasalScheduleEntry(4.0d, Duration.standardHours(20)));
BasalSchedule schedule = new BasalSchedule(entries);
List<BasalScheduleEntry> otherEntries = new ArrayList<>();
otherEntries.add(new BasalScheduleEntry(1.0d, Duration.ZERO));
otherEntries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6)));
otherEntries.add(new BasalScheduleEntry(3.0d, Duration.standardHours(7)));
otherEntries.add(new BasalScheduleEntry(4.1d, Duration.standardHours(20)));
BasalSchedule otherschedule = new BasalSchedule(otherEntries);
assertNotEquals(schedule, otherschedule);
}
@Test
public void testNotEquals2() {
List<BasalScheduleEntry> entries = new ArrayList<>();
entries.add(new BasalScheduleEntry(1.0d, Duration.ZERO));
entries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6)));
entries.add(new BasalScheduleEntry(3.0d, Duration.standardHours(7)));
entries.add(new BasalScheduleEntry(4.0d, Duration.standardHours(20)));
BasalSchedule schedule = new BasalSchedule(entries);
List<BasalScheduleEntry> otherEntries = new ArrayList<>();
otherEntries.add(new BasalScheduleEntry(1.0d, Duration.ZERO));
otherEntries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6)));
otherEntries.add(new BasalScheduleEntry(3.0d, Duration.standardHours(7)));
BasalSchedule otherschedule = new BasalSchedule(otherEntries);
assertNotEquals(schedule, otherschedule);
}
}

View file

@ -14,7 +14,6 @@ import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.FirmwareVersion;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsPodStateManager;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -24,7 +23,6 @@ import static org.junit.Assert.assertEquals;
public class AapsPodStateManagerTest {
@Mock AAPSLogger aapsLogger;
@Mock SP sp;
@Mock OmnipodPumpStatus omnipodPumpStatus;
RxBusWrapper rxBus = new RxBusWrapper();
@Test
@ -36,7 +34,7 @@ public class AapsPodStateManagerTest {
DateTimeUtils.setCurrentMillisFixed(now.getMillis());
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus);
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, rxBus);
podStateManager.initState(0x0);
podStateManager.setInitializationParameters(0, 0, new FirmwareVersion(1, 1, 1),
new FirmwareVersion(2, 2, 2), timeZone, PodProgressStatus.ABOVE_FIFTY_UNITS);
@ -54,7 +52,7 @@ public class AapsPodStateManagerTest {
DateTimeUtils.setCurrentMillisFixed(now.getMillis());
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus);
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, rxBus);
podStateManager.initState(0x0);
podStateManager.setInitializationParameters(0, 0, new FirmwareVersion(1, 1, 1),
new FirmwareVersion(2, 2, 2), timeZone, PodProgressStatus.ABOVE_FIFTY_UNITS);
@ -77,7 +75,7 @@ public class AapsPodStateManagerTest {
DateTimeUtils.setCurrentMillisFixed(now.getMillis());
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus);
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, rxBus);
podStateManager.initState(0x0);
podStateManager.setInitializationParameters(0, 0, new FirmwareVersion(1, 1, 1),
new FirmwareVersion(2, 2, 2), timeZone, PodProgressStatus.ABOVE_FIFTY_UNITS);