mirror of https://github.com/home-assistant/core
Warn when using custom components (#15172)
* Warn when using custom components * Update text
This commit is contained in:
parent
c0b6a857f7
commit
742144f401
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue