mirror of
https://github.com/home-assistant/core.git
synced 2026-07-01 19:57:08 +01:00
3222472f10
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
40 lines
1.2 KiB
Python
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)
|