2022-01-18 04:42:18 +00:00
|
|
|
"""Tests for the Diagnostics integration."""
|
2024-03-08 19:38:34 +00:00
|
|
|
|
2022-01-18 20:02:37 +00:00
|
|
|
from http import HTTPStatus
|
2023-02-09 11:15:18 +00:00
|
|
|
from typing import cast
|
2022-01-18 20:02:37 +00:00
|
|
|
|
2023-02-09 11:15:18 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.device_registry import DeviceEntry
|
2022-01-18 20:02:37 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2023-02-16 10:37:57 +00:00
|
|
|
from homeassistant.util.json import JsonObjectType
|
2022-01-18 20:02:37 +00:00
|
|
|
|
2023-02-09 11:15:18 +00:00
|
|
|
from tests.typing import ClientSessionGenerator
|
2022-01-18 20:02:37 +00:00
|
|
|
|
2023-02-09 11:15:18 +00:00
|
|
|
|
|
|
|
async def _get_diagnostics_for_config_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
hass_client: ClientSessionGenerator,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
) -> JsonObjectType:
|
2022-01-18 20:02:37 +00:00
|
|
|
"""Return the diagnostics config entry for the specified domain."""
|
|
|
|
assert await async_setup_component(hass, "diagnostics", {})
|
2024-04-07 07:58:23 +00:00
|
|
|
await hass.async_block_till_done()
|
2022-01-18 20:02:37 +00:00
|
|
|
|
|
|
|
client = await hass_client()
|
|
|
|
response = await client.get(
|
|
|
|
f"/api/diagnostics/config_entry/{config_entry.entry_id}"
|
|
|
|
)
|
|
|
|
assert response.status == HTTPStatus.OK
|
2023-02-09 11:15:18 +00:00
|
|
|
return cast(JsonObjectType, await response.json())
|
2022-01-20 04:48:32 +00:00
|
|
|
|
|
|
|
|
2023-02-09 11:15:18 +00:00
|
|
|
async def get_diagnostics_for_config_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
hass_client: ClientSessionGenerator,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
) -> JsonObjectType:
|
2022-01-23 09:15:23 +00:00
|
|
|
"""Return the diagnostics config entry for the specified domain."""
|
|
|
|
data = await _get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
2023-02-09 11:15:18 +00:00
|
|
|
return cast(JsonObjectType, data["data"])
|
2022-01-23 09:15:23 +00:00
|
|
|
|
|
|
|
|
2023-02-09 11:15:18 +00:00
|
|
|
async def _get_diagnostics_for_device(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
hass_client: ClientSessionGenerator,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
device: DeviceEntry,
|
|
|
|
) -> JsonObjectType:
|
2022-01-20 04:48:32 +00:00
|
|
|
"""Return the diagnostics for the specified device."""
|
2022-01-20 10:49:24 +00:00
|
|
|
assert await async_setup_component(hass, "diagnostics", {})
|
|
|
|
|
2022-01-20 04:48:32 +00:00
|
|
|
client = await hass_client()
|
|
|
|
response = await client.get(
|
|
|
|
f"/api/diagnostics/config_entry/{config_entry.entry_id}/device/{device.id}"
|
|
|
|
)
|
|
|
|
assert response.status == HTTPStatus.OK
|
2023-02-09 11:15:18 +00:00
|
|
|
return cast(JsonObjectType, await response.json())
|
2022-01-23 09:15:23 +00:00
|
|
|
|
|
|
|
|
2023-02-09 11:15:18 +00:00
|
|
|
async def get_diagnostics_for_device(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
hass_client: ClientSessionGenerator,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
device: DeviceEntry,
|
|
|
|
) -> JsonObjectType:
|
2022-01-23 09:15:23 +00:00
|
|
|
"""Return the diagnostics for the specified device."""
|
|
|
|
data = await _get_diagnostics_for_device(hass, hass_client, config_entry, device)
|
2023-02-09 11:15:18 +00:00
|
|
|
return cast(JsonObjectType, data["data"])
|