Tradfri config flow enhancements (#28179)

pull/28186/head
Joakim Sørensen 2019-10-24 21:31:58 +02:00 committed by Martin Hjelmare
parent 8791a48328
commit b61218f90e
2 changed files with 9 additions and 4 deletions

View File

@ -8,6 +8,7 @@ from pytradfri.api.aiocoap_api import APIFactory
import homeassistant.helpers.config_validation as cv
from homeassistant import config_entries
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.util.json import load_json
from . import config_flow # noqa pylint_disable=unused-import
from .const import (
@ -113,8 +114,8 @@ async def async_setup_entry(hass, entry):
try:
gateway_info = await api(gateway.get_gateway_info())
except RequestError:
_LOGGER.error("Tradfri setup failed.")
return False
await factory.shutdown()
raise ConfigEntryNotReady
hass.data.setdefault(KEY_API, {})[entry.entry_id] = api
hass.data.setdefault(KEY_GATEWAY, {})[entry.entry_id] = gateway

View File

@ -64,13 +64,17 @@ class FlowHandler(config_entries.ConfigFlow):
errors[KEY_SECURITY_CODE] = err.code
else:
errors["base"] = err.code
else:
user_input = {}
fields = OrderedDict()
if self._host is None:
fields[vol.Required(CONF_HOST)] = str
fields[vol.Required(CONF_HOST, default=user_input.get(CONF_HOST))] = str
fields[vol.Required(KEY_SECURITY_CODE)] = str
fields[
vol.Required(KEY_SECURITY_CODE, default=user_input.get(KEY_SECURITY_CODE))
] = str
return self.async_show_form(
step_id="auth", data_schema=vol.Schema(fields), errors=errors