renamed to TriggerPumpLastConnection
This commit is contained in:
parent
b108f1fa78
commit
3f1f199690
|
@ -222,7 +222,7 @@ object AutomationPlugin : PluginBase(PluginDescription()
|
||||||
TriggerLocation(),
|
TriggerLocation(),
|
||||||
TriggerAutosensValue(),
|
TriggerAutosensValue(),
|
||||||
TriggerBolusAgo(),
|
TriggerBolusAgo(),
|
||||||
TriggerPumpDisconnected()
|
TriggerPumpLastConnection()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,20 +24,20 @@ import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.JsonHelper;
|
import info.nightscout.androidaps.utils.JsonHelper;
|
||||||
import info.nightscout.androidaps.utils.T;
|
import info.nightscout.androidaps.utils.T;
|
||||||
|
|
||||||
public class TriggerPumpDisconnected extends Trigger {
|
public class TriggerPumpLastConnection extends Trigger {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.AUTOMATION);
|
private static Logger log = LoggerFactory.getLogger(L.AUTOMATION);
|
||||||
private InputDuration minutesAgo = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
|
private InputDuration minutesAgo = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
|
||||||
private Comparator comparator = new Comparator();
|
private Comparator comparator = new Comparator();
|
||||||
|
|
||||||
public TriggerPumpDisconnected() {
|
public TriggerPumpLastConnection() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
private TriggerPumpDisconnected(TriggerPumpDisconnected triggerPumpDisconnected) {
|
private TriggerPumpLastConnection(TriggerPumpLastConnection triggerPumpLastConnection) {
|
||||||
super();
|
super();
|
||||||
minutesAgo = new InputDuration(triggerPumpDisconnected.minutesAgo);
|
minutesAgo = new InputDuration(triggerPumpLastConnection.minutesAgo);
|
||||||
lastRun = triggerPumpDisconnected.lastRun;
|
lastRun = triggerPumpLastConnection.lastRun;
|
||||||
comparator = new Comparator(triggerPumpDisconnected.comparator);
|
comparator = new Comparator(triggerPumpLastConnection.comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getValue() {
|
public double getValue() {
|
||||||
|
@ -75,7 +75,7 @@ public class TriggerPumpDisconnected extends Trigger {
|
||||||
public synchronized String toJSON() {
|
public synchronized String toJSON() {
|
||||||
JSONObject o = new JSONObject();
|
JSONObject o = new JSONObject();
|
||||||
try {
|
try {
|
||||||
o.put("type", TriggerPumpDisconnected.class.getName());
|
o.put("type", TriggerPumpLastConnection.class.getName());
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
data.put("minutesAgo", getValue());
|
data.put("minutesAgo", getValue());
|
||||||
data.put("lastRun", lastRun);
|
data.put("lastRun", lastRun);
|
||||||
|
@ -102,12 +102,12 @@ public class TriggerPumpDisconnected extends Trigger {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int friendlyName() {
|
public int friendlyName() {
|
||||||
return R.string.automation_trigger_pump_disconnected_label;
|
return R.string.automation_trigger_pump_last_connection_label;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String friendlyDescription() {
|
public String friendlyDescription() {
|
||||||
return MainApp.gs(R.string.automation_trigger_pump_disconnected_compared, MainApp.gs(comparator.getValue().getStringRes()), (int) getValue());
|
return MainApp.gs(R.string.automation_trigger_pump_last_connection_compared, MainApp.gs(comparator.getValue().getStringRes()), (int) getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -117,20 +117,20 @@ public class TriggerPumpDisconnected extends Trigger {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Trigger duplicate() {
|
public Trigger duplicate() {
|
||||||
return new TriggerPumpDisconnected(this);
|
return new TriggerPumpLastConnection(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TriggerPumpDisconnected setValue(int requestedValue) {
|
TriggerPumpLastConnection setValue(int requestedValue) {
|
||||||
this.minutesAgo.setMinutes(requestedValue);
|
this.minutesAgo.setMinutes(requestedValue);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
TriggerPumpDisconnected lastRun(long lastRun) {
|
TriggerPumpLastConnection lastRun(long lastRun) {
|
||||||
this.lastRun = lastRun;
|
this.lastRun = lastRun;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
TriggerPumpDisconnected comparator(Comparator.Compare compare) {
|
TriggerPumpLastConnection comparator(Comparator.Compare compare) {
|
||||||
this.comparator = new Comparator().setValue(compare);
|
this.comparator = new Comparator().setValue(compare);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -138,9 +138,9 @@ public class TriggerPumpDisconnected extends Trigger {
|
||||||
@Override
|
@Override
|
||||||
public void generateDialog(LinearLayout root, FragmentManager fragmentManager) {
|
public void generateDialog(LinearLayout root, FragmentManager fragmentManager) {
|
||||||
new LayoutBuilder()
|
new LayoutBuilder()
|
||||||
.add(new StaticLabel(R.string.automation_trigger_pump_disconnected_label))
|
.add(new StaticLabel(R.string.automation_trigger_pump_last_connection_label))
|
||||||
.add(comparator)
|
.add(comparator)
|
||||||
.add(new LabelWithElement(MainApp.gs(R.string.automation_trigger_pump_disconnected_description) + ": ", "", minutesAgo))
|
.add(new LabelWithElement(MainApp.gs(R.string.automation_trigger_pump_last_connection_description) + ": ", "", minutesAgo))
|
||||||
.build(root);
|
.build(root);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -27,7 +27,7 @@ import static org.powermock.api.mockito.PowerMockito.when;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({MainApp.class, Bus.class, ProfileFunctions.class, DateUtil.class, TreatmentsPlugin.class, ConfigBuilderPlugin.class, System.class})
|
@PrepareForTest({MainApp.class, Bus.class, ProfileFunctions.class, DateUtil.class, TreatmentsPlugin.class, ConfigBuilderPlugin.class, System.class})
|
||||||
public class TriggerPumpDisconnectedTest {
|
public class TriggerPumpLastConnectionTest {
|
||||||
|
|
||||||
long now = 1514766900000L;
|
long now = 1514766900000L;
|
||||||
|
|
||||||
|
@ -38,64 +38,64 @@ public class TriggerPumpDisconnectedTest {
|
||||||
VirtualPumpPlugin virtualPumpPlugin = VirtualPumpPlugin.getPlugin();
|
VirtualPumpPlugin virtualPumpPlugin = VirtualPumpPlugin.getPlugin();
|
||||||
when(ConfigBuilderPlugin.getPlugin().getActivePump()).thenReturn(virtualPumpPlugin);
|
when(ConfigBuilderPlugin.getPlugin().getActivePump()).thenReturn(virtualPumpPlugin);
|
||||||
Assert.assertEquals(0L, virtualPumpPlugin.lastDataTime());
|
Assert.assertEquals(0L, virtualPumpPlugin.lastDataTime());
|
||||||
TriggerPumpDisconnected t = new TriggerPumpDisconnected().setValue(110).comparator(Comparator.Compare.IS_EQUAL).lastRun(now - 1);
|
TriggerPumpLastConnection t = new TriggerPumpLastConnection().setValue(110).comparator(Comparator.Compare.IS_EQUAL).lastRun(now - 1);
|
||||||
Assert.assertFalse(t.shouldRun());
|
Assert.assertFalse(t.shouldRun());
|
||||||
when(DateUtil.now()).thenReturn(now + (10*60*1000)); // set current time to now + 10 min
|
when(DateUtil.now()).thenReturn(now + (10*60*1000)); // set current time to now + 10 min
|
||||||
t = new TriggerPumpDisconnected().setValue(110).comparator(Comparator.Compare.IS_EQUAL);
|
t = new TriggerPumpLastConnection().setValue(110).comparator(Comparator.Compare.IS_EQUAL);
|
||||||
Assert.assertEquals(110, t.getValue(), 0.01d);
|
Assert.assertEquals(110, t.getValue(), 0.01d);
|
||||||
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t.getComparator().getValue());
|
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t.getComparator().getValue());
|
||||||
Assert.assertFalse(t.shouldRun());
|
Assert.assertFalse(t.shouldRun());
|
||||||
t = new TriggerPumpDisconnected().setValue(10).comparator(Comparator.Compare.IS_EQUAL);
|
t = new TriggerPumpLastConnection().setValue(10).comparator(Comparator.Compare.IS_EQUAL);
|
||||||
Assert.assertEquals(10, t.getValue(), 0.01d);
|
Assert.assertEquals(10, t.getValue(), 0.01d);
|
||||||
Assert.assertFalse(t.shouldRun()); // 0 == 10 -> FALSE
|
Assert.assertFalse(t.shouldRun()); // 0 == 10 -> FALSE
|
||||||
t = new TriggerPumpDisconnected().setValue(5).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER);
|
t = new TriggerPumpLastConnection().setValue(5).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER);
|
||||||
Assert.assertTrue(t.shouldRun()); // 5 => 0 -> TRUE
|
Assert.assertTrue(t.shouldRun()); // 5 => 0 -> TRUE
|
||||||
t = new TriggerPumpDisconnected().setValue(310).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
t = new TriggerPumpLastConnection().setValue(310).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
||||||
Assert.assertFalse(t.shouldRun()); // 310 <= 0 -> FALSE
|
Assert.assertFalse(t.shouldRun()); // 310 <= 0 -> FALSE
|
||||||
t = new TriggerPumpDisconnected().setValue(420).comparator(Comparator.Compare.IS_EQUAL);
|
t = new TriggerPumpLastConnection().setValue(420).comparator(Comparator.Compare.IS_EQUAL);
|
||||||
Assert.assertFalse(t.shouldRun()); // 420 == 0 -> FALSE
|
Assert.assertFalse(t.shouldRun()); // 420 == 0 -> FALSE
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void copyConstructorTest() {
|
public void copyConstructorTest() {
|
||||||
TriggerPumpDisconnected t = new TriggerPumpDisconnected().setValue(213).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
TriggerPumpLastConnection t = new TriggerPumpLastConnection().setValue(213).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
||||||
TriggerPumpDisconnected t1 = (TriggerPumpDisconnected) t.duplicate();
|
TriggerPumpLastConnection t1 = (TriggerPumpLastConnection) t.duplicate();
|
||||||
Assert.assertEquals(213, t1.getValue(), 0.01d);
|
Assert.assertEquals(213, t1.getValue(), 0.01d);
|
||||||
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.getComparator().getValue());
|
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.getComparator().getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void executeTest() {
|
public void executeTest() {
|
||||||
TriggerPumpDisconnected t = new TriggerPumpDisconnected().setValue(213).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
TriggerPumpLastConnection t = new TriggerPumpLastConnection().setValue(213).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER);
|
||||||
t.executed(1);
|
t.executed(1);
|
||||||
Assert.assertEquals(1l, t.getLastRun());
|
Assert.assertEquals(1l, t.getLastRun());
|
||||||
}
|
}
|
||||||
|
|
||||||
String LBJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"lastRun\":0,\"minutesAgo\":410},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerPumpDisconnected\"}";
|
String LBJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"lastRun\":0,\"minutesAgo\":410},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerPumpLastConnection\"}";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toJSONTest() {
|
public void toJSONTest() {
|
||||||
TriggerPumpDisconnected t = new TriggerPumpDisconnected().setValue(410).comparator(Comparator.Compare.IS_EQUAL);
|
TriggerPumpLastConnection t = new TriggerPumpLastConnection().setValue(410).comparator(Comparator.Compare.IS_EQUAL);
|
||||||
Assert.assertEquals(LBJson, t.toJSON());
|
Assert.assertEquals(LBJson, t.toJSON());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fromJSONTest() throws JSONException {
|
public void fromJSONTest() throws JSONException {
|
||||||
TriggerPumpDisconnected t = new TriggerPumpDisconnected().setValue(410).comparator(Comparator.Compare.IS_EQUAL);
|
TriggerPumpLastConnection t = new TriggerPumpLastConnection().setValue(410).comparator(Comparator.Compare.IS_EQUAL);
|
||||||
|
|
||||||
TriggerPumpDisconnected t2 = (TriggerPumpDisconnected) Trigger.instantiate(new JSONObject(t.toJSON()));
|
TriggerPumpLastConnection t2 = (TriggerPumpLastConnection) Trigger.instantiate(new JSONObject(t.toJSON()));
|
||||||
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.getComparator().getValue());
|
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.getComparator().getValue());
|
||||||
Assert.assertEquals(410, t2.getValue(), 0.01d);
|
Assert.assertEquals(410, t2.getValue(), 0.01d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void iconTest() {
|
public void iconTest() {
|
||||||
Assert.assertEquals(Optional.of(R.drawable.remove), new TriggerPumpDisconnected().icon());
|
Assert.assertEquals(Optional.of(R.drawable.remove), new TriggerPumpLastConnection().icon());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void friendlyNameTest() {
|
public void friendlyNameTest() {
|
||||||
Assert.assertEquals(R.string.automation_trigger_pump_disconnected_label, new TriggerPumpDisconnected().friendlyName());
|
Assert.assertEquals(R.string.automation_trigger_pump_last_connection_compared, new TriggerPumpLastConnection().friendlyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue