mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Tradfri config flow enhancements (#28179)
This commit is contained in:
parent
8791a48328
commit
b61218f90e
@ -8,6 +8,7 @@ from pytradfri.api.aiocoap_api import APIFactory
|
|||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.util.json import load_json
|
from homeassistant.util.json import load_json
|
||||||
from . import config_flow # noqa pylint_disable=unused-import
|
from . import config_flow # noqa pylint_disable=unused-import
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -113,8 +114,8 @@ async def async_setup_entry(hass, entry):
|
|||||||
try:
|
try:
|
||||||
gateway_info = await api(gateway.get_gateway_info())
|
gateway_info = await api(gateway.get_gateway_info())
|
||||||
except RequestError:
|
except RequestError:
|
||||||
_LOGGER.error("Tradfri setup failed.")
|
await factory.shutdown()
|
||||||
return False
|
raise ConfigEntryNotReady
|
||||||
|
|
||||||
hass.data.setdefault(KEY_API, {})[entry.entry_id] = api
|
hass.data.setdefault(KEY_API, {})[entry.entry_id] = api
|
||||||
hass.data.setdefault(KEY_GATEWAY, {})[entry.entry_id] = gateway
|
hass.data.setdefault(KEY_GATEWAY, {})[entry.entry_id] = gateway
|
||||||
|
@ -64,13 +64,17 @@ class FlowHandler(config_entries.ConfigFlow):
|
|||||||
errors[KEY_SECURITY_CODE] = err.code
|
errors[KEY_SECURITY_CODE] = err.code
|
||||||
else:
|
else:
|
||||||
errors["base"] = err.code
|
errors["base"] = err.code
|
||||||
|
else:
|
||||||
|
user_input = {}
|
||||||
|
|
||||||
fields = OrderedDict()
|
fields = OrderedDict()
|
||||||
|
|
||||||
if self._host is None:
|
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(
|
return self.async_show_form(
|
||||||
step_id="auth", data_schema=vol.Schema(fields), errors=errors
|
step_id="auth", data_schema=vol.Schema(fields), errors=errors
|
||||||
|
Loading…
x
Reference in New Issue
Block a user