Add coordinator to ring integration (#107088)

This commit is contained in:
Steven B
2024-01-31 10:37:55 +01:00
committed by GitHub
parent 7fe4a343f9
commit f725258ea9
12 changed files with 343 additions and 388 deletions
+60 -11
View File
@@ -60,6 +60,49 @@ async def test_auth_failed_on_setup(
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
@pytest.mark.parametrize(
("error_type", "log_msg"),
[
(
RingTimeout,
"Timeout communicating with API: ",
),
(
RingError,
"Error communicating with API: ",
),
],
ids=["timeout-error", "other-error"],
)
async def test_error_on_setup(
hass: HomeAssistant,
requests_mock: requests_mock.Mocker,
mock_config_entry: MockConfigEntry,
caplog,
error_type,
log_msg,
) -> None:
"""Test auth failure on setup entry."""
mock_config_entry.add_to_hass(hass)
with patch(
"ring_doorbell.Ring.update_data",
side_effect=error_type,
):
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
assert [
record.message
for record in caplog.records
if record.levelname == "DEBUG"
and record.name == "homeassistant.config_entries"
and log_msg in record.message
and DOMAIN in record.message
]
async def test_auth_failure_on_global_update(
hass: HomeAssistant,
requests_mock: requests_mock.Mocker,
@@ -78,8 +121,11 @@ async def test_auth_failure_on_global_update(
async_fire_time_changed(hass, dt_util.now() + timedelta(minutes=20))
await hass.async_block_till_done()
assert "Ring access token is no longer valid, need to re-authenticate" in [
record.message for record in caplog.records if record.levelname == "WARNING"
assert "Authentication failed while fetching devices data: " in [
record.message
for record in caplog.records
if record.levelname == "ERROR"
and record.name == "homeassistant.components.ring.coordinator"
]
assert any(mock_config_entry.async_get_active_flows(hass, {SOURCE_REAUTH}))
@@ -91,7 +137,7 @@ async def test_auth_failure_on_device_update(
mock_config_entry: MockConfigEntry,
caplog,
) -> None:
"""Test authentication failure on global data update."""
"""Test authentication failure on device data update."""
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
@@ -103,8 +149,11 @@ async def test_auth_failure_on_device_update(
async_fire_time_changed(hass, dt_util.now() + timedelta(minutes=20))
await hass.async_block_till_done()
assert "Ring access token is no longer valid, need to re-authenticate" in [
record.message for record in caplog.records if record.levelname == "WARNING"
assert "Authentication failed while fetching devices data: " in [
record.message
for record in caplog.records
if record.levelname == "ERROR"
and record.name == "homeassistant.components.ring.coordinator"
]
assert any(mock_config_entry.async_get_active_flows(hass, {SOURCE_REAUTH}))
@@ -115,11 +164,11 @@ async def test_auth_failure_on_device_update(
[
(
RingTimeout,
"Time out fetching Ring device data",
"Error fetching devices data: Timeout communicating with API: ",
),
(
RingError,
"Error fetching Ring device data: ",
"Error fetching devices data: Error communicating with API: ",
),
],
ids=["timeout-error", "other-error"],
@@ -145,7 +194,7 @@ async def test_error_on_global_update(
await hass.async_block_till_done()
assert log_msg in [
record.message for record in caplog.records if record.levelname == "WARNING"
record.message for record in caplog.records if record.levelname == "ERROR"
]
assert mock_config_entry.entry_id in hass.data[DOMAIN]
@@ -156,11 +205,11 @@ async def test_error_on_global_update(
[
(
RingTimeout,
"Time out fetching Ring history data for device aacdef123",
"Error fetching devices data: Timeout communicating with API for device Front: ",
),
(
RingError,
"Error fetching Ring history data for device aacdef123: ",
"Error fetching devices data: Error communicating with API for device Front: ",
),
],
ids=["timeout-error", "other-error"],
@@ -186,6 +235,6 @@ async def test_error_on_device_update(
await hass.async_block_till_done()
assert log_msg in [
record.message for record in caplog.records if record.levelname == "WARNING"
record.message for record in caplog.records if record.levelname == "ERROR"
]
assert mock_config_entry.entry_id in hass.data[DOMAIN]
+9 -2
View File
@@ -1,9 +1,10 @@
"""The tests for the Ring switch platform."""
import requests_mock
from homeassistant.const import Platform
from homeassistant.const import ATTR_ENTITY_ID, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component
from .common import setup_platform
@@ -84,7 +85,13 @@ async def test_updates_work(
text=load_fixture("devices_updated.json", "ring"),
)
await hass.services.async_call("ring", "update", {}, blocking=True)
await async_setup_component(hass, "homeassistant", {})
await hass.services.async_call(
"homeassistant",
"update_entity",
{ATTR_ENTITY_ID: ["switch.front_siren"]},
blocking=True,
)
await hass.async_block_till_done()