1 """Config flow for Nexia integration."""
7 from nexia.const
import BRAND_ASAIR, BRAND_NEXIA, BRAND_TRANE
8 from nexia.home
import NexiaHome
9 import voluptuous
as vol
24 from .util
import is_invalid_auth_code
26 _LOGGER = logging.getLogger(__name__)
28 DATA_SCHEMA = vol.Schema(
30 vol.Required(CONF_USERNAME): str,
31 vol.Required(CONF_PASSWORD): str,
32 vol.Required(CONF_BRAND, default=BRAND_NEXIA): vol.In(
34 BRAND_NEXIA: BRAND_NEXIA_NAME,
35 BRAND_ASAIR: BRAND_ASAIR_NAME,
36 BRAND_TRANE: BRAND_TRANE_NAME,
44 """Validate the user input allows us to connect.
46 Data has the keys from DATA_SCHEMA with values provided by the user.
49 state_file = hass.config.path(
50 f
"{data[CONF_BRAND]}_config_{data[CONF_USERNAME]}.conf"
53 nexia_home = NexiaHome(
55 username=data[CONF_USERNAME],
56 password=data[CONF_PASSWORD],
57 brand=data[CONF_BRAND],
58 device_name=hass.config.location_name,
59 state_file=state_file,
62 await nexia_home.login()
63 except TimeoutError
as ex:
64 _LOGGER.error(
"Unable to connect to Nexia service: %s", ex)
65 raise CannotConnect
from ex
66 except aiohttp.ClientResponseError
as http_ex:
67 _LOGGER.error(
"HTTP error from Nexia service: %s", http_ex)
69 raise InvalidAuth
from http_ex
70 raise CannotConnect
from http_ex
72 if not nexia_home.get_name():
75 info = {
"title": nexia_home.get_name(),
"house_id": nexia_home.house_id}
76 _LOGGER.debug(
"Setup ok with info: %s", info)
81 """Handle a config flow for Nexia."""
87 self, user_input: dict[str, Any] |
None =
None
88 ) -> ConfigFlowResult:
89 """Handle the initial step."""
91 if user_input
is not None:
95 errors[
"base"] =
"cannot_connect"
97 errors[
"base"] =
"invalid_auth"
99 _LOGGER.exception(
"Unexpected exception")
100 errors[
"base"] =
"unknown"
102 if "base" not in errors:
108 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
113 """Error to indicate we cannot connect."""
117 """Error to indicate there is invalid auth."""
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry|None async_set_unique_id(self, str|None unique_id=None, *bool raise_on_progress=True)
ConfigFlowResult async_create_entry(self, *str title, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None, Mapping[str, Any]|None options=None)
ConfigFlowResult async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_create_entry(self, *str|None title=None, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None)
def validate_input(HomeAssistant hass, data)
def is_invalid_auth_code(http_status_code)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)