Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Vulcan component."""
2 
3 from aiohttp import ClientConnectorError
4 from vulcan import Account, Keystore, UnauthorizedCertificateException, Vulcan
5 
6 from homeassistant.config_entries import ConfigEntry
7 from homeassistant.const import Platform
8 from homeassistant.core import HomeAssistant
9 from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
10 from homeassistant.helpers.aiohttp_client import async_get_clientsession
11 
12 from .const import DOMAIN
13 
14 PLATFORMS = [Platform.CALENDAR]
15 
16 
17 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
18  """Set up Uonet+ Vulcan integration."""
19  hass.data.setdefault(DOMAIN, {})
20  try:
21  keystore = Keystore.load(entry.data["keystore"])
22  account = Account.load(entry.data["account"])
23  client = Vulcan(keystore, account, async_get_clientsession(hass))
24  await client.select_student()
25  students = await client.get_students()
26  for student in students:
27  if str(student.pupil.id) == str(entry.data["student_id"]):
28  client.student = student
29  break
30  except UnauthorizedCertificateException as err:
31  raise ConfigEntryAuthFailed("The certificate is not authorized.") from err
32  except ClientConnectorError as err:
33  raise ConfigEntryNotReady(
34  f"Connection error - please check your internet connection: {err}"
35  ) from err
36  hass.data[DOMAIN][entry.entry_id] = client
37 
38  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
39 
40  return True
41 
42 
43 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
44  """Unload a config entry."""
45  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
46  hass.data[DOMAIN].pop(entry.entry_id)
47 
48  return unload_ok
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:43
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:17
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)