core/homeassistant/components/bond/config_flow.py

125 lines
4.1 KiB
Python
Raw Normal View History

Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
"""Config flow for Bond integration."""
import logging
from typing import Any, Dict, Optional
Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
from aiohttp import ClientConnectionError, ClientResponseError
from bond_api import Bond
Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
import voluptuous as vol
from homeassistant import config_entries, exceptions
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST, CONF_NAME
Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
from .const import CONF_BOND_ID
Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
from .const import DOMAIN # pylint:disable=unused-import
_LOGGER = logging.getLogger(__name__)
DATA_SCHEMA_USER = vol.Schema(
Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
{vol.Required(CONF_HOST): str, vol.Required(CONF_ACCESS_TOKEN): str}
)
DATA_SCHEMA_DISCOVERY = vol.Schema({vol.Required(CONF_ACCESS_TOKEN): str})
Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
async def _validate_input(data: Dict[str, Any]) -> str:
Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
"""Validate the user input allows us to connect."""
try:
bond = Bond(data[CONF_HOST], data[CONF_ACCESS_TOKEN])
version = await bond.version()
# call to non-version API is needed to validate authentication
await bond.devices()
except ClientConnectionError:
raise InputValidationError("cannot_connect")
except ClientResponseError as error:
if error.status == 401:
raise InputValidationError("invalid_auth")
raise InputValidationError("unknown")
except Exception:
_LOGGER.exception("Unexpected exception")
raise InputValidationError("unknown")
# Return unique ID from the hub to be stored in the config entry.
bond_id = version.get("bondid")
if not bond_id:
raise InputValidationError("old_firmware")
return bond_id
Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Bond."""
VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
_discovered: dict = None
async def async_step_zeroconf(
self, discovery_info: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]:
"""Handle a flow initialized by zeroconf discovery."""
name: str = discovery_info[CONF_NAME]
host: str = discovery_info[CONF_HOST]
bond_id = name.partition(".")[0]
await self.async_set_unique_id(bond_id)
self._abort_if_unique_id_configured({CONF_HOST: host})
self._discovered = {
CONF_HOST: host,
CONF_BOND_ID: bond_id,
}
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
self.context.update({"title_placeholders": self._discovered})
return await self.async_step_confirm()
async def async_step_confirm(
self, user_input: Dict[str, Any] = None
) -> Dict[str, Any]:
"""Handle confirmation flow for discovered bond hub."""
Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
errors = {}
if user_input is not None:
data = user_input.copy()
data[CONF_HOST] = self._discovered[CONF_HOST]
Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
try:
return await self._try_create_entry(data)
except InputValidationError as error:
errors["base"] = error.base
Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
return self.async_show_form(
step_id="confirm",
data_schema=DATA_SCHEMA_DISCOVERY,
errors=errors,
description_placeholders=self._discovered,
Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
)
async def async_step_user(
self, user_input: Dict[str, Any] = None
) -> Dict[str, Any]:
"""Handle a flow initialized by the user."""
errors = {}
if user_input is not None:
try:
return await self._try_create_entry(user_input)
except InputValidationError as error:
errors["base"] = error.base
return self.async_show_form(
step_id="user", data_schema=DATA_SCHEMA_USER, errors=errors
)
async def _try_create_entry(self, data: Dict[str, Any]) -> Dict[str, Any]:
bond_id = await _validate_input(data)
await self.async_set_unique_id(bond_id)
self._abort_if_unique_id_configured()
return self.async_create_entry(title=bond_id, data=data)
Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
class InputValidationError(exceptions.HomeAssistantError):
"""Error to indicate we cannot proceed due to invalid input."""
Add new integration for Bond hub (#37477) * create foundation for Bond integration * add Bond hub integration (fix lint) * Update homeassistant/components/bond/__init__.py adding async_unload_entry per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix missing import after applying PR suggestion) * Update tests/components/bond/test_init.py add a unit for unloading per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py add unit test for unload per PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py PR review suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (fix formatting) * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/strings.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/manifest.json PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update requirements_test_all.txt PR suggestion Co-authored-by: Chris Talkington <chris@talkingtontech.com> * add Bond hub integration (remove friendly name from config per PR suggestion) * Update homeassistant/components/bond/__init__.py add per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update homeassistant/components/bond/__init__.py remove per PR review feedback Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update tests/components/bond/test_init.py fix unit test Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
2020-07-06 01:17:53 +00:00
def __init__(self, base: str):
"""Initialize with error base."""
super().__init__()
self.base = base