Add evil genius labs diagnostics (#64339)
This commit is contained in:
parent
d8df62ba1b
commit
4cd222e70a
4 changed files with 72 additions and 11 deletions
24
homeassistant/components/evil_genius_labs/diagnostics.py
Normal file
24
homeassistant/components/evil_genius_labs/diagnostics.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
"""Diagnostics support for Evil Genius Labs."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import EvilGeniusUpdateCoordinator
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
) -> dict:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: EvilGeniusUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
return {
|
||||
"info": {
|
||||
**coordinator.info,
|
||||
"wiFiSsidDefault": "REDACTED",
|
||||
"wiFiSSID": "REDACTED",
|
||||
},
|
||||
"data": coordinator.data,
|
||||
}
|
|
@ -1 +1,24 @@
|
|||
"""Tests for the Diagnostics integration."""
|
||||
from http import HTTPStatus
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def get_diagnostics_for_config_entry(hass, hass_client, domain_or_config_entry):
|
||||
"""Return the diagnostics config entry for the specified domain."""
|
||||
if isinstance(domain_or_config_entry, str):
|
||||
config_entry = MockConfigEntry(domain=domain_or_config_entry)
|
||||
config_entry.add_to_hass(hass)
|
||||
else:
|
||||
config_entry = domain_or_config_entry
|
||||
|
||||
assert await async_setup_component(hass, "diagnostics", {})
|
||||
|
||||
client = await hass_client()
|
||||
response = await client.get(
|
||||
f"/api/diagnostics/config_entry/{config_entry.entry_id}"
|
||||
)
|
||||
assert response.status == HTTPStatus.OK
|
||||
return await response.json()
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Test the Diagnostics integration."""
|
||||
from http import HTTPStatus
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
import pytest
|
||||
|
@ -7,7 +6,9 @@ import pytest
|
|||
from homeassistant.components.websocket_api.const import TYPE_RESULT
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry, mock_platform
|
||||
from . import get_diagnostics_for_config_entry
|
||||
|
||||
from tests.common import mock_platform
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
@ -45,12 +46,6 @@ async def test_websocket_info(hass, hass_ws_client):
|
|||
|
||||
async def test_download_diagnostics(hass, hass_client):
|
||||
"""Test record service."""
|
||||
config_entry = MockConfigEntry(domain="fake_integration")
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
client = await hass_client()
|
||||
response = await client.get(
|
||||
f"/api/diagnostics/config_entry/{config_entry.entry_id}"
|
||||
)
|
||||
assert response.status == HTTPStatus.OK
|
||||
assert await response.json() == {"hello": "info"}
|
||||
assert await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, "fake_integration"
|
||||
) == {"hello": "info"}
|
||||
|
|
19
tests/components/evil_genius_labs/test_diagnostics.py
Normal file
19
tests/components/evil_genius_labs/test_diagnostics.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
"""Test evil genius labs diagnostics."""
|
||||
import pytest
|
||||
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
|
||||
|
||||
@pytest.mark.parametrize("platforms", [[]])
|
||||
async def test_entry_diagnostics(
|
||||
hass, hass_client, setup_evil_genius_labs, config_entry, data_fixture, info_fixture
|
||||
):
|
||||
"""Test config entry diagnostics."""
|
||||
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
||||
"info": {
|
||||
**info_fixture,
|
||||
"wiFiSsidDefault": "REDACTED",
|
||||
"wiFiSSID": "REDACTED",
|
||||
},
|
||||
"data": data_fixture,
|
||||
}
|
Loading…
Add table
Reference in a new issue