2020-06-03 12:01:56 +00:00
|
|
|
"""The Dune HD component."""
|
2021-05-24 19:09:57 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from typing import Final
|
|
|
|
|
2020-06-03 12:01:56 +00:00
|
|
|
from pdunehd import DuneHDPlayer
|
|
|
|
|
2021-05-24 19:09:57 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-12-03 16:51:30 +00:00
|
|
|
from homeassistant.const import CONF_HOST, Platform
|
2021-05-24 19:09:57 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2020-06-03 12:01:56 +00:00
|
|
|
|
|
|
|
from .const import DOMAIN
|
|
|
|
|
2021-12-03 16:51:30 +00:00
|
|
|
PLATFORMS: Final[list[Platform]] = [Platform.MEDIA_PLAYER]
|
2020-06-03 12:01:56 +00:00
|
|
|
|
|
|
|
|
2021-05-24 19:09:57 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2020-06-03 12:01:56 +00:00
|
|
|
"""Set up a config entry."""
|
2021-05-24 19:09:57 +00:00
|
|
|
host: str = entry.data[CONF_HOST]
|
2020-06-03 12:01:56 +00:00
|
|
|
|
|
|
|
player = DuneHDPlayer(host)
|
|
|
|
|
|
|
|
hass.data.setdefault(DOMAIN, {})
|
2021-04-27 06:46:49 +00:00
|
|
|
hass.data[DOMAIN][entry.entry_id] = player
|
2020-06-03 12:01:56 +00:00
|
|
|
|
2021-04-27 06:46:49 +00:00
|
|
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
2020-06-03 12:01:56 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2021-05-24 19:09:57 +00:00
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2020-06-03 12:01:56 +00:00
|
|
|
"""Unload a config entry."""
|
2021-04-27 06:46:49 +00:00
|
|
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
2020-06-03 12:01:56 +00:00
|
|
|
if unload_ok:
|
2021-04-27 06:46:49 +00:00
|
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
2020-06-03 12:01:56 +00:00
|
|
|
|
|
|
|
return unload_ok
|