1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +00:00

Extract config flow to own module (#13840)

* Extract config flow to own module

* Lint

* fix lint

* fix typo

* ConfigFlowHandler -> FlowHandler

* Rename to data_entry_flow
This commit is contained in:
Paulus Schoutsen
2018-04-13 10:14:53 -04:00
committed by GitHub
parent ddd2003629
commit 60508f7215
11 changed files with 428 additions and 388 deletions

View File

@@ -3,7 +3,7 @@ import asyncio
import voluptuous as vol
from homeassistant import config_entries
from homeassistant import config_entries, data_entry_flow
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http.data_validator import RequestDataValidator
@@ -24,7 +24,7 @@ def async_setup(hass):
def _prepare_json(result):
"""Convert result for JSON."""
if result['type'] != config_entries.RESULT_TYPE_FORM:
if result['type'] != data_entry_flow.RESULT_TYPE_FORM:
return result
import voluptuous_serialize
@@ -94,8 +94,8 @@ class ConfigManagerFlowIndexView(HomeAssistantView):
hass = request.app['hass']
return self.json([
flow for flow in hass.config_entries.flow.async_progress()
if flow['source'] != config_entries.SOURCE_USER])
flw for flw in hass.config_entries.flow.async_progress()
if flw['source'] != data_entry_flow.SOURCE_USER])
@RequestDataValidator(vol.Schema({
vol.Required('domain'): str,
@@ -108,9 +108,9 @@ class ConfigManagerFlowIndexView(HomeAssistantView):
try:
result = yield from hass.config_entries.flow.async_init(
data['domain'])
except config_entries.UnknownHandler:
except data_entry_flow.UnknownHandler:
return self.json_message('Invalid handler specified', 404)
except config_entries.UnknownStep:
except data_entry_flow.UnknownStep:
return self.json_message('Handler does not support init', 400)
result = _prepare_json(result)
@@ -126,13 +126,13 @@ class ConfigManagerFlowResourceView(HomeAssistantView):
@asyncio.coroutine
def get(self, request, flow_id):
"""Get the current state of a flow."""
"""Get the current state of a data_entry_flow."""
hass = request.app['hass']
try:
result = yield from hass.config_entries.flow.async_configure(
flow_id)
except config_entries.UnknownFlow:
except data_entry_flow.UnknownFlow:
return self.json_message('Invalid flow specified', 404)
result = _prepare_json(result)
@@ -148,7 +148,7 @@ class ConfigManagerFlowResourceView(HomeAssistantView):
try:
result = yield from hass.config_entries.flow.async_configure(
flow_id, data)
except config_entries.UnknownFlow:
except data_entry_flow.UnknownFlow:
return self.json_message('Invalid flow specified', 404)
except vol.Invalid:
return self.json_message('User input malformed', 400)
@@ -164,7 +164,7 @@ class ConfigManagerFlowResourceView(HomeAssistantView):
try:
hass.config_entries.flow.async_abort(flow_id)
except config_entries.UnknownFlow:
except data_entry_flow.UnknownFlow:
return self.json_message('Invalid flow specified', 404)
return self.json_message('Flow aborted')