* Initial commit for Dexcom integration * Dexcom config flow testing * Clarify errors during setup * Resolve minor test issues * Update sensor availability, resolve linting issues * Add sensor tests * Remove title due to 0.109, add abort * >94.97% codecov/patch * Move .translations/ to translations/ * Add constants for servers and unit of measurements * Bump pydexcom version * Updated domain schema, Dexcom creation * Support for different units of measurement * Update tests * Remove empty items from manifest Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Raise UpdateFailed if fetching new session fails * Switch everything over to required * Simplify state information * Simplify async_on_remove * Pydexcom package now handles fetching new session * Only allow config flow * Remove ternary operator * Bump version, pydexcom handling session refresh * Using common strings * Import from test.async_mock * Shorten variable names * Resolve tests after removing yaml support * Return false if credentials are invalid * Available seems to handle if data is empty * Now using option flow, remove handling import * Add fixture for JSON returned from API * Overhaul testing * Revise update options * Bump pydexcom version * Combat listener repetition * Undo update listener using callback * Change sensor availability to use last_update_success * Update sensor availability and tests * Rename test Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
"""Tests for the Dexcom integration."""
|
|
|
|
import json
|
|
|
|
from pydexcom import GlucoseReading
|
|
|
|
from homeassistant.components.dexcom.const import CONF_SERVER, DOMAIN, SERVER_US
|
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
|
|
|
from tests.async_mock import patch
|
|
from tests.common import MockConfigEntry, load_fixture
|
|
|
|
CONFIG = {
|
|
CONF_USERNAME: "test_username",
|
|
CONF_PASSWORD: "test_password",
|
|
CONF_SERVER: SERVER_US,
|
|
}
|
|
|
|
GLUCOSE_READING = GlucoseReading(json.loads(load_fixture("dexcom_data.json")))
|
|
|
|
|
|
async def init_integration(hass) -> MockConfigEntry:
|
|
"""Set up the Dexcom integration in Home Assistant."""
|
|
entry = MockConfigEntry(
|
|
domain=DOMAIN,
|
|
title="test_username",
|
|
unique_id="test_username",
|
|
data=CONFIG,
|
|
options=None,
|
|
)
|
|
with patch(
|
|
"homeassistant.components.dexcom.Dexcom.get_current_glucose_reading",
|
|
return_value=GLUCOSE_READING,
|
|
), patch(
|
|
"homeassistant.components.dexcom.Dexcom.create_session",
|
|
return_value="test_session_id",
|
|
):
|
|
entry.add_to_hass(hass)
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
return entry
|