Adjust entity slow warning for custom component (#31711)
This commit is contained in:
parent
2db6246244
commit
5a0f21cbe3
2 changed files with 35 additions and 6 deletions
|
@ -365,17 +365,25 @@ class Entity(ABC):
|
||||||
|
|
||||||
if end - start > 0.4 and not self._slow_reported:
|
if end - start > 0.4 and not self._slow_reported:
|
||||||
self._slow_reported = True
|
self._slow_reported = True
|
||||||
url = "https://github.com/home-assistant/home-assistant/issues?q=is%3Aopen+is%3Aissue"
|
extra = ""
|
||||||
if self.platform:
|
if "custom_components" in type(self).__module__:
|
||||||
url += f"+label%3A%22integration%3A+{self.platform.platform_name}%22"
|
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(
|
_LOGGER.warning(
|
||||||
"Updating state for %s (%s) took %.3f seconds. "
|
"Updating state for %s (%s) took %.3f seconds. %s",
|
||||||
"Please create a bug report at %s",
|
|
||||||
self.entity_id,
|
self.entity_id,
|
||||||
type(self),
|
type(self),
|
||||||
end - start,
|
end - start,
|
||||||
url,
|
extra,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Overwrite properties that have been set in the config file.
|
# Overwrite properties that have been set in the config file.
|
||||||
|
|
|
@ -680,3 +680,24 @@ async def test_warn_slow_write_state(hass, caplog):
|
||||||
"https://github.com/home-assistant/home-assistant/issues?"
|
"https://github.com/home-assistant/home-assistant/issues?"
|
||||||
"q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+hue%22"
|
"q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+hue%22"
|
||||||
) in caplog.text
|
) 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 "
|
||||||
|
"(<class 'custom_components.bla.sensor.test_warn_slow_write_state_custom_component.<locals>.CustomComponentEntity'>) "
|
||||||
|
"took 10.000 seconds. Please report it to the custom component author."
|
||||||
|
) in caplog.text
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue