mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 02:24:51 -05:00
Use runtime_data in launch_library integration (#167887)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
epenet
parent
7cf422361b
commit
ce9875806d
@@ -2,31 +2,31 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import LaunchLibraryCoordinator
|
||||
from .coordinator import LaunchLibraryConfigEntry, LaunchLibraryCoordinator
|
||||
|
||||
PLATFORMS = [Platform.SENSOR]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: LaunchLibraryConfigEntry
|
||||
) -> bool:
|
||||
"""Set up this integration using UI."""
|
||||
|
||||
coordinator = LaunchLibraryCoordinator(hass, entry)
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
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: LaunchLibraryConfigEntry
|
||||
) -> bool:
|
||||
"""Handle removal of an entry."""
|
||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||
del hass.data[DOMAIN]
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
@@ -16,6 +16,9 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
type LaunchLibraryConfigEntry = ConfigEntry[LaunchLibraryCoordinator]
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -29,12 +32,12 @@ class LaunchLibraryData(TypedDict):
|
||||
class LaunchLibraryCoordinator(DataUpdateCoordinator[LaunchLibraryData]):
|
||||
"""Class to manage fetching Launch Library data."""
|
||||
|
||||
config_entry: ConfigEntry
|
||||
config_entry: LaunchLibraryConfigEntry
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: LaunchLibraryConfigEntry,
|
||||
) -> None:
|
||||
"""Initialize the coordinator."""
|
||||
super().__init__(
|
||||
|
||||
@@ -6,20 +6,18 @@ from typing import Any
|
||||
|
||||
from pylaunches.types import Event, Launch
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import LaunchLibraryCoordinator
|
||||
from .coordinator import LaunchLibraryConfigEntry
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: LaunchLibraryConfigEntry,
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
|
||||
coordinator: LaunchLibraryCoordinator = hass.data[DOMAIN]
|
||||
coordinator = entry.runtime_data
|
||||
if coordinator.data is None:
|
||||
return {}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ from homeassistant.components.sensor import (
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME, PERCENTAGE
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
@@ -23,7 +22,7 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util.dt import parse_datetime
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import LaunchLibraryCoordinator
|
||||
from .coordinator import LaunchLibraryConfigEntry, LaunchLibraryCoordinator
|
||||
|
||||
DEFAULT_NEXT_LAUNCH_NAME = "Next launch"
|
||||
|
||||
@@ -118,12 +117,12 @@ SENSOR_DESCRIPTIONS: tuple[LaunchLibrarySensorEntityDescription, ...] = (
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: LaunchLibraryConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the sensor platform."""
|
||||
name = entry.data.get(CONF_NAME, DEFAULT_NEXT_LAUNCH_NAME)
|
||||
coordinator: LaunchLibraryCoordinator = hass.data[DOMAIN]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
LaunchLibrarySensor(
|
||||
|
||||
Reference in New Issue
Block a user