diff --git a/homeassistant/components/dexcom/__init__.py b/homeassistant/components/dexcom/__init__.py index 54722c8dade..9902b9d5554 100644 --- a/homeassistant/components/dexcom/__init__.py +++ b/homeassistant/components/dexcom/__init__.py @@ -1,6 +1,7 @@ """The Dexcom integration.""" -from pydexcom import AccountError, Dexcom, SessionError +from pydexcom import Dexcom, Region +from pydexcom.errors import AccountError, SessionError from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant @@ -14,10 +15,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: DexcomConfigEntry) -> bo """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, + lambda: Dexcom( + username=entry.data[CONF_USERNAME], + password=entry.data[CONF_PASSWORD], + region=Region.OUS + if entry.data[CONF_SERVER] == SERVER_OUS + else Region.US, + ) ) except AccountError: return False diff --git a/homeassistant/components/dexcom/config_flow.py b/homeassistant/components/dexcom/config_flow.py index ed6dc94e764..cbe97952fef 100644 --- a/homeassistant/components/dexcom/config_flow.py +++ b/homeassistant/components/dexcom/config_flow.py @@ -5,7 +5,8 @@ from __future__ import annotations import logging from typing import Any -from pydexcom import AccountError, Dexcom, SessionError +from pydexcom import Dexcom, Region +from pydexcom.errors import AccountError, SessionError import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult @@ -37,10 +38,13 @@ class DexcomConfigFlow(ConfigFlow, domain=DOMAIN): if user_input is not None: try: await self.hass.async_add_executor_job( - Dexcom, - user_input[CONF_USERNAME], - user_input[CONF_PASSWORD], - user_input[CONF_SERVER] == SERVER_OUS, + lambda: Dexcom( + username=user_input[CONF_USERNAME], + password=user_input[CONF_PASSWORD], + region=Region.OUS + if user_input[CONF_SERVER] == SERVER_OUS + else Region.US, + ) ) except SessionError: errors["base"] = "cannot_connect" diff --git a/homeassistant/components/dexcom/coordinator.py b/homeassistant/components/dexcom/coordinator.py index a9e14def350..3f00767f3dd 100644 --- a/homeassistant/components/dexcom/coordinator.py +++ b/homeassistant/components/dexcom/coordinator.py @@ -18,7 +18,7 @@ _SCAN_INTERVAL = timedelta(seconds=180) type DexcomConfigEntry = ConfigEntry[DexcomCoordinator] -class DexcomCoordinator(DataUpdateCoordinator[GlucoseReading]): +class DexcomCoordinator(DataUpdateCoordinator[GlucoseReading | None]): """Dexcom Coordinator.""" def __init__( @@ -37,7 +37,7 @@ class DexcomCoordinator(DataUpdateCoordinator[GlucoseReading]): ) self.dexcom = dexcom - async def _async_update_data(self) -> GlucoseReading: + async def _async_update_data(self) -> GlucoseReading | None: """Fetch data from API endpoint.""" return await self.hass.async_add_executor_job( self.dexcom.get_current_glucose_reading diff --git a/homeassistant/components/dexcom/manifest.json b/homeassistant/components/dexcom/manifest.json index 0244fc71d65..e516445b07f 100644 --- a/homeassistant/components/dexcom/manifest.json +++ b/homeassistant/components/dexcom/manifest.json @@ -7,5 +7,5 @@ "integration_type": "service", "iot_class": "cloud_polling", "loggers": ["pydexcom"], - "requirements": ["pydexcom==0.2.3"] + "requirements": ["pydexcom==0.5.1"] } diff --git a/requirements_all.txt b/requirements_all.txt index d352fde190a..99cde55f49d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1989,7 +1989,7 @@ pydeconz==120 pydelijn==1.1.0 # homeassistant.components.dexcom -pydexcom==0.2.3 +pydexcom==0.5.1 # homeassistant.components.discovergy pydiscovergy==3.0.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 3df4999c684..6a677cb796a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1696,7 +1696,7 @@ pydeako==0.6.0 pydeconz==120 # homeassistant.components.dexcom -pydexcom==0.2.3 +pydexcom==0.5.1 # homeassistant.components.discovergy pydiscovergy==3.0.2 diff --git a/tests/components/dexcom/__init__.py b/tests/components/dexcom/__init__.py index 10a742070d6..9046c83fb87 100644 --- a/tests/components/dexcom/__init__.py +++ b/tests/components/dexcom/__init__.py @@ -19,6 +19,8 @@ CONFIG = { } GLUCOSE_READING = GlucoseReading(json.loads(load_fixture("data.json", "dexcom"))) +TEST_ACCOUNT_ID = "99999999-9999-9999-9999-999999999999" +TEST_SESSION_ID = "55555555-5555-5555-5555-555555555555" async def init_integration( @@ -38,8 +40,12 @@ async def init_integration( return_value=GLUCOSE_READING, ), patch( - "homeassistant.components.dexcom.Dexcom.create_session", - return_value="test_session_id", + "homeassistant.components.dexcom.Dexcom._get_account_id", + return_value=TEST_ACCOUNT_ID, + ), + patch( + "homeassistant.components.dexcom.Dexcom._get_session_id", + return_value=TEST_SESSION_ID, ), ): entry.add_to_hass(hass) diff --git a/tests/components/dexcom/fixtures/data.json b/tests/components/dexcom/fixtures/data.json index d1ae571f203..1bf930362bb 100644 --- a/tests/components/dexcom/fixtures/data.json +++ b/tests/components/dexcom/fixtures/data.json @@ -1,7 +1,7 @@ { - "DT": "/Date(1587165223000+0000)/", - "ST": "/Date(1587179623000)/", - "Trend": 4, - "Value": 110, - "WT": "/Date(1587179623000)/" + "WT": "Date(1745081913085)", + "ST": "Date(1745081913085)", + "DT": "Date(1745081913085-0400)", + "Value": 100, + "Trend": "Flat" } diff --git a/tests/components/dexcom/test_config_flow.py b/tests/components/dexcom/test_config_flow.py index 0a7338c13da..e696aa723f3 100644 --- a/tests/components/dexcom/test_config_flow.py +++ b/tests/components/dexcom/test_config_flow.py @@ -2,7 +2,7 @@ from unittest.mock import patch -from pydexcom import AccountError, SessionError +from pydexcom.errors import AccountError, SessionError from homeassistant import config_entries from homeassistant.components.dexcom.const import DOMAIN @@ -23,10 +23,7 @@ async def test_form(hass: HomeAssistant) -> None: assert result["errors"] == {} with ( - patch( - "homeassistant.components.dexcom.config_flow.Dexcom.create_session", - return_value="test_session_id", - ), + patch("homeassistant.components.dexcom.config_flow.Dexcom"), patch( "homeassistant.components.dexcom.async_setup_entry", return_value=True, diff --git a/tests/components/dexcom/test_init.py b/tests/components/dexcom/test_init.py index f43d39626b0..59580f68672 100644 --- a/tests/components/dexcom/test_init.py +++ b/tests/components/dexcom/test_init.py @@ -2,7 +2,7 @@ from unittest.mock import patch -from pydexcom import AccountError, SessionError +from pydexcom.errors import AccountError, SessionError from homeassistant.components.dexcom.const import DOMAIN from homeassistant.config_entries import ConfigEntryState diff --git a/tests/components/dexcom/test_sensor.py b/tests/components/dexcom/test_sensor.py index 5c0a5280ad6..6fef662b745 100644 --- a/tests/components/dexcom/test_sensor.py +++ b/tests/components/dexcom/test_sensor.py @@ -2,7 +2,7 @@ from unittest.mock import patch -from pydexcom import SessionError +from pydexcom.errors import SessionError from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN from homeassistant.core import HomeAssistant