Silence redundant warnings about slow setup (#11352)
* Downgrade slow domain setup warning
* Revert "Downgrade slow domain setup warning"
This reverts commit 64472c006b
.
* Remove warning for entity components
* Remove lint
* Fix original test with extra call
pull/11391/merge
parent
0a67195529
commit
02c3ea1917
|
@ -181,9 +181,15 @@ def _async_setup_component(hass: core.HomeAssistant,
|
|||
|
||||
start = timer()
|
||||
_LOGGER.info("Setting up %s", domain)
|
||||
warn_task = hass.loop.call_later(
|
||||
SLOW_SETUP_WARNING, _LOGGER.warning,
|
||||
"Setup of %s is taking over %s seconds.", domain, SLOW_SETUP_WARNING)
|
||||
|
||||
if hasattr(component, 'PLATFORM_SCHEMA'):
|
||||
# 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:
|
||||
if async_comp:
|
||||
|
@ -197,7 +203,8 @@ def _async_setup_component(hass: core.HomeAssistant,
|
|||
return False
|
||||
finally:
|
||||
end = timer()
|
||||
warn_task.cancel()
|
||||
if warn_task:
|
||||
warn_task.cancel()
|
||||
_LOGGER.info("Setup of domain %s took %.1f seconds.", domain, end - start)
|
||||
|
||||
if result is False:
|
||||
|
|
|
@ -456,7 +456,7 @@ def test_component_warn_slow_setup(hass):
|
|||
hass, 'test_component1', {})
|
||||
assert result
|
||||
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]
|
||||
|
||||
|
@ -464,3 +464,17 @@ def test_component_warn_slow_setup(hass):
|
|||
assert logger_method == setup._LOGGER.warning
|
||||
|
||||
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…
Reference in New Issue