Skip to content

Commit

Permalink
[influxdb] Treat a stored 1 AND 1.0 as true (#9545)
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Triller <github@stefantriller.de>
  • Loading branch information
t2000 authored Dec 29, 2020
1 parent 6da56da commit bf2d40c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private static boolean toBoolean(@Nullable Object object) {
if (object instanceof Boolean) {
return (Boolean) object;
} else if (object != null) {
if ("1".equals(object)) {
if ("1".equals(object) || "1.0".equals(object)) {
return true;
} else {
return Boolean.valueOf(String.valueOf(object));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,15 @@ public void convertDecimalToState(String number) {
public void convertOnOffToState() {
boolean val1 = true;
int val2 = 1;
double val3 = 1.0;
SwitchItem onOffItem = new SwitchItem("name");
ContactItem contactItem = new ContactItem("name");
assertThat(InfluxDBStateConvertUtils.objectToState(val1, onOffItem), equalTo(OnOffType.ON));
assertThat(InfluxDBStateConvertUtils.objectToState(val2, onOffItem), equalTo(OnOffType.ON));
assertThat(InfluxDBStateConvertUtils.objectToState(val3, onOffItem), equalTo(OnOffType.ON));
assertThat(InfluxDBStateConvertUtils.objectToState(val1, contactItem), equalTo(OpenClosedType.OPEN));
assertThat(InfluxDBStateConvertUtils.objectToState(val2, contactItem), equalTo(OpenClosedType.OPEN));
assertThat(InfluxDBStateConvertUtils.objectToState(val3, contactItem), equalTo(OpenClosedType.OPEN));
}

@Test
Expand Down

0 comments on commit bf2d40c

Please sign in to comment.