1 """Shark IQ Integration."""
4 from contextlib
import suppress
9 SharkIqAuthExpiringError,
10 SharkIqNotAuthedError,
14 from homeassistant
import exceptions
25 SHARKIQ_REGION_DEFAULT,
26 SHARKIQ_REGION_EUROPE,
28 from .coordinator
import SharkIqUpdateCoordinator
32 """Error to indicate we cannot connect."""
36 """Connect to vacuum."""
38 async
with asyncio.timeout(API_TIMEOUT):
39 LOGGER.debug(
"Initialize connection to Ayla networks API")
40 await ayla_api.async_sign_in()
41 except SharkIqAuthError:
42 LOGGER.error(
"Authentication error connecting to Shark IQ api")
44 except TimeoutError
as exc:
45 LOGGER.error(
"Timeout expired")
46 raise CannotConnect
from exc
52 """Initialize the sharkiq platform via config entry."""
53 if CONF_REGION
not in config_entry.data:
54 hass.config_entries.async_update_entry(
56 data={**config_entry.data, CONF_REGION: SHARKIQ_REGION_DEFAULT},
59 ayla_api = get_ayla_api(
60 username=config_entry.data[CONF_USERNAME],
61 password=config_entry.data[CONF_PASSWORD],
63 europe=(config_entry.data[CONF_REGION] == SHARKIQ_REGION_EUROPE),
69 except CannotConnect
as exc:
72 shark_vacs = await ayla_api.async_get_devices(
False)
73 device_names =
", ".join(d.name
for d
in shark_vacs)
74 LOGGER.debug(
"Found %d Shark IQ device(s): %s", len(shark_vacs), device_names)
77 await coordinator.async_config_entry_first_refresh()
79 hass.data.setdefault(DOMAIN, {})
80 hass.data[DOMAIN][config_entry.entry_id] = coordinator
82 await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
88 """Disconnect to vacuum."""
89 LOGGER.debug(
"Disconnecting from Ayla Api")
90 async
with asyncio.timeout(5):
92 SharkIqAuthError, SharkIqAuthExpiringError, SharkIqNotAuthedError
94 await coordinator.ayla_api.async_sign_out()
99 await hass.config_entries.async_reload(config_entry.entry_id)
103 """Unload a config entry."""
104 unload_ok = await hass.config_entries.async_unload_platforms(
105 config_entry, PLATFORMS
108 domain_data = hass.data[DOMAIN][config_entry.entry_id]
109 with suppress(SharkIqAuthError):
111 hass.data[DOMAIN].pop(config_entry.entry_id)
def async_update_options(hass, config_entry)
bool async_connect_or_timeout(AylaApi ayla_api)
bool async_unload_entry(HomeAssistant hass, ConfigEntry config_entry)
def async_disconnect_or_timeout(SharkIqUpdateCoordinator coordinator)
bool async_setup_entry(HomeAssistant hass, ConfigEntry config_entry)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)