2022-01-18 04:42:18 +00:00
|
|
|
"""Tests for the Diagnostics integration."""
|
2022-01-18 20:02:37 +00:00
|
|
|
from http import HTTPStatus
|
|
|
|
|
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
|
2022-01-23 09:15:23 +00:00
|
|
|
async def _get_diagnostics_for_config_entry(hass, hass_client, config_entry):
|
2022-01-18 20:02:37 +00:00
|
|
|
"""Return the diagnostics config entry for the specified domain."""
|
|
|
|
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()
|
2022-01-20 04:48:32 +00:00
|
|
|
|
|
|
|
|
2022-01-23 09:15:23 +00:00
|
|
|
async def get_diagnostics_for_config_entry(hass, hass_client, config_entry):
|
|
|
|
"""Return the diagnostics config entry for the specified domain."""
|
|
|
|
data = await _get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
|
|
|
return data["data"]
|
|
|
|
|
|
|
|
|
|
|
|
async def _get_diagnostics_for_device(hass, hass_client, config_entry, device):
|
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
|
|
|
|
return await response.json()
|
2022-01-23 09:15:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def get_diagnostics_for_device(hass, hass_client, config_entry, device):
|
|
|
|
"""Return the diagnostics for the specified device."""
|
|
|
|
data = await _get_diagnostics_for_device(hass, hass_client, config_entry, device)
|
|
|
|
return data["data"]
|