mirror of
https://github.com/home-assistant/core.git
synced 2026-08-03 20:24:55 +02:00
Migrate mullvad to use entry.runtime_data (#170583)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user