From 02c3ea1917b9bfd4c3c6e9b350676e249351e10b Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Tue, 2 Jan 2018 21:16:32 +0100 Subject: [PATCH] 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 --- homeassistant/setup.py | 15 +++++++++++---- tests/test_setup.py | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/homeassistant/setup.py b/homeassistant/setup.py index 05a8ee1e2f1..12a39e80517 100644 --- a/homeassistant/setup.py +++ b/homeassistant/setup.py @@ -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: diff --git a/tests/test_setup.py b/tests/test_setup.py index 9a0f85874ad..afea30ddcd1 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -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