Don't allow numerical sensor state to be NaN or inf (#98110)

This commit is contained in:
Erik Montnemery 2023-08-23 14:16:40 +02:00 committed by GitHub
parent 3b16a3e1e0
commit e3b945a8d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 9 deletions

View file

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