1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-01 19:57:08 +01:00
Files
core/homeassistant/components/youless/__init__.py
T
epenet 3222472f10 Use runtime_data in youless (#168694)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-04-21 12:44:18 +02:00

40 lines
1.2 KiB
Python

"""The youless integration."""
import logging
from urllib.error import URLError
from youless_api import YoulessAPI
from homeassistant.const import CONF_HOST, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from .coordinator import YouLessConfigEntry, YouLessCoordinator
PLATFORMS = [Platform.SENSOR]
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass: HomeAssistant, entry: YouLessConfigEntry) -> bool:
"""Set up youless from a config entry."""
api = YoulessAPI(entry.data[CONF_HOST])
try:
await hass.async_add_executor_job(api.initialize)
except URLError as exception:
raise ConfigEntryNotReady from exception
youless_coordinator = YouLessCoordinator(hass, entry, api)
await youless_coordinator.async_config_entry_first_refresh()
entry.runtime_data = youless_coordinator
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: YouLessConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)