Merge pull request #1756 from schmitzn/automation-patch1

Check value after setting unit
This commit is contained in:
Milos Kozak 2019-04-22 09:37:17 +02:00 committed by GitHub
commit bef170699f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 3 deletions

View file

@ -80,6 +80,9 @@ public class InputBg extends Element {
decimalFormat = new DecimalFormat("0");
}
// make sure that value is in range
textWatcher.afterTextChanged(null);
this.units = units;
return this;
}

View file

@ -102,10 +102,10 @@ public class TriggerBg extends Trigger {
Trigger fromJSON(String data) {
try {
JSONObject d = new JSONObject(data);
bg.setUnits(JsonHelper.safeGetString(d, "units"));
bg.setValue(JsonHelper.safeGetDouble(d, "bg"));
lastRun = JsonHelper.safeGetLong(d, "lastRun");
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
bg.setUnits(JsonHelper.safeGetString(d, "units"));
} catch (Exception e) {
e.printStackTrace();
}

View file

@ -18,7 +18,7 @@ public class InputBgTest {
@Test
public void textWatcherTest() {
InputBg t = new InputBg().setValue(1d).setUnits(Constants.MMOL);
InputBg t = new InputBg().setUnits(Constants.MMOL).setValue(1d);
t.textWatcher.beforeTextChanged(null, 0, 0, 0);
t.textWatcher.onTextChanged(null, 0, 0, 0);
t.textWatcher.afterTextChanged(null);
@ -31,7 +31,7 @@ public class InputBgTest {
@Test
public void getSetValueTest() {
InputBg i = new InputBg().setValue(5d).setUnits(Constants.MMOL);
InputBg i = new InputBg().setUnits(Constants.MMOL).setValue(5d);
Assert.assertEquals(5d, i.getValue(), 0.01d);
Assert.assertEquals(2, i.minValue, 0.01d);
i = new InputBg().setValue(100d).setUnits(Constants.MGDL);