Small cleanup in Dexcom (#112425)

This commit is contained in:
Joost Lekkerkerker 2024-03-05 21:36:11 +01:00 committed by GitHub
parent 5dea902a9c
commit ed23bb7c04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 24 deletions

View File

@ -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

View File

@ -24,6 +24,3 @@ CONF_SERVER = "server"
SERVER_OUS = "EU"
SERVER_US = "US"
COORDINATOR = "coordinator"
UNDO_UPDATE_LISTENER = "undo_update_listener"

View File

@ -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,
)