Support config flow on custom components (#24946)
* Support populating list of flows from custom components * Re-allow custom component config flows * Add tests for custom component retrieval * Don't crash view if no handler exist * Use get_custom_components instead fo resolve_from_root * Switch to using an event instead of lock * Leave list of integrations as set * The returned list is not guaranteed to be ordered Backend uses a set to represent them.
This commit is contained in:
1 parent
a2237ce5d4
commit
2fbbcafaed
6 files changed
+149
-31
No files matched your search
@@ -1,4 +1,5 @@
|
||||
"""Test to verify that we can load components."""
|
||||
from asynctest.mock import ANY, patch
|
||||
import pytest
|
||||
|
||||
import homeassistant.loader as loader
|
||||
@@ -172,3 +173,57 @@ async def test_integrations_only_once(hass):
|
||||
loader.async_get_integration(hass, 'hue'))
|
||||
|
||||
assert await int_1 is await int_2
|
||||
|
||||
|
||||
async def test_get_custom_components_internal(hass):
|
||||
"""Test that we can a list of custom components."""
|
||||
# pylint: disable=protected-access
|
||||
integrations = await loader._async_get_custom_components(hass)
|
||||
assert integrations == {
|
||||
'test': ANY,
|
||||
"test_package": ANY
|
||||
}
|
||||
|
||||
|
||||
def _get_test_integration(hass, name, config_flow):
|
||||
"""Return a generated test integration."""
|
||||
return loader.Integration(
|
||||
hass, "homeassistant.components.{}".format(name), None, {
|
||||
'name': name,
|
||||
'domain': name,
|
||||
'config_flow': config_flow,
|
||||
'dependencies': [],
|
||||
'requirements': []})
|
||||
|
||||
|
||||
async def test_get_custom_components(hass):
|
||||
"""Verify that custom components are cached."""
|
||||
test_1_integration = _get_test_integration(hass, 'test_1', False)
|
||||
test_2_integration = _get_test_integration(hass, 'test_2', True)
|
||||
|
||||
name = 'homeassistant.loader._async_get_custom_components'
|
||||
with patch(name) as mock_get:
|
||||
mock_get.return_value = {
|
||||
'test_1': test_1_integration,
|
||||
'test_2': test_2_integration,
|
||||
}
|
||||
integrations = await loader.async_get_custom_components(hass)
|
||||
assert integrations == mock_get.return_value
|
||||
integrations = await loader.async_get_custom_components(hass)
|
||||
assert integrations == mock_get.return_value
|
||||
mock_get.assert_called_once_with(hass)
|
||||
|
||||
|
||||
async def test_get_config_flows(hass):
|
||||
"""Verify that custom components with config_flow are available."""
|
||||
test_1_integration = _get_test_integration(hass, 'test_1', False)
|
||||
test_2_integration = _get_test_integration(hass, 'test_2', True)
|
||||
|
||||
with patch('homeassistant.loader.async_get_custom_components') as mock_get:
|
||||
mock_get.return_value = {
|
||||
'test_1': test_1_integration,
|
||||
'test_2': test_2_integration,
|
||||
}
|
||||
flows = await loader.async_get_config_flows(hass)
|
||||
assert 'test_2' in flows
|
||||
assert 'test_1' not in flows
|
||||
Reference in new issue
Block a user