Skip to content

Commit

Permalink
Use runtime_data for enigma2 (#119154)
Browse files Browse the repository at this point in the history
* Use runtime_data for enigma2

* Update __init__.py
  • Loading branch information
autinerd authored Jun 8, 2024
1 parent ae0e751 commit a662ee7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
11 changes: 4 additions & 7 deletions homeassistant/components/enigma2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_create_clientsession

from .const import DOMAIN
type Enigma2ConfigEntry = ConfigEntry[OpenWebIfDevice]

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."""
base_url = URL.build(
scheme="http" if not entry.data[CONF_SSL] else "https",
Expand All @@ -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.data.setdefault(DOMAIN, {})[entry.entry_id] = OpenWebIfDevice(session)
entry.runtime_data = 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
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
5 changes: 3 additions & 2 deletions homeassistant/components/enigma2/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

from . import Enigma2ConfigEntry
from .const import (
CONF_DEEP_STANDBY,
CONF_MAC_ADDRESS,
Expand Down Expand Up @@ -102,12 +103,12 @@ async def async_setup_platform(

async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
entry: Enigma2ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Enigma2 media player platform."""

device: OpenWebIfDevice = hass.data[DOMAIN][entry.entry_id]
device = entry.runtime_data
about = await device.get_about()
device.mac_address = about["info"]["ifaces"][0]["mac"]
entity = Enigma2Device(entry, device, about)
Expand Down

0 comments on commit a662ee7

Please sign in to comment.