From 32344a8488b44e39bcf75c4043979e61551750c6 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 13 Apr 2023 22:39:03 +0200 Subject: [PATCH] Fix incorrect warn of async_update_ha_state use (#91387) --- homeassistant/helpers/entity.py | 3 +-- tests/helpers/test_entity.py | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 023922a5814..9dbd5d4ad67 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -555,8 +555,7 @@ class Entity(ABC): except Exception: # pylint: disable=broad-except _LOGGER.exception("Update for %s fails", self.entity_id) return - - if not self._async_update_ha_state_reported: + elif not self._async_update_ha_state_reported: report_issue = self._suggest_report_issue() _LOGGER.warning( ( diff --git a/tests/helpers/test_entity.py b/tests/helpers/test_entity.py index 24bed13ef44..bb95860142d 100644 --- a/tests/helpers/test_entity.py +++ b/tests/helpers/test_entity.py @@ -996,10 +996,17 @@ async def test_warn_using_async_update_ha_state( ent.hass = hass 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() await ent.async_update_ha_state() assert "is using self.async_update_ha_state()" in caplog.text + # When not forcing, it should not trigger the warning again caplog.clear() await ent.async_update_ha_state() assert "is using self.async_update_ha_state()" not in caplog.text