1 """Support for Neato botvac connected vacuum cleaners."""
6 from pybotvac
import Account
7 from pybotvac.exceptions
import NeatoException
16 from .const
import NEATO_DOMAIN, NEATO_LOGIN
17 from .hub
import NeatoHub
19 _LOGGER = logging.getLogger(__name__)
31 """Set up config entry."""
32 hass.data.setdefault(NEATO_DOMAIN, {})
33 if CONF_TOKEN
not in entry.data:
34 raise ConfigEntryAuthFailed
37 await config_entry_oauth2_flow.async_get_config_entry_implementation(
42 session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
44 await session.async_ensure_token_valid()
45 except aiohttp.ClientResponseError
as ex:
46 _LOGGER.debug(
"API error: %s (%s)", ex.code, ex.message)
47 if ex.code
in (401, 403):
49 raise ConfigEntryNotReady
from ex
52 hass.data[NEATO_DOMAIN][entry.entry_id] = neato_session
53 hub =
NeatoHub(hass, Account(neato_session))
55 await hub.async_update_entry_unique_id(entry)
58 await hass.async_add_executor_job(hub.update_robots)
59 except NeatoException
as ex:
60 _LOGGER.debug(
"Failed to connect to Neato API")
61 raise ConfigEntryNotReady
from ex
63 hass.data[NEATO_LOGIN] = hub
65 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
71 """Unload config entry."""
72 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
74 hass.data[NEATO_DOMAIN].pop(entry.entry_id)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)