mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +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
|
||||
public class NumberValue extends Value {
|
||||
private static final String NAN = "NaN";
|
||||
private static final String NEGATIVE_NAN = "-NaN";
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(NumberValue.class);
|
||||
private final @Nullable BigDecimal min;
|
||||
@ -120,7 +121,8 @@ public class NumberValue extends Value {
|
||||
|
||||
@Override
|
||||
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 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));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user