Handle explicit Modbus NaN values (#90800)
Co-authored-by: jan iversen <jancasacondor@gmail.com>
This commit is contained in:
parent
0511071757
commit
c4a5373976
6 changed files with 57 additions and 2 deletions
|
@ -64,6 +64,7 @@ from homeassistant.components.modbus.const import (
|
|||
from homeassistant.components.modbus.validators import (
|
||||
duplicate_entity_validator,
|
||||
duplicate_modbus_validator,
|
||||
nan_validator,
|
||||
number_validator,
|
||||
struct_validator,
|
||||
)
|
||||
|
@ -141,6 +142,23 @@ async def test_number_validator() -> None:
|
|||
pytest.fail("Number_validator not throwing exception")
|
||||
|
||||
|
||||
async def test_nan_validator() -> None:
|
||||
"""Test number validator."""
|
||||
|
||||
for value, value_type in (
|
||||
(15, int),
|
||||
("15", int),
|
||||
("abcdef", int),
|
||||
("0xabcdef", int),
|
||||
):
|
||||
assert isinstance(nan_validator(value), value_type)
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
nan_validator("x15")
|
||||
with pytest.raises(vol.Invalid):
|
||||
nan_validator("not a hex string")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"do_config",
|
||||
[
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue