core/homeassistant/components/bond/config_flow.py

187 lines
6.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."""
2021-03-17 22:34:25 +00:00
from __future__ import annotations
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 logging
2021-03-17 22:34:25 +00:00
from typing import Any
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,
HTTP_UNAUTHORIZED,
)
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultDict
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.typing import DiscoveryInfoType
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
from .utils import BondHub
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
_LOGGER = logging.getLogger(__name__)
USER_SCHEMA = 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}
)
DISCOVERY_SCHEMA = vol.Schema({vol.Required(CONF_ACCESS_TOKEN): str})
TOKEN_SCHEMA = 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
async def _validate_input(hass: HomeAssistant, data: dict[str, Any]) -> tuple[str, 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."""
bond = Bond(
data[CONF_HOST], data[CONF_ACCESS_TOKEN], session=async_get_clientsession(hass)
)
try:
hub = BondHub(bond)
await hub.setup(max_devices=1)
except ClientConnectionError as error:
raise InputValidationError("cannot_connect") from error
except ClientResponseError as error:
if error.status == HTTP_UNAUTHORIZED:
raise InputValidationError("invalid_auth") from error
raise InputValidationError("unknown") from error
except Exception as error:
_LOGGER.exception("Unexpected exception")
raise InputValidationError("unknown") from error
# Return unique ID from the hub to be stored in the config entry.
if not hub.bond_id:
raise InputValidationError("old_firmware")
return hub.bond_id, hub.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
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Bond."""
VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_PUSH
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) -> None:
"""Initialize config flow."""
2021-03-17 22:34:25 +00:00
self._discovered: dict[str, str] = {}
async def _async_try_automatic_configure(self) -> None:
"""Try to auto configure the device.
Failure is acceptable here since the device may have been
online longer then the allowed setup period, and we will
instead ask them to manually enter the token.
"""
bond = Bond(
self._discovered[CONF_HOST], "", session=async_get_clientsession(self.hass)
)
try:
response = await bond.token()
except ClientConnectionError:
return
token = response.get("token")
if token is None:
return
self._discovered[CONF_ACCESS_TOKEN] = token
_, hub_name = await _validate_input(self.hass, self._discovered)
self._discovered[CONF_NAME] = hub_name
async def async_step_zeroconf( # type: ignore[override]
self, discovery_info: DiscoveryInfoType
) -> FlowResultDict:
"""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_NAME: bond_id}
await self._async_try_automatic_configure()
self.context.update(
{
"title_placeholders": {
CONF_HOST: self._discovered[CONF_HOST],
CONF_NAME: self._discovered[CONF_NAME],
}
}
)
return await self.async_step_confirm()
async def async_step_confirm(
2021-03-17 22:34:25 +00:00
self, user_input: dict[str, Any] | None = None
) -> FlowResultDict:
"""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:
if CONF_ACCESS_TOKEN in self._discovered:
return self.async_create_entry(
title=self._discovered[CONF_NAME],
data={
CONF_ACCESS_TOKEN: self._discovered[CONF_ACCESS_TOKEN],
CONF_HOST: self._discovered[CONF_HOST],
},
)
data = {
CONF_ACCESS_TOKEN: user_input[CONF_ACCESS_TOKEN],
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:
_, hub_name = await _validate_input(self.hass, data)
except InputValidationError as error:
errors["base"] = error.base
else:
return self.async_create_entry(
title=hub_name,
data=data,
)
if CONF_ACCESS_TOKEN in self._discovered:
data_schema = TOKEN_SCHEMA
else:
data_schema = DISCOVERY_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
return self.async_show_form(
step_id="confirm",
data_schema=data_schema,
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(
2021-03-17 22:34:25 +00:00
self, user_input: dict[str, Any] | None = None
) -> FlowResultDict:
"""Handle a flow initialized by the user."""
errors = {}
if user_input is not None:
try:
bond_id, hub_name = await _validate_input(self.hass, user_input)
except InputValidationError as error:
errors["base"] = error.base
else:
await self.async_set_unique_id(bond_id)
self._abort_if_unique_id_configured()
return self.async_create_entry(title=hub_name, data=user_input)
return self.async_show_form(
step_id="user", data_schema=USER_SCHEMA, errors=errors
)
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