2022-01-17 20:42:18 -08:00
|
|
|
"""Tests for the Diagnostics integration."""
|
2022-01-18 12:02:37 -08:00
|
|
|
from http import HTTPStatus
|
|
|
|
|
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
|
2022-01-23 10:15:23 +01:00
|
|
|
async def _get_diagnostics_for_config_entry(hass, hass_client, config_entry):
|
2022-01-18 12:02:37 -08: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-19 23:48:32 -05:00
|
|
|
|
|
|
|
|
2022-01-23 10:15:23 +01: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-19 23:48:32 -05:00
|
|
|
"""Return the diagnostics for the specified device."""
|
2022-01-20 05:49:24 -05:00
|
|
|
assert await async_setup_component(hass, "diagnostics", {})
|
|
|
|
|
2022-01-19 23:48:32 -05: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 10:15:23 +01: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"]
|