mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Move coordinator store to entry runtime data for Azure DevOps (#119408)
Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>
This commit is contained in:
parent
7bfa1e4729
commit
01d4629a2b
@ -8,15 +8,17 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import CONF_PAT, CONF_PROJECT, DOMAIN
|
||||
from .const import CONF_PAT, CONF_PROJECT
|
||||
from .coordinator import AzureDevOpsDataUpdateCoordinator
|
||||
|
||||
type AzureDevOpsConfigEntry = ConfigEntry[AzureDevOpsDataUpdateCoordinator]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORMS = [Platform.SENSOR]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: AzureDevOpsConfigEntry) -> bool:
|
||||
"""Set up Azure DevOps from a config entry."""
|
||||
|
||||
# Create the data update coordinator
|
||||
@ -26,9 +28,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
entry=entry,
|
||||
)
|
||||
|
||||
# Store the coordinator in hass data
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.entry_id] = coordinator
|
||||
# Store the coordinator in runtime data
|
||||
entry.runtime_data = coordinator
|
||||
|
||||
# If a personal access token is set, authorize the client
|
||||
if entry.data.get(CONF_PAT) is not None:
|
||||
@ -48,8 +49,4 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload Azure DevOps config entry."""
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
del hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
@ -15,13 +15,12 @@ from homeassistant.components.sensor import (
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import DOMAIN
|
||||
from . import AzureDevOpsConfigEntry
|
||||
from .coordinator import AzureDevOpsDataUpdateCoordinator
|
||||
from .entity import AzureDevOpsEntity
|
||||
|
||||
@ -128,11 +127,11 @@ def parse_datetime(value: str | None) -> datetime | None:
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: AzureDevOpsConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Azure DevOps sensor based on a config entry."""
|
||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
initial_builds: list[Build] = coordinator.data.builds
|
||||
|
||||
async_add_entities(
|
||||
|
Loading…
x
Reference in New Issue
Block a user