diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 250b81bb0fb..92072b22df2 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -365,17 +365,25 @@ 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" + extra = "" + if "custom_components" in type(self).__module__: + extra = "Please report it to the custom component author." + else: + extra = ( + "Please create a bug report at " + "https://github.com/home-assistant/home-assistant/issues?q=is%3Aopen+is%3Aissue" + ) + if self.platform: + extra += ( + f"+label%3A%22integration%3A+{self.platform.platform_name}%22" + ) _LOGGER.warning( - "Updating state for %s (%s) took %.3f seconds. " - "Please create a bug report at %s", + "Updating state for %s (%s) took %.3f seconds. %s", self.entity_id, type(self), end - start, - url, + extra, ) # 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 9977c99904a..6dc194c09d4 100644 --- a/tests/helpers/test_entity.py +++ b/tests/helpers/test_entity.py @@ -680,3 +680,24 @@ async def test_warn_slow_write_state(hass, caplog): "https://github.com/home-assistant/home-assistant/issues?" "q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+hue%22" ) in caplog.text + + +async def test_warn_slow_write_state_custom_component(hass, caplog): + """Check that we log a warning if reading properties takes too long.""" + + class CustomComponentEntity(entity.Entity): + __module__ = "custom_components.bla.sensor" + + mock_entity = CustomComponentEntity() + 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 " + "(.CustomComponentEntity'>) " + "took 10.000 seconds. Please report it to the custom component author." + ) in caplog.text