From 55fed18e3edb3f6b525a616347695e2533374d73 Mon Sep 17 00:00:00 2001 From: Gertjan Date: Wed, 15 Feb 2023 15:53:44 +0100 Subject: [PATCH] Fixed float number validation in sensor component (#88074) --- homeassistant/components/sensor/__init__.py | 2 +- tests/components/sensor/test_init.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index 5108a167552..2fbd8ef211d 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -587,7 +587,7 @@ class SensorEntity(Entity): numerical_value: int | float | Decimal if not isinstance(value, (int, float, Decimal)): try: - if isinstance(value, str) and "." not in value: + if isinstance(value, str) and "." not in value and "e" not in value: numerical_value = int(value) else: numerical_value = float(value) # type:ignore[arg-type] diff --git a/tests/components/sensor/test_init.py b/tests/components/sensor/test_init.py index b43c63f015c..f63d10bc76a 100644 --- a/tests/components/sensor/test_init.py +++ b/tests/components/sensor/test_init.py @@ -1548,6 +1548,7 @@ async def test_non_numeric_validation_raise( [ (13, "13"), (17.50, "17.5"), + ("1e-05", "1e-05"), (Decimal(18.50), "18.5"), ("19.70", "19.70"), (None, STATE_UNKNOWN),