diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index fa649561e3d..250b81bb0fb 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -365,13 +365,17 @@ class Entity(ABC): if end - start > 0.4 and not self._slow_reported: self._slow_reported = True + url = "https://github.com/home-assistant/home-assistant/issues?q=is%3Aopen+is%3Aissue" + if self.platform: + url += f"+label%3A%22integration%3A+{self.platform.platform_name}%22" + _LOGGER.warning( "Updating state for %s (%s) took %.3f seconds. " - "Please report platform to the developers at " - "https://goo.gl/Nvioub", + "Please create a bug report at %s", self.entity_id, type(self), end - start, + url, ) # Overwrite properties that have been set in the config file. diff --git a/tests/helpers/test_entity.py b/tests/helpers/test_entity.py index 749c11ff1a5..9977c99904a 100644 --- a/tests/helpers/test_entity.py +++ b/tests/helpers/test_entity.py @@ -661,3 +661,22 @@ async def test_capability_attrs(hass): assert state is not None assert state.state == STATE_UNAVAILABLE assert state.attributes["always"] == "there" + + +async def test_warn_slow_write_state(hass, caplog): + """Check that we log a warning if reading properties takes too long.""" + mock_entity = entity.Entity() + mock_entity.hass = hass + mock_entity.entity_id = "comp_test.test_entity" + mock_entity.platform = MagicMock(platform_name="hue") + + with patch("homeassistant.helpers.entity.timer", side_effect=[0, 10]): + mock_entity.async_write_ha_state() + + assert ( + "Updating state for comp_test.test_entity " + "() " + "took 10.000 seconds. Please create a bug report at " + "https://github.com/home-assistant/home-assistant/issues?" + "q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+hue%22" + ) in caplog.text