Use runtime_data for enigma2 (#119154)

* Use runtime_data for enigma2

* Update __init__.py
This commit is contained in:
Sid 2024-06-08 20:40:34 +02:00 committed by GitHub
parent ae0e751a6d
commit a662ee772c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 9 deletions

View File

@ -16,12 +16,12 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_create_clientsession from homeassistant.helpers.aiohttp_client import async_create_clientsession
from .const import DOMAIN type Enigma2ConfigEntry = ConfigEntry[OpenWebIfDevice]
PLATFORMS = [Platform.MEDIA_PLAYER] PLATFORMS = [Platform.MEDIA_PLAYER]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: Enigma2ConfigEntry) -> bool:
"""Set up Enigma2 from a config entry.""" """Set up Enigma2 from a config entry."""
base_url = URL.build( base_url = URL.build(
scheme="http" if not entry.data[CONF_SSL] else "https", scheme="http" if not entry.data[CONF_SSL] else "https",
@ -35,14 +35,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass, verify_ssl=entry.data[CONF_VERIFY_SSL], base_url=base_url hass, verify_ssl=entry.data[CONF_VERIFY_SSL], base_url=base_url
) )
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = OpenWebIfDevice(session) entry.runtime_data = OpenWebIfDevice(session)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry.""" """Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok

View File

@ -32,6 +32,7 @@ from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import Enigma2ConfigEntry
from .const import ( from .const import (
CONF_DEEP_STANDBY, CONF_DEEP_STANDBY,
CONF_MAC_ADDRESS, CONF_MAC_ADDRESS,
@ -102,12 +103,12 @@ async def async_setup_platform(
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, hass: HomeAssistant,
entry: ConfigEntry, entry: Enigma2ConfigEntry,
async_add_entities: AddEntitiesCallback, async_add_entities: AddEntitiesCallback,
) -> None: ) -> None:
"""Set up the Enigma2 media player platform.""" """Set up the Enigma2 media player platform."""
device: OpenWebIfDevice = hass.data[DOMAIN][entry.entry_id] device = entry.runtime_data
about = await device.get_about() about = await device.get_about()
device.mac_address = about["info"]["ifaces"][0]["mac"] device.mac_address = about["info"]["ifaces"][0]["mac"]
entity = Enigma2Device(entry, device, about) entity = Enigma2Device(entry, device, about)