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:
Jason Hu 2018-08-09 04:24:14 -07:00 committed by Paulus Schoutsen
parent 39d19f2183
commit f58425dd3c
25 changed files with 128 additions and 79 deletions

View file

@ -108,7 +108,7 @@ def test_add_entry_calls_setup_entry(hass, manager):
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='title',
data={
@ -162,7 +162,7 @@ async def test_saving_and_loading(hass):
VERSION = 5
@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 Title',
data={
@ -177,7 +177,7 @@ async def test_saving_and_loading(hass):
VERSION = 3
@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 2 Title',
data={
@ -266,7 +266,7 @@ async def test_discovery_notification(hass):
with patch.dict(config_entries.HANDLERS, {'test': TestFlow}):
result = await hass.config_entries.flow.async_init(
'test', source=data_entry_flow.SOURCE_DISCOVERY)
'test', context={'source': config_entries.SOURCE_DISCOVERY})
await hass.async_block_till_done()
state = hass.states.get('persistent_notification.config_entry_discovery')
@ -294,7 +294,7 @@ async def test_discovery_notification_not_created(hass):
with patch.dict(config_entries.HANDLERS, {'test': TestFlow}):
await hass.config_entries.flow.async_init(
'test', source=data_entry_flow.SOURCE_DISCOVERY)
'test', context={'source': config_entries.SOURCE_DISCOVERY})
await hass.async_block_till_done()
state = hass.states.get('persistent_notification.config_entry_discovery')