TriggerProfilePercent extends Trigger { @Override public synchronized boolean shouldRun() { if (lastRun > DateUtil.now() - T.mins(5).msecs()) return false; Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null && comparator.getValue().equals(Comparator.Compare.IS_NOT_AVAILABLE)) { if (L.isEnabled(L.AUTOMATION)) log.debug("Ready for execution: " + friendlyDescription()); return true; } if (profile == null) return false; boolean doRun = comparator.getValue().check((double) profile.getPercentage(), pct.getValue()); if (doRun) { if (L.isEnabled(L.AUTOMATION)) log.debug("Ready for execution: " + friendlyDescription()); return true; } return false; } TriggerProfilePercent(); private  TriggerProfilePercent(TriggerProfilePercent triggerProfilePercent); double getValue(); Comparator getComparator(); long getLastRun(); @Override synchronized boolean shouldRun(); @Override synchronized String toJSON(); @Override int friendlyName(); @Override String friendlyDescription(); @Override Optional<Integer> icon(); @Override Trigger duplicate(); TriggerProfilePercent setValue(double value); TriggerProfilePercent comparator(Comparator.Compare compare); @Override void generateDialog(LinearLayout root, FragmentManager fragmentManager);  }
@Test public void shouldRunTest() { TriggerProfilePercent t = new TriggerProfilePercent().setValue(101d).comparator(Comparator.Compare.IS_EQUAL); Assert.assertFalse(t.shouldRun()); t = new TriggerProfilePercent().setValue(100d).comparator(Comparator.Compare.IS_EQUAL); Assert.assertTrue(t.shouldRun()); t = new TriggerProfilePercent().setValue(100d).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER); Assert.assertTrue(t.shouldRun()); t = new TriggerProfilePercent().setValue(90d).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER); Assert.assertTrue(t.shouldRun()); t = new TriggerProfilePercent().setValue(100d).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER); Assert.assertTrue(t.shouldRun()); t = new TriggerProfilePercent().setValue(101d).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER); Assert.assertTrue(t.shouldRun()); t = new TriggerProfilePercent().setValue(215d).comparator(Comparator.Compare.IS_EQUAL); Assert.assertFalse(t.shouldRun()); t = new TriggerProfilePercent().setValue(110d).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER); Assert.assertFalse(t.shouldRun()); t = new TriggerProfilePercent().setValue(90d).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER); Assert.assertFalse(t.shouldRun()); t = new TriggerProfilePercent().setValue(101d).comparator(Comparator.Compare.IS_EQUAL).lastRun(now - 1); Assert.assertFalse(t.shouldRun()); }