2020-07-02 00:14:54 +00:00
|
|
|
"""The Dexcom integration."""
|
2024-03-08 13:15:26 +00:00
|
|
|
|
2025-01-24 13:20:23 +00:00
|
|
|
from pydexcom import AccountError, Dexcom, SessionError
|
2020-07-02 00:14:54 +00:00
|
|
|
|
2024-11-15 11:13:21 +00:00
|
|
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
2020-07-02 00:14:54 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.exceptions import ConfigEntryNotReady
|
|
|
|
|
2025-01-24 14:14:05 +00:00
|
|
|
from .const import CONF_SERVER, PLATFORMS, SERVER_OUS
|
|
|
|
from .coordinator import DexcomConfigEntry, DexcomCoordinator
|
2020-07-02 00:14:54 +00:00
|
|
|
|
|
|
|
|
2025-01-24 14:14:05 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: DexcomConfigEntry) -> bool:
|
2020-07-02 00:14:54 +00:00
|
|
|
"""Set up Dexcom from a config entry."""
|
|
|
|
try:
|
|
|
|
dexcom = await hass.async_add_executor_job(
|
|
|
|
Dexcom,
|
|
|
|
entry.data[CONF_USERNAME],
|
|
|
|
entry.data[CONF_PASSWORD],
|
|
|
|
entry.data[CONF_SERVER] == SERVER_OUS,
|
|
|
|
)
|
|
|
|
except AccountError:
|
|
|
|
return False
|
2020-08-28 11:50:32 +00:00
|
|
|
except SessionError as error:
|
|
|
|
raise ConfigEntryNotReady from error
|
2020-07-02 00:14:54 +00:00
|
|
|
|
2025-01-24 13:20:23 +00:00
|
|
|
coordinator = DexcomCoordinator(hass, entry=entry, dexcom=dexcom)
|
2023-08-02 06:29:00 +00:00
|
|
|
await coordinator.async_config_entry_first_refresh()
|
|
|
|
|
2025-01-24 14:14:05 +00:00
|
|
|
entry.runtime_data = coordinator
|
2024-03-05 20:36:11 +00:00
|
|
|
|
2022-07-09 15:27:42 +00:00
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
2020-07-02 00:14:54 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2025-01-24 14:14:05 +00:00
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: DexcomConfigEntry) -> bool:
|
2020-07-02 00:14:54 +00:00
|
|
|
"""Unload a config entry."""
|
2025-01-24 14:14:05 +00:00
|
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|