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 ed3aa38a03..d195925edb 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 @@ -90,6 +90,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.CommandPlay import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.CommandUpdateAlertConfiguration; import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.OmnipodCustomCommand; import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.OmnipodCustomCommandType; +import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.manager.OmnipodRileyLinkCommunicationManager; import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.service.RileyLinkOmnipodService; import info.nightscout.androidaps.plugins.pump.omnipod.ui.OmnipodOverviewFragment; import info.nightscout.androidaps.plugins.pump.omnipod.util.AapsOmnipodUtil; @@ -137,8 +138,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, private final DateUtil dateUtil; private final PumpDescription pumpDescription; private final ServiceConnection serviceConnection; + private final OmnipodRileyLinkCommunicationManager omnipodRileyLinkCommunicationManager; private final PumpType pumpType = PumpType.Insulet_Omnipod; - private final CompositeDisposable disposables = new CompositeDisposable(); private final NSUpload nsUpload; @@ -175,7 +176,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, RileyLinkUtil rileyLinkUtil, OmnipodAlertUtil omnipodAlertUtil, ProfileFunction profileFunction, - NSUpload nsUpload + NSUpload nsUpload, + OmnipodRileyLinkCommunicationManager omnipodRileyLinkCommunicationManager ) { super(new PluginDescription() // .mainType(PluginType.PUMP) // @@ -202,6 +204,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, this.omnipodAlertUtil = omnipodAlertUtil; this.profileFunction = profileFunction; this.nsUpload = nsUpload; + this.omnipodRileyLinkCommunicationManager = omnipodRileyLinkCommunicationManager; pumpDescription = new PumpDescription(pumpType); @@ -613,7 +616,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, @Override public int getBatteryLevel() { if (aapsOmnipodManager.isUseRileyLinkBatteryLevel()) { - return rileyLinkServiceData.batteryLevel == null ? 0 : rileyLinkServiceData.batteryLevel; + Integer batteryLevel = omnipodRileyLinkCommunicationManager.getBatteryLevel(); + return batteryLevel == null ? 0 : batteryLevel; } return 0; diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/rileylink/manager/OmnipodRileyLinkCommunicationManager.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/rileylink/manager/OmnipodRileyLinkCommunicationManager.java index 44f2069c59..0171b60a9a 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/rileylink/manager/OmnipodRileyLinkCommunicationManager.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/rileylink/manager/OmnipodRileyLinkCommunicationManager.java @@ -8,6 +8,7 @@ import java.util.List; import javax.inject.Inject; import javax.inject.Singleton; +import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager; @@ -15,6 +16,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLink import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RLMessageType; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkBLEError; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; +import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.action.OmnipodAction; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.MessageBlock; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.OmnipodMessage; @@ -50,6 +52,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateMa */ @Singleton public class OmnipodRileyLinkCommunicationManager extends RileyLinkCommunicationManager { + private Integer batteryLevel; + // This empty constructor must be kept, otherwise dagger injection might break! @Inject public OmnipodRileyLinkCommunicationManager() { @@ -81,6 +85,21 @@ public class OmnipodRileyLinkCommunicationManager extends RileyLinkCommunication // We don't use PumpDeviceState in the Omnipod driver } + @Override protected OmnipodPacket sendAndListen(OmnipodPacket msg, int timeout_ms, int repeatCount, int retryCount, Integer extendPreamble_ms) throws RileyLinkCommunicationException { + OmnipodPacket response = super.sendAndListen(msg, timeout_ms, repeatCount, retryCount, extendPreamble_ms); + + PumpInterface activePump = activePluginProvider.getActivePump(); + if (activePump instanceof OmnipodPumpPlugin && ((OmnipodPumpPlugin) activePump).isUseRileyLinkBatteryLevel()) { + updateBatteryLevel(); + } + + return response; + } + + public Integer getBatteryLevel() { + return batteryLevel; + } + public T sendCommand(Class responseClass, PodStateManager podStateManager, MessageBlock command) { return sendCommand(responseClass, podStateManager, command, true); } @@ -384,4 +403,7 @@ public class OmnipodRileyLinkCommunicationManager extends RileyLinkCommunication throw new RileyLinkUnreachableException(); } + private void updateBatteryLevel() { + batteryLevel = rfspy.getBatteryLevel(); + } } diff --git a/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPluginTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPluginTest.java index 28af58b0d6..e6aeed9f79 100644 --- a/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPluginTest.java +++ b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPluginTest.java @@ -60,7 +60,7 @@ public class OmnipodPumpPluginTest { OmnipodPumpPlugin plugin = new OmnipodPumpPlugin(injector, aapsLogger, rxBusWrapper, null, resourceHelper, activePluginProvider, null, null, aapsOmnipodManager, commandQueueProvider, null, null, null, null, - rileyLinkUtil, null, null, null + rileyLinkUtil, null, null, null, null ); when(activePluginProvider.getActiveTreatments().getTempBasalFromHistory(anyLong())).thenReturn(null); when(rileyLinkUtil.getRileyLinkHistory()).thenReturn(new ArrayList<>()); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java index 21e94e99ff..a7aae37175 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java @@ -81,8 +81,6 @@ public abstract class RileyLinkCommunicationManager { RadioResponse radioResponse = rfSpyResponse.getRadioResponse(injector); T response = createResponseMessage(radioResponse.getPayload()); - updateBatteryLevel(); - if (response.isValid()) { // Mark this as the last time we heard from the pump. rememberLastGoodDeviceCommunicationTime(); @@ -118,10 +116,6 @@ public abstract class RileyLinkCommunicationManager { return response; } - private void updateBatteryLevel() { - rileyLinkServiceData.batteryLevel = rfspy.getBatteryLevel(); - } - public abstract T createResponseMessage(byte[] payload); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java index 3a0bc6dde1..6307c7ad87 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java @@ -43,8 +43,6 @@ public class RileyLinkServiceData { // radio version public String versionCC110; - public Integer batteryLevel; - public RileyLinkTargetDevice targetDevice; // Medtronic Pump