Don't allow numerical sensor state to be NaN or inf (#98110)
This commit is contained in:
parent
3b16a3e1e0
commit
e3b945a8d0
2 changed files with 27 additions and 9 deletions
|
@ -1861,13 +1861,17 @@ async def test_device_classes_with_invalid_unit_of_measurement(
|
|||
],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"native_value",
|
||||
("native_value", "problem"),
|
||||
[
|
||||
"",
|
||||
"abc",
|
||||
"13.7.1",
|
||||
datetime(2012, 11, 10, 7, 35, 1),
|
||||
date(2012, 11, 10),
|
||||
("", "non-numeric"),
|
||||
("abc", "non-numeric"),
|
||||
("13.7.1", "non-numeric"),
|
||||
(datetime(2012, 11, 10, 7, 35, 1), "non-numeric"),
|
||||
(date(2012, 11, 10), "non-numeric"),
|
||||
("inf", "non-finite"),
|
||||
(float("inf"), "non-finite"),
|
||||
("nan", "non-finite"),
|
||||
(float("nan"), "non-finite"),
|
||||
],
|
||||
)
|
||||
async def test_non_numeric_validation_error(
|
||||
|
@ -1875,6 +1879,7 @@ async def test_non_numeric_validation_error(
|
|||
caplog: pytest.LogCaptureFixture,
|
||||
enable_custom_integrations: None,
|
||||
native_value: Any,
|
||||
problem: str,
|
||||
device_class: SensorDeviceClass | None,
|
||||
state_class: SensorStateClass | None,
|
||||
unit: str | None,
|
||||
|
@ -1899,7 +1904,7 @@ async def test_non_numeric_validation_error(
|
|||
|
||||
assert (
|
||||
"thus indicating it has a numeric value; "
|
||||
f"however, it has the non-numeric value: '{native_value}'"
|
||||
f"however, it has the {problem} value: '{native_value}'"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue