generated from ludeeus/integration_blueprint
-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_diagnostics.py
63 lines (48 loc) · 2.21 KB
/
test_diagnostics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Test kamstrup_403 diagnostics."""
from http import HTTPStatus
from typing import cast
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from homeassistant.util.json import JsonObjectType
from pytest_homeassistant_custom_component.common import MockConfigEntry
from pytest_homeassistant_custom_component.typing import ClientSessionGenerator
from custom_components.kamstrup_403.const import DOMAIN
from .const import MOCK_CONFIG
async def test_config_entry_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
bypass_get_data,
) -> None:
"""Test config entry diagnostics."""
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test")
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
result = await get_diagnostics_for_config_entry(hass, hass_client, entry)
assert result["config_entry"]["entry_id"] == "test"
assert result["config_entry"]["domain"] == DOMAIN
assert result["registered_commands"] == [60, 68, 99, 113, 1001, 1004]
# The following 2 functions are copied from https://github.com/home-assistant/core/blob/dev/tests/components/diagnostics/__init__.py
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", {})
await hass.async_block_till_done()
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"])