mirror of
https://github.com/home-assistant/core
synced 2024-09-03 08:14:07 +02:00
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
"""The Vulcan component."""
|
|
|
|
from aiohttp import ClientConnectorError
|
|
from vulcan import Account, Keystore, UnauthorizedCertificateException, Vulcan
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
|
|
from .const import DOMAIN
|
|
|
|
PLATFORMS = ["calendar"]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Set up Uonet+ Vulcan integration."""
|
|
hass.data.setdefault(DOMAIN, {})
|
|
try:
|
|
keystore = Keystore.load(entry.data["keystore"])
|
|
account = Account.load(entry.data["account"])
|
|
client = Vulcan(keystore, account, async_get_clientsession(hass))
|
|
await client.select_student()
|
|
students = await client.get_students()
|
|
for student in students:
|
|
if str(student.pupil.id) == str(entry.data["student_id"]):
|
|
client.student = student
|
|
break
|
|
except UnauthorizedCertificateException as err:
|
|
raise ConfigEntryAuthFailed("The certificate is not authorized.") from err
|
|
except ClientConnectorError as err:
|
|
raise ConfigEntryNotReady(
|
|
f"Connection error - please check your internet connection: {err}"
|
|
) from err
|
|
hass.data[DOMAIN][entry.entry_id] = client
|
|
|
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
|
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Unload a config entry."""
|
|
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
return unload_ok
|