mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Fix handling of NaN float values for current humidity in ESPHome (#139600)
fixes #131837
This commit is contained in:
parent
56ddfa9ff8
commit
89b655c192
@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from functools import partial
|
||||
from math import isfinite
|
||||
from typing import Any, cast
|
||||
|
||||
from aioesphomeapi import (
|
||||
@ -238,9 +239,13 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti
|
||||
@esphome_state_property
|
||||
def current_humidity(self) -> int | None:
|
||||
"""Return the current humidity."""
|
||||
if not self._static_info.supports_current_humidity:
|
||||
if (
|
||||
not self._static_info.supports_current_humidity
|
||||
or (val := self._state.current_humidity) is None
|
||||
or not isfinite(val)
|
||||
):
|
||||
return None
|
||||
return round(self._state.current_humidity)
|
||||
return round(val)
|
||||
|
||||
@property
|
||||
@esphome_float_state_property
|
||||
|
@ -407,7 +407,7 @@ async def test_climate_entity_with_inf_value(
|
||||
target_temperature=math.inf,
|
||||
fan_mode=ClimateFanMode.AUTO,
|
||||
swing_mode=ClimateSwingMode.BOTH,
|
||||
current_humidity=20.1,
|
||||
current_humidity=math.inf,
|
||||
target_humidity=25.7,
|
||||
)
|
||||
]
|
||||
@ -422,7 +422,7 @@ async def test_climate_entity_with_inf_value(
|
||||
assert state is not None
|
||||
assert state.state == HVACMode.AUTO
|
||||
attributes = state.attributes
|
||||
assert attributes[ATTR_CURRENT_HUMIDITY] == 20
|
||||
assert ATTR_CURRENT_HUMIDITY not in attributes
|
||||
assert attributes[ATTR_HUMIDITY] == 26
|
||||
assert attributes[ATTR_MAX_HUMIDITY] == 30
|
||||
assert attributes[ATTR_MIN_HUMIDITY] == 10
|
||||
|
Loading…
x
Reference in New Issue
Block a user