Generic Hygrostat: Do not log warning if the hygrostat is already not active (#102662)

* Generic Hygrostat: Do not log warning if the hygrostat is already not active

* add test
This commit is contained in:
Denis Shulyaka 2024-02-16 17:29:14 +03:00 committed by GitHub
parent 085f75ef1f
commit 2d74dafd3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 2 deletions

View file

@ -396,9 +396,12 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
try:
self._cur_humidity = float(humidity)
except ValueError as ex:
_LOGGER.warning("Unable to update from sensor: %s", ex)
if self._active:
_LOGGER.warning("Unable to update from sensor: %s", ex)
self._active = False
else:
_LOGGER.debug("Unable to update from sensor: %s", ex)
self._cur_humidity = None
self._active = False
if self._is_device_active:
await self._async_device_turn_off()

View file

@ -468,6 +468,35 @@ async def test_sensor_bad_value(hass: HomeAssistant, setup_comp_2) -> None:
assert hass.states.get(ENTITY).state == STATE_UNAVAILABLE
async def test_sensor_bad_value_twice(
hass: HomeAssistant, setup_comp_2, caplog
) -> None:
"""Test sensor that the second bad value is not logged as warning."""
assert hass.states.get(ENTITY).state == STATE_ON
_setup_sensor(hass, "forty")
await hass.async_block_till_done()
assert hass.states.get(ENTITY).state == STATE_UNAVAILABLE
assert [
rec.levelname
for rec in caplog.records
if "Unable to update from sensor" in rec.message
] == ["WARNING"]
caplog.clear()
_setup_sensor(hass, "fifty")
await hass.async_block_till_done()
assert hass.states.get(ENTITY).state == STATE_UNAVAILABLE
assert [
rec.levelname
for rec in caplog.records
if "Unable to update from sensor" in rec.message
] == ["DEBUG"]
async def test_set_target_humidity_humidifier_on(
hass: HomeAssistant, setup_comp_2
) -> None: