Use math.isfinite instead of explicitly checking for both nan and inf (#98103)

This commit is contained in:
Erik Montnemery 2023-08-09 14:13:57 +02:00 committed by GitHub
parent 7e9d0cca44
commit e1f0b44ba4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 3 deletions

View File

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

View File

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

View File

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