Update link when IO in event loop (#31519)

pull/31528/head
Paulus Schoutsen 2020-02-06 02:37:35 -08:00 committed by GitHub
parent 8d429d7676
commit a3b3924e21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -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.

View File

@ -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 "
"(<class 'homeassistant.helpers.entity.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