Refactor data entry flow (#15883)
* Refactoring data_entry_flow and config_entry_flow Move SOURCE_* to config_entries Change data_entry_flow.FlowManager.async_init() source param default to None Change this first step_id as source or init if source is None _BaseFlowManagerView pass in SOURCE_USER as default source * First step of data entry flow decided by _async_create_flow() now * Lint * Change helpers.config_entry_flow.DiscoveryFlowHandler default step * Change FlowManager.async_init source param to context dict param
This commit is contained in:
1 parent
39d19f2183
commit
f58425dd3c
25 files changed
+128
-79
No files matched your search
@@ -102,13 +102,13 @@ def test_initialize_flow(hass, client):
|
||||
"""Test we can initialize a flow."""
|
||||
class TestFlow(FlowHandler):
|
||||
@asyncio.coroutine
|
||||
def async_step_init(self, user_input=None):
|
||||
def async_step_user(self, user_input=None):
|
||||
schema = OrderedDict()
|
||||
schema[vol.Required('username')] = str
|
||||
schema[vol.Required('password')] = str
|
||||
|
||||
return self.async_show_form(
|
||||
step_id='init',
|
||||
step_id='user',
|
||||
data_schema=schema,
|
||||
description_placeholders={
|
||||
'url': 'https://example.com',
|
||||
@@ -130,7 +130,7 @@ def test_initialize_flow(hass, client):
|
||||
assert data == {
|
||||
'type': 'form',
|
||||
'handler': 'test',
|
||||
'step_id': 'init',
|
||||
'step_id': 'user',
|
||||
'data_schema': [
|
||||
{
|
||||
'name': 'username',
|
||||
@@ -157,7 +157,7 @@ def test_abort(hass, client):
|
||||
"""Test a flow that aborts."""
|
||||
class TestFlow(FlowHandler):
|
||||
@asyncio.coroutine
|
||||
def async_step_init(self, user_input=None):
|
||||
def async_step_user(self, user_input=None):
|
||||
return self.async_abort(reason='bla')
|
||||
|
||||
with patch.dict(HANDLERS, {'test': TestFlow}):
|
||||
@@ -185,7 +185,7 @@ def test_create_account(hass, client):
|
||||
VERSION = 1
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_step_init(self, user_input=None):
|
||||
def async_step_user(self, user_input=None):
|
||||
return self.async_create_entry(
|
||||
title='Test Entry',
|
||||
data={'secret': 'account_token'}
|
||||
@@ -218,7 +218,7 @@ def test_two_step_flow(hass, client):
|
||||
VERSION = 1
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_step_init(self, user_input=None):
|
||||
def async_step_user(self, user_input=None):
|
||||
return self.async_show_form(
|
||||
step_id='account',
|
||||
data_schema=vol.Schema({
|
||||
@@ -286,7 +286,7 @@ def test_get_progress_index(hass, client):
|
||||
|
||||
with patch.dict(HANDLERS, {'test': TestFlow}):
|
||||
form = yield from hass.config_entries.flow.async_init(
|
||||
'test', source='hassio')
|
||||
'test', context={'source': 'hassio'})
|
||||
|
||||
resp = yield from client.get('/api/config/config_entries/flow')
|
||||
assert resp.status == 200
|
||||
@@ -305,13 +305,13 @@ def test_get_progress_flow(hass, client):
|
||||
"""Test we can query the API for same result as we get from init a flow."""
|
||||
class TestFlow(FlowHandler):
|
||||
@asyncio.coroutine
|
||||
def async_step_init(self, user_input=None):
|
||||
def async_step_user(self, user_input=None):
|
||||
schema = OrderedDict()
|
||||
schema[vol.Required('username')] = str
|
||||
schema[vol.Required('password')] = str
|
||||
|
||||
return self.async_show_form(
|
||||
step_id='init',
|
||||
step_id='user',
|
||||
data_schema=schema,
|
||||
errors={
|
||||
'username': 'Should be unique.'
|
||||
|
||||
@@ -5,7 +5,7 @@ from unittest.mock import patch, MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components import discovery
|
||||
from homeassistant.util.dt import utcnow
|
||||
@@ -175,5 +175,5 @@ async def test_discover_config_flow(hass):
|
||||
assert len(m_init.mock_calls) == 1
|
||||
args, kwargs = m_init.mock_calls[0][1:]
|
||||
assert args == ('mock-component',)
|
||||
assert kwargs['source'] == data_entry_flow.SOURCE_DISCOVERY
|
||||
assert kwargs['context']['source'] == config_entries.SOURCE_DISCOVERY
|
||||
assert kwargs['data'] == discovery_info
|
||||
Reference in new issue
Block a user