mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Add madvr diagnostics (#125109)
* feat: add basic diagnostics * fix: add mock data * fix: regen snapshots
This commit is contained in:
parent
adda02b6b1
commit
ba5d23290a
25
homeassistant/components/madvr/diagnostics.py
Normal file
25
homeassistant/components/madvr/diagnostics.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
"""Provides diagnostics for madVR."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.components.diagnostics import async_redact_data
|
||||||
|
from homeassistant.const import CONF_HOST
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from . import MadVRConfigEntry
|
||||||
|
|
||||||
|
TO_REDACT = [CONF_HOST]
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, config_entry: MadVRConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
data = config_entry.runtime_data.data
|
||||||
|
|
||||||
|
return {
|
||||||
|
"config_entry": async_redact_data(config_entry.as_dict(), TO_REDACT),
|
||||||
|
"madvr_data": data,
|
||||||
|
}
|
@ -57,6 +57,7 @@ def mock_config_entry() -> MockConfigEntry:
|
|||||||
data=MOCK_CONFIG,
|
data=MOCK_CONFIG,
|
||||||
unique_id=MOCK_MAC,
|
unique_id=MOCK_MAC,
|
||||||
title=DEFAULT_NAME,
|
title=DEFAULT_NAME,
|
||||||
|
entry_id="3bd2acb0e4f0476d40865546d0d91132",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
26
tests/components/madvr/snapshots/test_diagnostics.ambr
Normal file
26
tests/components/madvr/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_entry_diagnostics[positive_payload0]
|
||||||
|
dict({
|
||||||
|
'config_entry': dict({
|
||||||
|
'data': dict({
|
||||||
|
'host': '**REDACTED**',
|
||||||
|
'port': 44077,
|
||||||
|
}),
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'madvr',
|
||||||
|
'entry_id': '3bd2acb0e4f0476d40865546d0d91132',
|
||||||
|
'minor_version': 1,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'pref_disable_new_entities': False,
|
||||||
|
'pref_disable_polling': False,
|
||||||
|
'source': 'user',
|
||||||
|
'title': 'envy',
|
||||||
|
'unique_id': '00:11:22:33:44:55',
|
||||||
|
'version': 1,
|
||||||
|
}),
|
||||||
|
'madvr_data': dict({
|
||||||
|
'is_on': True,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
# ---
|
48
tests/components/madvr/test_diagnostics.py
Normal file
48
tests/components/madvr/test_diagnostics.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
"""Test madVR diagnostics."""
|
||||||
|
|
||||||
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from syrupy import SnapshotAssertion
|
||||||
|
from syrupy.filters import props
|
||||||
|
|
||||||
|
from homeassistant.const import Platform
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from . import setup_integration
|
||||||
|
from .conftest import get_update_callback
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("positive_payload"),
|
||||||
|
[
|
||||||
|
{"is_on": True},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_entry_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
mock_madvr_client: AsyncMock,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
positive_payload: dict,
|
||||||
|
) -> None:
|
||||||
|
"""Test config entry diagnostics."""
|
||||||
|
with patch("homeassistant.components.madvr.PLATFORMS", [Platform.SENSOR]):
|
||||||
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
|
update_callback = get_update_callback(mock_madvr_client)
|
||||||
|
|
||||||
|
# Add data to test storing diagnostic data
|
||||||
|
update_callback(positive_payload)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
result = await get_diagnostics_for_config_entry(
|
||||||
|
hass, hass_client, mock_config_entry
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result == snapshot(exclude=props("created_at", "modified_at"))
|
Loading…
x
Reference in New Issue
Block a user