mirror of
https://github.com/home-assistant/core.git
synced 2026-09-17 05:58:41 +01:00
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
"""The Discogs integration."""
|
|
|
|
import discogs_client
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import CONF_TOKEN
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import ConfigEntryNotReady
|
|
from homeassistant.helpers.aiohttp_client import SERVER_SOFTWARE
|
|
|
|
from .const import PLATFORMS
|
|
|
|
type DiscogsConfigEntry = ConfigEntry[discogs_client.Client]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: DiscogsConfigEntry) -> bool:
|
|
"""Set up Discogs from a config entry."""
|
|
|
|
def _setup_client() -> discogs_client.Client:
|
|
client = discogs_client.Client(
|
|
SERVER_SOFTWARE, user_token=entry.data[CONF_TOKEN]
|
|
)
|
|
client.identity()
|
|
return client
|
|
|
|
try:
|
|
client = await hass.async_add_executor_job(_setup_client)
|
|
except discogs_client.exceptions.HTTPError as err:
|
|
raise ConfigEntryNotReady(f"Error communicating with Discogs: {err}") from err
|
|
|
|
entry.runtime_data = client
|
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: DiscogsConfigEntry) -> bool:
|
|
"""Unload Discogs config entry."""
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|