From 742144f401075ce054c0b8b005e9d965b8af2a71 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 27 Jun 2018 15:21:32 -0400 Subject: [PATCH] Warn when using custom components (#15172) * Warn when using custom components * Update text --- homeassistant/loader.py | 10 +++++++++- tests/test_loader.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/homeassistant/loader.py b/homeassistant/loader.py index ce93c8705b5..e3e41e09db2 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -81,7 +81,7 @@ def get_component(hass, comp_or_platform) -> Optional[ModuleType]: potential_paths = ['custom_components.{}'.format(comp_or_platform), 'homeassistant.components.{}'.format(comp_or_platform)] - for path in potential_paths: + for index, path in enumerate(potential_paths): try: module = importlib.import_module(path) @@ -100,6 +100,14 @@ def get_component(hass, comp_or_platform) -> Optional[ModuleType]: cache[comp_or_platform] = module + if index == 0: + _LOGGER.warning( + 'You are using a custom component for %s which has not ' + 'been tested by Home Assistant. This component might ' + 'cause stability problems, be sure to disable it if you ' + 'do experience issues with Home Assistant.', + comp_or_platform) + return module except ImportError as err: diff --git a/tests/test_loader.py b/tests/test_loader.py index c97e94a7ce1..d87201fb61b 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -124,3 +124,13 @@ async def test_custom_component_name(hass): # Test custom components is mounted from custom_components.test_package import TEST assert TEST == 5 + + +async def test_log_warning_custom_component(hass, caplog): + """Test that we log a warning when loading a custom component.""" + loader.get_component(hass, 'test_standalone') + assert \ + 'You are using a custom component for test_standalone' in caplog.text + + loader.get_component(hass, 'light.test') + assert 'You are using a custom component for light.test' in caplog.text