Warn when user tries run custom config flow (#24657)

pull/24776/head
Paulus Schoutsen 2019-06-20 13:22:12 -07:00
parent da12ceae5b
commit d4cab60343
4 changed files with 38 additions and 1 deletions

View File

@ -553,6 +553,14 @@ class ConfigEntries:
_LOGGER.error('Cannot find integration %s', handler_key)
raise data_entry_flow.UnknownHandler
# Our config flow list is based on built-in integrations. If overriden,
# we should not load it's config flow.
if not integration.is_built_in:
_LOGGER.error(
'Config flow is not supported for custom integration %s',
handler_key)
raise data_entry_flow.UnknownHandler
# Make sure requirements and dependencies of component are resolved
await async_process_deps_reqs(
self.hass, self._hass_config, integration)

View File

@ -123,6 +123,11 @@ class Integration:
self.requirements = manifest['requirements'] # type: List[str]
_LOGGER.info("Loaded %s from %s", self.domain, pkg_path)
@property
def is_built_in(self) -> bool:
"""Test if package is a built-in integration."""
return self.pkg_path.startswith(PACKAGE_BUILTIN)
def get_component(self) -> ModuleType:
"""Return the component."""
cache = self.hass.data.setdefault(DATA_COMPONENTS, {})

View File

@ -5,7 +5,7 @@ from unittest.mock import MagicMock, patch
import pytest
from homeassistant import config_entries, data_entry_flow
from homeassistant import config_entries, data_entry_flow, loader
from homeassistant.core import callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.setup import async_setup_component
@ -934,3 +934,17 @@ async def test_entry_reload_error(hass, manager, state):
assert len(async_setup_entry.mock_calls) == 0
assert entry.state == state
async def test_init_custom_integration(hass):
"""Test initializing flow for custom integration."""
integration = loader.Integration(hass, 'custom_components.hue', None, {
'name': 'Hue',
'dependencies': [],
'requirements': [],
'domain': 'hue',
})
with pytest.raises(data_entry_flow.UnknownHandler):
with patch('homeassistant.loader.async_get_integration',
return_value=mock_coro(integration)):
await hass.config_entries.flow.async_init('bla')

View File

@ -152,6 +152,16 @@ def test_integration_properties(hass):
assert integration.domain == 'hue'
assert integration.dependencies == ['test-dep']
assert integration.requirements == ['test-req==1.0.0']
assert integration.is_built_in is True
integration = loader.Integration(
hass, 'custom_components.hue', None, {
'name': 'Philips Hue',
'domain': 'hue',
'dependencies': ['test-dep'],
'requirements': ['test-req==1.0.0'],
})
assert integration.is_built_in is False
async def test_integrations_only_once(hass):