Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail when user tries run custom config flow #24657

Merged
merged 1 commit into from Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions homeassistant/config_entries.py
Expand Up @@ -553,6 +553,14 @@ async def _async_create_flow(self, handler_key, *, context, data):
_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)
Expand Down
5 changes: 5 additions & 0 deletions homeassistant/loader.py
Expand Up @@ -123,6 +123,11 @@ def __init__(self, hass: 'HomeAssistant', pkg_path: str,
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, {})
Expand Down
16 changes: 15 additions & 1 deletion tests/test_config_entries.py
Expand Up @@ -5,7 +5,7 @@

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
Expand Down Expand Up @@ -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')
10 changes: 10 additions & 0 deletions tests/test_loader.py
Expand Up @@ -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):
Expand Down