generated from ludeeus/integration_blueprint
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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"]) |