mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Add type hints to diagnostics test helper (#85494)
* Add type hints to diagnostics test helper * Move type alias to the top * Use Any * Move TestClientGenerator to typing helper * Use `dict[str, Any]` again * Use JsonObjectType * Add cast
This commit is contained in:
parent
ecb1d93b2e
commit
94779dddaa
@ -1,10 +1,21 @@
|
||||
"""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.helpers.json import JsonObjectType
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
async def _get_diagnostics_for_config_entry(hass, hass_client, config_entry):
|
||||
|
||||
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", {})
|
||||
|
||||
@ -13,16 +24,25 @@ async def _get_diagnostics_for_config_entry(hass, hass_client, config_entry):
|
||||
f"/api/diagnostics/config_entry/{config_entry.entry_id}"
|
||||
)
|
||||
assert response.status == HTTPStatus.OK
|
||||
return await response.json()
|
||||
return cast(JsonObjectType, await response.json())
|
||||
|
||||
|
||||
async def get_diagnostics_for_config_entry(hass, hass_client, config_entry):
|
||||
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 data["data"]
|
||||
return cast(JsonObjectType, data["data"])
|
||||
|
||||
|
||||
async def _get_diagnostics_for_device(hass, hass_client, config_entry, device):
|
||||
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", {})
|
||||
|
||||
@ -31,10 +51,15 @@ async def _get_diagnostics_for_device(hass, hass_client, config_entry, device):
|
||||
f"/api/diagnostics/config_entry/{config_entry.entry_id}/device/{device.id}"
|
||||
)
|
||||
assert response.status == HTTPStatus.OK
|
||||
return await response.json()
|
||||
return cast(JsonObjectType, await response.json())
|
||||
|
||||
|
||||
async def get_diagnostics_for_device(hass, hass_client, config_entry, device):
|
||||
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 data["data"]
|
||||
return cast(JsonObjectType, data["data"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user