From 3f8f206c53defb5dec2013bcaf7f7f7497e84f7c Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 20 Jan 2025 18:13:33 +0100 Subject: [PATCH] Add diagnostics to Overseerr (#136094) --- .../components/overseerr/diagnostics.py | 26 ++++++++++ .../components/overseerr/quality_scale.yaml | 2 +- .../overseerr/snapshots/test_diagnostics.ambr | 31 ++++++++++++ .../components/overseerr/test_diagnostics.py | 47 +++++++++++++++++++ 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/overseerr/diagnostics.py create mode 100644 tests/components/overseerr/snapshots/test_diagnostics.ambr create mode 100644 tests/components/overseerr/test_diagnostics.py diff --git a/homeassistant/components/overseerr/diagnostics.py b/homeassistant/components/overseerr/diagnostics.py new file mode 100644 index 00000000000..d45e1441e23 --- /dev/null +++ b/homeassistant/components/overseerr/diagnostics.py @@ -0,0 +1,26 @@ +"""Diagnostics support for Overseerr.""" + +from __future__ import annotations + +from dataclasses import asdict +from typing import Any + +from homeassistant.core import HomeAssistant + +from . import CONF_CLOUDHOOK_URL +from .coordinator import OverseerrConfigEntry + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: OverseerrConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + + has_cloudhooks = CONF_CLOUDHOOK_URL in entry.data + + data = entry.runtime_data + + return { + "has_cloudhooks": has_cloudhooks, + "coordinator_data": asdict(data.data), + } diff --git a/homeassistant/components/overseerr/quality_scale.yaml b/homeassistant/components/overseerr/quality_scale.yaml index 144f5c1977c..d4295030fdc 100644 --- a/homeassistant/components/overseerr/quality_scale.yaml +++ b/homeassistant/components/overseerr/quality_scale.yaml @@ -41,7 +41,7 @@ rules: test-coverage: todo # Gold devices: done - diagnostics: todo + diagnostics: done discovery-update-info: status: exempt comment: | diff --git a/tests/components/overseerr/snapshots/test_diagnostics.ambr b/tests/components/overseerr/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..164257bb9f1 --- /dev/null +++ b/tests/components/overseerr/snapshots/test_diagnostics.ambr @@ -0,0 +1,31 @@ +# serializer version: 1 +# name: test_diagnostics_polling_instance + dict({ + 'coordinator_data': dict({ + 'approved': 11, + 'available': 8, + 'declined': 0, + 'movie': 9, + 'pending': 0, + 'processing': 3, + 'total': 11, + 'tv': 2, + }), + 'has_cloudhooks': False, + }) +# --- +# name: test_diagnostics_webhook_instance + dict({ + 'coordinator_data': dict({ + 'approved': 11, + 'available': 8, + 'declined': 0, + 'movie': 9, + 'pending': 0, + 'processing': 3, + 'total': 11, + 'tv': 2, + }), + 'has_cloudhooks': True, + }) +# --- diff --git a/tests/components/overseerr/test_diagnostics.py b/tests/components/overseerr/test_diagnostics.py new file mode 100644 index 00000000000..28b97e9514f --- /dev/null +++ b/tests/components/overseerr/test_diagnostics.py @@ -0,0 +1,47 @@ +"""Tests for the diagnostics data provided by the Overseerr integration.""" + +from unittest.mock import AsyncMock + +from syrupy import SnapshotAssertion + +from homeassistant.core import HomeAssistant + +from . import setup_integration + +from tests.common import MockConfigEntry +from tests.components.diagnostics import get_diagnostics_for_config_entry +from tests.typing import ClientSessionGenerator + + +async def test_diagnostics_polling_instance( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + mock_overseerr_client: AsyncMock, + mock_config_entry: MockConfigEntry, + snapshot: SnapshotAssertion, +) -> None: + """Test diagnostics.""" + await setup_integration(hass, mock_config_entry) + + assert ( + await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry) + == snapshot + ) + + +async def test_diagnostics_webhook_instance( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + mock_overseerr_client_cloudhook: AsyncMock, + mock_cloudhook_config_entry: MockConfigEntry, + snapshot: SnapshotAssertion, +) -> None: + """Test diagnostics.""" + await setup_integration(hass, mock_cloudhook_config_entry) + + assert ( + await get_diagnostics_for_config_entry( + hass, hass_client, mock_cloudhook_config_entry + ) + == snapshot + )