Fixed float number validation in sensor component (#88074)

pull/88190/head
Gertjan 2023-02-15 15:53:44 +01:00 committed by Paulus Schoutsen
parent be5777ba59
commit 55fed18e3e
2 changed files with 2 additions and 1 deletions

View File

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

View File

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