mirror of
https://github.com/home-assistant/core.git
synced 2025-05-03 21:49:17 +00:00

* add config flow to enigma2 * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * fix suggested change * use parametrize for config flow tests * Restore PLATFORM_SCHEMA and add create_issue to async_setup_platform * fix docstring * remove name, refactor config flow * bump dependency * remove name, add verify_ssl, use async_create_clientsession * use translation key, change integration type to device * Bump openwebifpy to 4.2.1 * cleanup, remove CONF_NAME from entity, add async_set_unique_id * clear unneeded constants, fix tests * fix tests * move _attr_translation_key out of init * update test requirement * Address review comments * address review comments * clear strings.json * Review coments --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
"""Support for Enigma2 devices."""
|
|
|
|
from openwebif.api import OpenWebIfDevice
|
|
from yarl import URL
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
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 .const import DOMAIN
|
|
|
|
PLATFORMS = [Platform.MEDIA_PLAYER]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Set up Enigma2 from a config entry."""
|
|
base_url = URL.build(
|
|
scheme="http" if not entry.data[CONF_SSL] else "https",
|
|
host=entry.data[CONF_HOST],
|
|
port=entry.data[CONF_PORT],
|
|
user=entry.data.get(CONF_USERNAME),
|
|
password=entry.data.get(CONF_PASSWORD),
|
|
)
|
|
|
|
session = async_create_clientsession(
|
|
hass, verify_ssl=entry.data[CONF_VERIFY_SSL], base_url=base_url
|
|
)
|
|
|
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = OpenWebIfDevice(session)
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Unload a config entry."""
|
|
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
return unload_ok
|