Add detailed status for UptimeRobot (#64879)
Co-authored-by: Joakim Sørensen <hi@ludeeus.dev>
This commit is contained in:
parent
eb5c6076af
commit
3f12ce06af
10 changed files with 178 additions and 23 deletions
50
tests/components/uptimerobot/test_sensor.py
Normal file
50
tests/components/uptimerobot/test_sensor.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
"""Test UptimeRobot sensor."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from pyuptimerobot import UptimeRobotAuthenticationException
|
||||
|
||||
from homeassistant.components.uptimerobot.const import COORDINATOR_UPDATE_INTERVAL
|
||||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util import dt
|
||||
|
||||
from .common import (
|
||||
MOCK_UPTIMEROBOT_MONITOR,
|
||||
STATE_UP,
|
||||
UPTIMEROBOT_SENSOR_TEST_ENTITY,
|
||||
setup_uptimerobot_integration,
|
||||
)
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
SENSOR_ICON = "mdi:television-shimmer"
|
||||
|
||||
|
||||
async def test_presentation(hass: HomeAssistant) -> None:
|
||||
"""Test the presenstation of UptimeRobot sensors."""
|
||||
await setup_uptimerobot_integration(hass)
|
||||
|
||||
entity = hass.states.get(UPTIMEROBOT_SENSOR_TEST_ENTITY)
|
||||
|
||||
assert entity.state == STATE_UP
|
||||
assert entity.attributes["icon"] == SENSOR_ICON
|
||||
assert entity.attributes["target"] == MOCK_UPTIMEROBOT_MONITOR["url"]
|
||||
|
||||
|
||||
async def test_unaviable_on_update_failure(hass: HomeAssistant) -> None:
|
||||
"""Test entity unaviable on update failure."""
|
||||
await setup_uptimerobot_integration(hass)
|
||||
|
||||
entity = hass.states.get(UPTIMEROBOT_SENSOR_TEST_ENTITY)
|
||||
assert entity.state == STATE_UP
|
||||
|
||||
with patch(
|
||||
"pyuptimerobot.UptimeRobot.async_get_monitors",
|
||||
side_effect=UptimeRobotAuthenticationException,
|
||||
):
|
||||
async_fire_time_changed(hass, dt.utcnow() + COORDINATOR_UPDATE_INTERVAL)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity = hass.states.get(UPTIMEROBOT_SENSOR_TEST_ENTITY)
|
||||
assert entity.state == STATE_UNAVAILABLE
|
Loading…
Add table
Add a link
Reference in a new issue