hass-core/tests/components/diagnostics/__init__.py
epenet ba23816a0c
Inverse json import logic (#88099)
* Fix helpers and util

* Adjust components

* Move back errors

* Add report

* mypy

* mypy

* Assert deprecation messages

* Move test_json_loads_object

* Adjust tests

* Fix rebase

* Adjust pylint plugin

* Fix plugin

* Adjust references

* Adjust backup tests
2023-02-16 11:37:57 +01:00

65 lines
2.2 KiB
Python

"""Tests for the Diagnostics integration."""
from http import HTTPStatus
from typing import cast
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntry
from homeassistant.setup import async_setup_component
from homeassistant.util.json import JsonObjectType
from tests.typing import ClientSessionGenerator
async def _get_diagnostics_for_config_entry(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
config_entry: ConfigEntry,
) -> JsonObjectType:
"""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 cast(JsonObjectType, await response.json())
async def get_diagnostics_for_config_entry(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
config_entry: ConfigEntry,
) -> JsonObjectType:
"""Return the diagnostics config entry for the specified domain."""
data = await _get_diagnostics_for_config_entry(hass, hass_client, config_entry)
return cast(JsonObjectType, data["data"])
async def _get_diagnostics_for_device(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
config_entry: ConfigEntry,
device: DeviceEntry,
) -> JsonObjectType:
"""Return the diagnostics for the specified device."""
assert await async_setup_component(hass, "diagnostics", {})
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 cast(JsonObjectType, await response.json())
async def get_diagnostics_for_device(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
config_entry: ConfigEntry,
device: DeviceEntry,
) -> JsonObjectType:
"""Return the diagnostics for the specified device."""
data = await _get_diagnostics_for_device(hass, hass_client, config_entry, device)
return cast(JsonObjectType, data["data"])