[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:
Cody Cutrer 2024-01-08 09:15:02 -07:00 committed by Ciprian Pascu
parent 8e34fa4ffd
commit 70137ce58a
2 changed files with 5 additions and 1 deletions

View File

@ -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);

View File

@ -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