mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Use math.isfinite instead of explicitly checking for both nan and inf (#98103)
This commit is contained in:
parent
7e9d0cca44
commit
e1f0b44ba4
@ -442,7 +442,7 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
|||||||
"""Update thermostat with latest state from sensor."""
|
"""Update thermostat with latest state from sensor."""
|
||||||
try:
|
try:
|
||||||
cur_temp = float(state.state)
|
cur_temp = float(state.state)
|
||||||
if math.isnan(cur_temp) or math.isinf(cur_temp):
|
if not math.isfinite(cur_temp):
|
||||||
raise ValueError(f"Sensor has illegal state {state.state}")
|
raise ValueError(f"Sensor has illegal state {state.state}")
|
||||||
self._cur_temp = cur_temp
|
self._cur_temp = cur_temp
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
|
@ -149,7 +149,7 @@ def _equivalent_units(units: set[str | None]) -> bool:
|
|||||||
def _parse_float(state: str) -> float:
|
def _parse_float(state: str) -> float:
|
||||||
"""Parse a float string, throw on inf or nan."""
|
"""Parse a float string, throw on inf or nan."""
|
||||||
fstate = float(state)
|
fstate = float(state)
|
||||||
if math.isnan(fstate) or math.isinf(fstate):
|
if not math.isfinite(fstate):
|
||||||
raise ValueError
|
raise ValueError
|
||||||
return fstate
|
return fstate
|
||||||
|
|
||||||
|
@ -1934,7 +1934,7 @@ def is_number(value):
|
|||||||
fvalue = float(value)
|
fvalue = float(value)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
return False
|
return False
|
||||||
if math.isnan(fvalue) or math.isinf(fvalue):
|
if not math.isfinite(fvalue):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user