mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Store runtime data inside the config entry in Bring (#116820)
This commit is contained in:
parent
e66581e3a2
commit
95ddb734ed
@ -24,8 +24,10 @@ PLATFORMS: list[Platform] = [Platform.TODO]
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
BringConfigEntry = ConfigEntry[BringDataUpdateCoordinator]
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
||||||
|
async def async_setup_entry(hass: HomeAssistant, entry: BringConfigEntry) -> bool:
|
||||||
"""Set up Bring! from a config entry."""
|
"""Set up Bring! from a config entry."""
|
||||||
|
|
||||||
email = entry.data[CONF_EMAIL]
|
email = entry.data[CONF_EMAIL]
|
||||||
@ -57,7 +59,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
coordinator = BringDataUpdateCoordinator(hass, bring)
|
coordinator = BringDataUpdateCoordinator(hass, bring)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
entry.runtime_data = coordinator
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
@ -66,7 +68,4 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
@ -15,7 +15,6 @@ from homeassistant.components.todo import (
|
|||||||
TodoListEntity,
|
TodoListEntity,
|
||||||
TodoListEntityFeature,
|
TodoListEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||||
@ -23,6 +22,7 @@ from homeassistant.helpers.config_validation import make_entity_service_schema
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from . import BringConfigEntry
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_ITEM_NAME,
|
ATTR_ITEM_NAME,
|
||||||
ATTR_NOTIFICATION_TYPE,
|
ATTR_NOTIFICATION_TYPE,
|
||||||
@ -34,11 +34,11 @@ from .coordinator import BringData, BringDataUpdateCoordinator
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: BringConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the sensor from a config entry created in the integrations UI."""
|
"""Set up the sensor from a config entry created in the integrations UI."""
|
||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = config_entry.runtime_data
|
||||||
|
|
||||||
unique_id = config_entry.unique_id
|
unique_id = config_entry.unique_id
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user