mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Adjust entity slow warning for custom component (#31711)
This commit is contained in:
parent
2db6246244
commit
5a0f21cbe3
@ -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.
|
||||
|
@ -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 "
|
||||
"(<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…
x
Reference in New Issue
Block a user