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"); decimalFormat = new DecimalFormat("0");
} }
// make sure that value is in range
textWatcher.afterTextChanged(null);
this.units = units; this.units = units;
return this; return this;
} }

View file

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

View file

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