virtual pump lifecycle

This commit is contained in:
Milos Kozak 2018-08-23 18:59:46 +02:00
parent b0f8ab9922
commit b7950322c8
2 changed files with 29 additions and 9 deletions

View file

@ -2,6 +2,8 @@ package info.nightscout.androidaps.plugins.PumpVirtual;
import android.os.SystemClock; import android.os.SystemClock;
import com.squareup.otto.Subscribe;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -17,6 +19,7 @@ import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
@ -115,6 +118,23 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
pumpDescription.is30minBasalRatesCapable = true; pumpDescription.is30minBasalRatesCapable = true;
} }
@Override
protected void onStart() {
super.onStart();
refreshConfiguration();
}
@Override
protected void onStop() {
MainApp.bus().unregister(this);
}
@Subscribe
public void onStatusEvent(final EventPreferenceChange s) {
if (s.isChanged(R.string.key_virtualpump_type))
refreshConfiguration();
}
@Override @Override
public boolean isFakingTempsByExtendedBoluses() { public boolean isFakingTempsByExtendedBoluses() {
return (Config.NSCLIENT) && fromNSAreCommingFakedExtendedBoluses; return (Config.NSCLIENT) && fromNSAreCommingFakedExtendedBoluses;
@ -419,23 +439,23 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
return "Virtual Pump"; return "Virtual Pump";
} }
public PumpType getPumpType() public PumpType getPumpType() {
{
return pumpType; return pumpType;
} }
public void refreshConfiguration() public void refreshConfiguration() {
{
String pumptype = SP.getString(R.string.key_virtualpump_type, "Generic AAPS"); String pumptype = SP.getString(R.string.key_virtualpump_type, "Generic AAPS");
PumpType pumpTypeNew = PumpType.getByDescription(pumptype); PumpType pumpTypeNew = PumpType.getByDescription(pumptype);
if (L.isEnabled(L.PUMP))
log.debug("Pump in configuration: {}, PumpType object: {}", pumptype, pumpTypeNew); log.debug("Pump in configuration: {}, PumpType object: {}", pumptype, pumpTypeNew);
if (pumpType == pumpTypeNew) if (pumpType == pumpTypeNew)
return; return;
if (L.isEnabled(L.PUMP))
log.debug("New pump configuration found ({}), changing from previous ({})", pumpTypeNew, pumpType); log.debug("New pump configuration found ({}), changing from previous ({})", pumpTypeNew, pumpType);
// reset // reset

View file

@ -45,11 +45,11 @@ public class VirtualPumpPluginUTest {
@Test @Test
public void getPumpType() throws Exception { public void getPumpType() {
} }
@Test @Test
public void refreshConfiguration() throws Exception { public void refreshConfiguration() {
when(SP.getString(R.string.key_virtualpump_type, "Generic AAPS")).thenReturn("Accu-Chek Combo"); when(SP.getString(R.string.key_virtualpump_type, "Generic AAPS")).thenReturn("Accu-Chek Combo");
@ -60,7 +60,7 @@ public class VirtualPumpPluginUTest {
@Test @Test
public void refreshConfigurationTwice() throws Exception { public void refreshConfigurationTwice() {
when(SP.getString(R.string.key_virtualpump_type, "Generic AAPS")).thenReturn("Accu-Chek Combo"); when(SP.getString(R.string.key_virtualpump_type, "Generic AAPS")).thenReturn("Accu-Chek Combo");