core/tests/components/nightscout/test_sensor.py

59 lines
1.9 KiB
Python

"""The sensor tests for the Nightscout platform."""
from homeassistant.components.nightscout.const import (
ATTR_DELTA,
ATTR_DEVICE,
ATTR_DIRECTION,
)
from homeassistant.const import ATTR_DATE, ATTR_ICON, STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
from . import (
GLUCOSE_READINGS,
init_integration,
init_integration_empty_response,
init_integration_unavailable,
)
async def test_sensor_state(hass: HomeAssistant) -> None:
"""Test sensor state data."""
await init_integration(hass)
test_glucose_sensor = hass.states.get("sensor.blood_sugar")
assert test_glucose_sensor.state == str(
GLUCOSE_READINGS[0].sgv # pylint: disable=maybe-no-member
)
async def test_sensor_error(hass: HomeAssistant) -> None:
"""Test sensor state data."""
await init_integration_unavailable(hass)
test_glucose_sensor = hass.states.get("sensor.blood_sugar")
assert test_glucose_sensor.state == STATE_UNAVAILABLE
async def test_sensor_empty_response(hass: HomeAssistant) -> None:
"""Test sensor state data."""
await init_integration_empty_response(hass)
test_glucose_sensor = hass.states.get("sensor.blood_sugar")
assert test_glucose_sensor.state == STATE_UNAVAILABLE
async def test_sensor_attributes(hass: HomeAssistant) -> None:
"""Test sensor attributes."""
await init_integration(hass)
test_glucose_sensor = hass.states.get("sensor.blood_sugar")
reading = GLUCOSE_READINGS[0]
assert reading is not None
attr = test_glucose_sensor.attributes
assert attr[ATTR_DATE] == reading.date # pylint: disable=maybe-no-member
assert attr[ATTR_DELTA] == reading.delta # pylint: disable=maybe-no-member
assert attr[ATTR_DEVICE] == reading.device # pylint: disable=maybe-no-member
assert attr[ATTR_DIRECTION] == reading.direction # pylint: disable=maybe-no-member
assert attr[ATTR_ICON] == "mdi:arrow-bottom-right"