mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Small cleanup in Dexcom (#112425)
This commit is contained in:
parent
5dea902a9c
commit
ed23bb7c04
@ -10,15 +10,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .const import (
|
||||
CONF_SERVER,
|
||||
COORDINATOR,
|
||||
DOMAIN,
|
||||
MG_DL,
|
||||
PLATFORMS,
|
||||
SERVER_OUS,
|
||||
UNDO_UPDATE_LISTENER,
|
||||
)
|
||||
from .const import CONF_SERVER, DOMAIN, MG_DL, PLATFORMS, SERVER_OUS
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -59,11 +51,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
)
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.entry_id] = {
|
||||
COORDINATOR: coordinator,
|
||||
UNDO_UPDATE_LISTENER: entry.add_update_listener(update_listener),
|
||||
}
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
||||
|
||||
entry.async_on_unload(entry.add_update_listener(update_listener))
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
@ -72,10 +62,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]()
|
||||
|
||||
if unload_ok:
|
||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
return unload_ok
|
||||
|
||||
|
@ -24,6 +24,3 @@ CONF_SERVER = "server"
|
||||
|
||||
SERVER_OUS = "EU"
|
||||
SERVER_US = "US"
|
||||
|
||||
COORDINATOR = "coordinator"
|
||||
UNDO_UPDATE_LISTENER = "undo_update_listener"
|
||||
|
@ -12,7 +12,7 @@ from homeassistant.helpers.update_coordinator import (
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
|
||||
from .const import COORDINATOR, DOMAIN, GLUCOSE_TREND_ICON, MG_DL
|
||||
from .const import DOMAIN, GLUCOSE_TREND_ICON, MG_DL
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
@ -21,7 +21,7 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Dexcom sensors."""
|
||||
coordinator = hass.data[DOMAIN][config_entry.entry_id][COORDINATOR]
|
||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
username = config_entry.data[CONF_USERNAME]
|
||||
unit_of_measurement = config_entry.options[CONF_UNIT_OF_MEASUREMENT]
|
||||
async_add_entities(
|
||||
@ -31,7 +31,6 @@ async def async_setup_entry(
|
||||
coordinator, username, config_entry.entry_id, unit_of_measurement
|
||||
),
|
||||
],
|
||||
False,
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user