mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Fixed float number validation in sensor component (#88074)
This commit is contained in:
parent
93f23e7523
commit
66ba0cb1d3
@ -548,7 +548,7 @@ class SensorEntity(Entity):
|
|||||||
numerical_value: int | float | Decimal
|
numerical_value: int | float | Decimal
|
||||||
if not isinstance(value, (int, float, Decimal)):
|
if not isinstance(value, (int, float, Decimal)):
|
||||||
try:
|
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)
|
numerical_value = int(value)
|
||||||
else:
|
else:
|
||||||
numerical_value = float(value) # type:ignore[arg-type]
|
numerical_value = float(value) # type:ignore[arg-type]
|
||||||
|
@ -1727,6 +1727,7 @@ async def test_non_numeric_validation_raise(
|
|||||||
[
|
[
|
||||||
(13, "13"),
|
(13, "13"),
|
||||||
(17.50, "17.5"),
|
(17.50, "17.5"),
|
||||||
|
("1e-05", "1e-05"),
|
||||||
(Decimal(18.50), "18.5"),
|
(Decimal(18.50), "18.5"),
|
||||||
("19.70", "19.70"),
|
("19.70", "19.70"),
|
||||||
(None, STATE_UNKNOWN),
|
(None, STATE_UNKNOWN),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user