1 """The pyLoad integration."""
3 from __future__
import annotations
5 from aiohttp
import CookieJar
6 from pyloadapi.api
import PyLoadAPI
7 from pyloadapi.exceptions
import CannotConnect, InvalidAuth, ParserError
23 from .const
import DOMAIN
24 from .coordinator
import PyLoadCoordinator
26 PLATFORMS: list[Platform] = [Platform.BUTTON, Platform.SENSOR, Platform.SWITCH]
28 type PyLoadConfigEntry = ConfigEntry[PyLoadCoordinator]
32 """Set up pyLoad from a config entry."""
35 f
"{"https
" if entry.data[CONF_SSL] else "http
"}://"
36 f
"{entry.data[CONF_HOST]}:{entry.data[CONF_PORT]}/"
41 verify_ssl=entry.data[CONF_VERIFY_SSL],
42 cookie_jar=CookieJar(unsafe=
True),
44 pyloadapi = PyLoadAPI(
47 username=entry.data[CONF_USERNAME],
48 password=entry.data[CONF_PASSWORD],
52 await pyloadapi.login()
53 except CannotConnect
as e:
55 translation_domain=DOMAIN,
56 translation_key=
"setup_request_exception",
58 except ParserError
as e:
60 translation_domain=DOMAIN,
61 translation_key=
"setup_parse_exception",
63 except InvalidAuth
as e:
65 translation_domain=DOMAIN,
66 translation_key=
"setup_authentication_exception",
67 translation_placeholders={CONF_USERNAME: entry.data[CONF_USERNAME]},
71 await coordinator.async_config_entry_first_refresh()
73 entry.runtime_data = coordinator
74 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
80 """Unload a config entry."""
81 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, PyLoadConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, PyLoadConfigEntry entry)
aiohttp.ClientSession async_create_clientsession()