mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Use runtime_data in dexcom (#136441)
This commit is contained in:
parent
f3e13f4662
commit
4dc873416f
@ -2,16 +2,15 @@
|
|||||||
|
|
||||||
from pydexcom import AccountError, Dexcom, SessionError
|
from pydexcom import AccountError, Dexcom, SessionError
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
|
|
||||||
from .const import CONF_SERVER, DOMAIN, PLATFORMS, SERVER_OUS
|
from .const import CONF_SERVER, PLATFORMS, SERVER_OUS
|
||||||
from .coordinator import DexcomCoordinator
|
from .coordinator import DexcomConfigEntry, DexcomCoordinator
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: DexcomConfigEntry) -> bool:
|
||||||
"""Set up Dexcom from a config entry."""
|
"""Set up Dexcom from a config entry."""
|
||||||
try:
|
try:
|
||||||
dexcom = await hass.async_add_executor_job(
|
dexcom = await hass.async_add_executor_job(
|
||||||
@ -28,15 +27,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
coordinator = DexcomCoordinator(hass, entry=entry, dexcom=dexcom)
|
coordinator = DexcomCoordinator(hass, entry=entry, dexcom=dexcom)
|
||||||
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)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: DexcomConfigEntry) -> 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,6 +15,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
_SCAN_INTERVAL = timedelta(seconds=180)
|
_SCAN_INTERVAL = timedelta(seconds=180)
|
||||||
|
|
||||||
|
type DexcomConfigEntry = ConfigEntry[DexcomCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class DexcomCoordinator(DataUpdateCoordinator[GlucoseReading]):
|
class DexcomCoordinator(DataUpdateCoordinator[GlucoseReading]):
|
||||||
"""Dexcom Coordinator."""
|
"""Dexcom Coordinator."""
|
||||||
@ -22,7 +24,7 @@ class DexcomCoordinator(DataUpdateCoordinator[GlucoseReading]):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: DexcomConfigEntry,
|
||||||
dexcom: Dexcom,
|
dexcom: Dexcom,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the coordinator."""
|
"""Initialize the coordinator."""
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_USERNAME, UnitOfBloodGlucoseConcentration
|
from homeassistant.const import CONF_USERNAME, UnitOfBloodGlucoseConcentration
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
@ -11,7 +10,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import DexcomCoordinator
|
from .coordinator import DexcomConfigEntry, DexcomCoordinator
|
||||||
|
|
||||||
TRENDS = {
|
TRENDS = {
|
||||||
1: "rising_quickly",
|
1: "rising_quickly",
|
||||||
@ -26,11 +25,11 @@ TRENDS = {
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: DexcomConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Dexcom sensors."""
|
"""Set up the Dexcom sensors."""
|
||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = config_entry.runtime_data
|
||||||
username = config_entry.data[CONF_USERNAME]
|
username = config_entry.data[CONF_USERNAME]
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user