hass-core/tests/components/nightscout/test_sensor.py
Marcio Granzotto Rodrigues 52a9921ed3
Nightscout PR fixes (#38737)
* Don't allow duplicate nightscout configs

* Fix nightscout translations

* Remove unnecessary should_poll method

* Remove SVG attribute, as it was duplicating the state

* Use aiohttp client session from HA

* Move validate_input outside the config class

* Use the entry unique_id on the sensor

* Move create entity logic

* Handle unexpected exception on Nightscout config
2020-08-13 07:46:07 -04:00

58 lines
1.8 KiB
Python

"""The sensor tests for the Nightscout platform."""
from homeassistant.components.nightscout.const import (
ATTR_DATE,
ATTR_DELTA,
ATTR_DEVICE,
ATTR_DIRECTION,
)
from homeassistant.const import ATTR_ICON, STATE_UNAVAILABLE
from tests.components.nightscout import (
GLUCOSE_READINGS,
init_integration,
init_integration_empty_response,
init_integration_unavailable,
)
async def test_sensor_state(hass):
"""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):
"""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):
"""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):
"""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"