1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-15 10:34:19 +01:00
Files
core/homeassistant/components/pyload/__init__.py
T
Manu 5c8fa717bf Move test before setup coordinator _async_setup in pyLoad integration (#138893)
Move setup test to `async_setup` in the coordinator
2025-02-20 08:14:08 +01:00

58 lines
1.5 KiB
Python

"""The pyLoad integration."""
from __future__ import annotations
from aiohttp import CookieJar
from pyloadapi.api import PyLoadAPI
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
CONF_PORT,
CONF_SSL,
CONF_USERNAME,
CONF_VERIFY_SSL,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_create_clientsession
from .coordinator import PyLoadConfigEntry, PyLoadCoordinator
PLATFORMS: list[Platform] = [Platform.BUTTON, Platform.SENSOR, Platform.SWITCH]
async def async_setup_entry(hass: HomeAssistant, entry: PyLoadConfigEntry) -> bool:
"""Set up pyLoad from a config entry."""
url = (
f"{'https' if entry.data[CONF_SSL] else 'http'}://"
f"{entry.data[CONF_HOST]}:{entry.data[CONF_PORT]}/"
)
session = async_create_clientsession(
hass,
verify_ssl=entry.data[CONF_VERIFY_SSL],
cookie_jar=CookieJar(unsafe=True),
)
pyloadapi = PyLoadAPI(
session,
api_url=url,
username=entry.data[CONF_USERNAME],
password=entry.data[CONF_PASSWORD],
)
coordinator = PyLoadCoordinator(hass, entry, pyloadapi)
await coordinator.async_config_entry_first_refresh()
entry.runtime_data = coordinator
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: PyLoadConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)