mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Replace Float 'nan' with None for modbus floats (#93832)
Co-authored-by: jan iversen <jancasacondor@gmail.com>
This commit is contained in:
parent
c4a5373976
commit
56dd88db17
@ -218,6 +218,9 @@ class BaseStructPlatform(BasePlatform, RestoreEntity):
|
||||
# the conversion only when it's absolutely necessary.
|
||||
if isinstance(v_temp, int) and self._precision == 0:
|
||||
v_result.append(str(v_temp))
|
||||
elif v_temp != v_temp: # noqa: PLR0124
|
||||
# NaN float detection replace with None
|
||||
v_result.append("nan") # pragma: no cover
|
||||
else:
|
||||
v_result.append(f"{float(v_temp):.{self._precision}f}")
|
||||
return ",".join(map(str, v_result))
|
||||
@ -228,6 +231,10 @@ class BaseStructPlatform(BasePlatform, RestoreEntity):
|
||||
# We could convert int to float, and the code would still work; however
|
||||
# we lose some precision, and unit tests will fail. Therefore, we do
|
||||
# the conversion only when it's absolutely necessary.
|
||||
|
||||
# NaN float detection replace with None
|
||||
if val_result != val_result: # noqa: PLR0124
|
||||
return None # pragma: no cover
|
||||
if isinstance(val_result, int) and self._precision == 0:
|
||||
return str(val_result)
|
||||
if isinstance(val_result, str):
|
||||
|
Loading…
x
Reference in New Issue
Block a user