2020-07-01 20:14:54 -04:00
|
|
|
"""The sensor tests for the griddy platform."""
|
2024-03-08 14:50:25 +01:00
|
|
|
|
2021-01-01 22:31:56 +01:00
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
2020-07-01 20:14:54 -04:00
|
|
|
from pydexcom import SessionError
|
|
|
|
|
|
2024-11-15 12:13:21 +01:00
|
|
|
from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN
|
2023-02-08 13:01:44 +01:00
|
|
|
from homeassistant.core import HomeAssistant
|
2022-03-25 23:22:58 +01:00
|
|
|
from homeassistant.helpers.entity_component import async_update_entity
|
2020-07-01 20:14:54 -04:00
|
|
|
|
2022-09-19 09:31:57 +02:00
|
|
|
from . import GLUCOSE_READING, init_integration
|
2020-07-01 20:14:54 -04:00
|
|
|
|
|
|
|
|
|
2023-02-08 13:01:44 +01:00
|
|
|
async def test_sensors(hass: HomeAssistant) -> None:
|
2020-07-01 20:14:54 -04:00
|
|
|
"""Test we get sensor data."""
|
|
|
|
|
await init_integration(hass)
|
|
|
|
|
|
2023-08-22 22:09:18 +02:00
|
|
|
test_username_glucose_value = hass.states.get("sensor.test_username_glucose_value")
|
2020-07-01 20:14:54 -04:00
|
|
|
assert test_username_glucose_value.state == str(GLUCOSE_READING.value)
|
2023-08-22 22:09:18 +02:00
|
|
|
test_username_glucose_trend = hass.states.get("sensor.test_username_glucose_trend")
|
2020-07-01 20:14:54 -04:00
|
|
|
assert test_username_glucose_trend.state == GLUCOSE_READING.trend_description
|
|
|
|
|
|
|
|
|
|
|
2023-02-08 13:01:44 +01:00
|
|
|
async def test_sensors_unknown(hass: HomeAssistant) -> None:
|
2020-07-01 20:14:54 -04:00
|
|
|
"""Test we handle sensor state unknown."""
|
|
|
|
|
await init_integration(hass)
|
|
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.dexcom.Dexcom.get_current_glucose_reading",
|
|
|
|
|
return_value=None,
|
|
|
|
|
):
|
2023-08-22 22:09:18 +02:00
|
|
|
await async_update_entity(hass, "sensor.test_username_glucose_value")
|
|
|
|
|
await async_update_entity(hass, "sensor.test_username_glucose_trend")
|
2020-07-01 20:14:54 -04:00
|
|
|
|
2023-08-22 22:09:18 +02:00
|
|
|
test_username_glucose_value = hass.states.get("sensor.test_username_glucose_value")
|
2020-07-01 20:14:54 -04:00
|
|
|
assert test_username_glucose_value.state == STATE_UNKNOWN
|
2023-08-22 22:09:18 +02:00
|
|
|
test_username_glucose_trend = hass.states.get("sensor.test_username_glucose_trend")
|
2020-07-01 20:14:54 -04:00
|
|
|
assert test_username_glucose_trend.state == STATE_UNKNOWN
|
|
|
|
|
|
|
|
|
|
|
2023-02-08 13:01:44 +01:00
|
|
|
async def test_sensors_update_failed(hass: HomeAssistant) -> None:
|
2020-07-01 20:14:54 -04:00
|
|
|
"""Test we handle sensor update failed."""
|
|
|
|
|
await init_integration(hass)
|
|
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.dexcom.Dexcom.get_current_glucose_reading",
|
|
|
|
|
side_effect=SessionError,
|
|
|
|
|
):
|
2023-08-22 22:09:18 +02:00
|
|
|
await async_update_entity(hass, "sensor.test_username_glucose_value")
|
|
|
|
|
await async_update_entity(hass, "sensor.test_username_glucose_trend")
|
2020-07-01 20:14:54 -04:00
|
|
|
|
2023-08-22 22:09:18 +02:00
|
|
|
test_username_glucose_value = hass.states.get("sensor.test_username_glucose_value")
|
2020-07-01 20:14:54 -04:00
|
|
|
assert test_username_glucose_value.state == STATE_UNAVAILABLE
|
2023-08-22 22:09:18 +02:00
|
|
|
test_username_glucose_trend = hass.states.get("sensor.test_username_glucose_trend")
|
2020-07-01 20:14:54 -04:00
|
|
|
assert test_username_glucose_trend.state == STATE_UNAVAILABLE
|