mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 10:17:51 +00:00
Silence redundant warnings about slow setup (#11352)
* Downgrade slow domain setup warning * Revert "Downgrade slow domain setup warning" This reverts commit 64472c006bb553c6bb75a024384361adad50d565. * Remove warning for entity components * Remove lint * Fix original test with extra call
This commit is contained in:
parent
0a67195529
commit
02c3ea1917
@ -181,9 +181,15 @@ def _async_setup_component(hass: core.HomeAssistant,
|
|||||||
|
|
||||||
start = timer()
|
start = timer()
|
||||||
_LOGGER.info("Setting up %s", domain)
|
_LOGGER.info("Setting up %s", domain)
|
||||||
warn_task = hass.loop.call_later(
|
|
||||||
SLOW_SETUP_WARNING, _LOGGER.warning,
|
if hasattr(component, 'PLATFORM_SCHEMA'):
|
||||||
"Setup of %s is taking over %s seconds.", domain, SLOW_SETUP_WARNING)
|
# Entity components have their own warning
|
||||||
|
warn_task = None
|
||||||
|
else:
|
||||||
|
warn_task = hass.loop.call_later(
|
||||||
|
SLOW_SETUP_WARNING, _LOGGER.warning,
|
||||||
|
"Setup of %s is taking over %s seconds.",
|
||||||
|
domain, SLOW_SETUP_WARNING)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if async_comp:
|
if async_comp:
|
||||||
@ -197,7 +203,8 @@ def _async_setup_component(hass: core.HomeAssistant,
|
|||||||
return False
|
return False
|
||||||
finally:
|
finally:
|
||||||
end = timer()
|
end = timer()
|
||||||
warn_task.cancel()
|
if warn_task:
|
||||||
|
warn_task.cancel()
|
||||||
_LOGGER.info("Setup of domain %s took %.1f seconds.", domain, end - start)
|
_LOGGER.info("Setup of domain %s took %.1f seconds.", domain, end - start)
|
||||||
|
|
||||||
if result is False:
|
if result is False:
|
||||||
|
@ -456,7 +456,7 @@ def test_component_warn_slow_setup(hass):
|
|||||||
hass, 'test_component1', {})
|
hass, 'test_component1', {})
|
||||||
assert result
|
assert result
|
||||||
assert mock_call.called
|
assert mock_call.called
|
||||||
assert len(mock_call.mock_calls) == 2
|
assert len(mock_call.mock_calls) == 3
|
||||||
|
|
||||||
timeout, logger_method = mock_call.mock_calls[0][1][:2]
|
timeout, logger_method = mock_call.mock_calls[0][1][:2]
|
||||||
|
|
||||||
@ -464,3 +464,17 @@ def test_component_warn_slow_setup(hass):
|
|||||||
assert logger_method == setup._LOGGER.warning
|
assert logger_method == setup._LOGGER.warning
|
||||||
|
|
||||||
assert mock_call().cancel.called
|
assert mock_call().cancel.called
|
||||||
|
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def test_platform_no_warn_slow(hass):
|
||||||
|
"""Do not warn for long entity setup time."""
|
||||||
|
loader.set_component(
|
||||||
|
'test_component1',
|
||||||
|
MockModule('test_component1', platform_schema=PLATFORM_SCHEMA))
|
||||||
|
with mock.patch.object(hass.loop, 'call_later', mock.MagicMock()) \
|
||||||
|
as mock_call:
|
||||||
|
result = yield from setup.async_setup_component(
|
||||||
|
hass, 'test_component1', {})
|
||||||
|
assert result
|
||||||
|
assert not mock_call.called
|
||||||
|
Loading…
x
Reference in New Issue
Block a user