forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move dexcom coordinator to separate module (home-assistant#136433)
- Loading branch information
Showing
3 changed files
with
51 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Coordinator for the Dexcom integration.""" | ||
|
||
from datetime import timedelta | ||
import logging | ||
|
||
from pydexcom import Dexcom, GlucoseReading | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator | ||
|
||
from .const import DOMAIN | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
_SCAN_INTERVAL = timedelta(seconds=180) | ||
|
||
|
||
class DexcomCoordinator(DataUpdateCoordinator[GlucoseReading]): | ||
"""Dexcom Coordinator.""" | ||
|
||
def __init__( | ||
self, | ||
hass: HomeAssistant, | ||
entry: ConfigEntry, | ||
dexcom: Dexcom, | ||
) -> None: | ||
"""Initialize the coordinator.""" | ||
super().__init__( | ||
hass, | ||
_LOGGER, | ||
config_entry=entry, | ||
name=DOMAIN, | ||
update_interval=_SCAN_INTERVAL, | ||
) | ||
self.dexcom = dexcom | ||
|
||
async def _async_update_data(self) -> GlucoseReading: | ||
"""Fetch data from API endpoint.""" | ||
return await self.hass.async_add_executor_job( | ||
self.dexcom.get_current_glucose_reading | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters