mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[mqtt] recognize -NaN as UNDEF as well (#16245)
Signed-off-by: Cody Cutrer <cody@cutrer.us> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
8e34fa4ffd
commit
70137ce58a
@ -47,6 +47,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class NumberValue extends Value {
|
public class NumberValue extends Value {
|
||||||
private static final String NAN = "NaN";
|
private static final String NAN = "NaN";
|
||||||
|
private static final String NEGATIVE_NAN = "-NaN";
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(NumberValue.class);
|
private final Logger logger = LoggerFactory.getLogger(NumberValue.class);
|
||||||
private final @Nullable BigDecimal min;
|
private final @Nullable BigDecimal min;
|
||||||
@ -120,7 +121,8 @@ public class NumberValue extends Value {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type parseMessage(Command command) throws IllegalArgumentException {
|
public Type parseMessage(Command command) throws IllegalArgumentException {
|
||||||
if (command instanceof StringType && command.toString().equalsIgnoreCase(NAN)) {
|
if (command instanceof StringType
|
||||||
|
&& (command.toString().equalsIgnoreCase(NAN) || command.toString().equalsIgnoreCase(NEGATIVE_NAN))) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return parseCommand(command);
|
return parseCommand(command);
|
||||||
|
@ -189,6 +189,8 @@ public class ValueTests {
|
|||||||
|
|
||||||
assertThat(v.parseMessage(new StringType("NaN")), is(UnDefType.UNDEF));
|
assertThat(v.parseMessage(new StringType("NaN")), is(UnDefType.UNDEF));
|
||||||
assertThat(v.parseMessage(new StringType("nan")), is(UnDefType.UNDEF));
|
assertThat(v.parseMessage(new StringType("nan")), is(UnDefType.UNDEF));
|
||||||
|
assertThat(v.parseMessage(new StringType("-NaN")), is(UnDefType.UNDEF));
|
||||||
|
assertThat(v.parseMessage(new StringType("-nan")), is(UnDefType.UNDEF));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user