Fixed float number validation in sensor component (#88074)
parent
be5777ba59
commit
55fed18e3e
|
@ -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]
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue