Fix incorrect warn of async_update_ha_state use (#91387)

This commit is contained in:
Franck Nijhof 2023-04-13 22:39:03 +02:00 committed by GitHub
parent b7b22b79d1
commit 32344a8488
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -555,8 +555,7 @@ class Entity(ABC):
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
_LOGGER.exception("Update for %s fails", self.entity_id) _LOGGER.exception("Update for %s fails", self.entity_id)
return return
elif not self._async_update_ha_state_reported:
if not self._async_update_ha_state_reported:
report_issue = self._suggest_report_issue() report_issue = self._suggest_report_issue()
_LOGGER.warning( _LOGGER.warning(
( (

View file

@ -996,10 +996,17 @@ async def test_warn_using_async_update_ha_state(
ent.hass = hass ent.hass = hass
ent.entity_id = "hello.world" ent.entity_id = "hello.world"
# When forcing, it should not trigger the warning
caplog.clear()
await ent.async_update_ha_state(force_refresh=True)
assert "is using self.async_update_ha_state()" not in caplog.text
# When not forcing, it should trigger the warning
caplog.clear() caplog.clear()
await ent.async_update_ha_state() await ent.async_update_ha_state()
assert "is using self.async_update_ha_state()" in caplog.text assert "is using self.async_update_ha_state()" in caplog.text
# When not forcing, it should not trigger the warning again
caplog.clear() caplog.clear()
await ent.async_update_ha_state() await ent.async_update_ha_state()
assert "is using self.async_update_ha_state()" not in caplog.text assert "is using self.async_update_ha_state()" not in caplog.text