mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Store Glances coordinator in runtime_data (#119607)
This commit is contained in:
parent
1d62056d9b
commit
f3ce562847
@ -40,8 +40,12 @@ CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type GlancesConfigEntry = ConfigEntry[GlancesDataUpdateCoordinator]
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant, config_entry: GlancesConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Set up Glances from config entry."""
|
"""Set up Glances from config entry."""
|
||||||
try:
|
try:
|
||||||
api = await get_api(hass, dict(config_entry.data))
|
api = await get_api(hass, dict(config_entry.data))
|
||||||
@ -54,20 +58,16 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
coordinator = GlancesDataUpdateCoordinator(hass, config_entry, api)
|
coordinator = GlancesDataUpdateCoordinator(hass, config_entry, api)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = coordinator
|
config_entry.runtime_data = coordinator
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: GlancesConfigEntry) -> 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)
|
|
||||||
if not hass.data[DOMAIN]:
|
|
||||||
del hass.data[DOMAIN]
|
|
||||||
return unload_ok
|
|
||||||
|
|
||||||
|
|
||||||
async def get_api(hass: HomeAssistant, entry_data: dict[str, Any]) -> Glances:
|
async def get_api(hass: HomeAssistant, entry_data: dict[str, Any]) -> Glances:
|
||||||
|
@ -10,7 +10,6 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
REVOLUTIONS_PER_MINUTE,
|
REVOLUTIONS_PER_MINUTE,
|
||||||
@ -23,7 +22,7 @@ from homeassistant.helpers.device_registry import DeviceInfo
|
|||||||
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 GlancesDataUpdateCoordinator
|
from . import GlancesConfigEntry, GlancesDataUpdateCoordinator
|
||||||
from .const import CPU_ICON, DOMAIN
|
from .const import CPU_ICON, DOMAIN
|
||||||
|
|
||||||
|
|
||||||
@ -288,12 +287,12 @@ SENSOR_TYPES = {
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: GlancesConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Glances sensors."""
|
"""Set up the Glances sensors."""
|
||||||
|
|
||||||
coordinator: GlancesDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = config_entry.runtime_data
|
||||||
entities: list[GlancesSensor] = []
|
entities: list[GlancesSensor] = []
|
||||||
|
|
||||||
for sensor_type, sensors in coordinator.data.items():
|
for sensor_type, sensors in coordinator.data.items():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user