Migrate mullvad to use entry.runtime_data (#170583)

This commit is contained in:
Michael
2026-05-14 16:18:23 +02:00
committed by GitHub
parent eb45c35952
commit 0cca80e57d
3 changed files with 13 additions and 22 deletions
+5 -13
View File
@@ -1,33 +1,25 @@
"""The Mullvad VPN integration."""
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from .const import DOMAIN
from .coordinator import MullvadCoordinator
from .coordinator import MullvadConfigEntry, MullvadCoordinator
PLATFORMS = [Platform.BINARY_SENSOR]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: MullvadConfigEntry) -> bool:
"""Set up Mullvad VPN integration."""
coordinator = MullvadCoordinator(hass, entry)
await coordinator.async_config_entry_first_refresh()
# Uses legacy hass.data[DOMAIN] pattern
# pylint: disable-next=home-assistant-use-runtime-data
hass.data[DOMAIN] = coordinator
entry.runtime_data = coordinator
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: MullvadConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
del hass.data[DOMAIN]
return unload_ok
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
@@ -5,14 +5,13 @@ from homeassistant.components.binary_sensor import (
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN
from .coordinator import MullvadCoordinator
from .coordinator import MullvadConfigEntry, MullvadCoordinator
BINARY_SENSORS = (
BinarySensorEntityDescription(
@@ -25,13 +24,11 @@ BINARY_SENSORS = (
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: MullvadConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Defer sensor setup to the shared sensor module."""
# Uses legacy hass.data[DOMAIN] pattern
# pylint: disable-next=home-assistant-use-runtime-data
coordinator = hass.data[DOMAIN]
coordinator = config_entry.runtime_data
async_add_entities(
MullvadBinarySensor(coordinator, entity_description, config_entry)
@@ -48,7 +45,7 @@ class MullvadBinarySensor(CoordinatorEntity[MullvadCoordinator], BinarySensorEnt
self,
coordinator: MullvadCoordinator,
entity_description: BinarySensorEntityDescription,
config_entry: ConfigEntry,
config_entry: MullvadConfigEntry,
) -> None:
"""Initialize the Mullvad binary sensor."""
super().__init__(coordinator)
@@ -15,13 +15,15 @@ from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
type MullvadConfigEntry = ConfigEntry[MullvadCoordinator]
class MullvadCoordinator(DataUpdateCoordinator[dict[str, Any]]):
"""Mullvad VPN data update coordinator."""
config_entry: ConfigEntry
config_entry: MullvadConfigEntry
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
def __init__(self, hass: HomeAssistant, entry: MullvadConfigEntry) -> None:
"""Initialize the Mullvad coordinator."""
super().__init__(
hass,