Skip to content

Commit

Permalink
[influxdb] Treat a stored 1 AND 1.0 as true (openhab#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 and thinkingstone committed Nov 7, 2021
1 parent 2ac68e0 commit f4773e7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
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
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 f4773e7

Please sign in to comment.