mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +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."""
|
||||
try:
|
||||
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}")
|
||||
self._cur_temp = cur_temp
|
||||
except ValueError as ex:
|
||||
|
@ -149,7 +149,7 @@ def _equivalent_units(units: set[str | None]) -> bool:
|
||||
def _parse_float(state: str) -> float:
|
||||
"""Parse a float string, throw on inf or nan."""
|
||||
fstate = float(state)
|
||||
if math.isnan(fstate) or math.isinf(fstate):
|
||||
if not math.isfinite(fstate):
|
||||
raise ValueError
|
||||
return fstate
|
||||
|
||||
|
@ -1934,7 +1934,7 @@ def is_number(value):
|
||||
fvalue = float(value)
|
||||
except (ValueError, TypeError):
|
||||
return False
|
||||
if math.isnan(fvalue) or math.isinf(fvalue):
|
||||
if not math.isfinite(fvalue):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user