2022-01-27 22:03:20 +00:00
|
|
|
"""Tests for the diagnostics data provided by the KNX integration."""
|
|
|
|
|
2023-02-20 15:57:12 +00:00
|
|
|
import pytest
|
2023-08-21 09:48:55 +00:00
|
|
|
from syrupy import SnapshotAssertion
|
2022-03-30 19:10:47 +00:00
|
|
|
from xknx.io import DEFAULT_MCAST_GRP, DEFAULT_MCAST_PORT
|
2022-01-27 22:03:20 +00:00
|
|
|
|
2022-03-30 19:10:47 +00:00
|
|
|
from homeassistant.components.knx.const import (
|
|
|
|
CONF_KNX_AUTOMATIC,
|
|
|
|
CONF_KNX_CONNECTION_TYPE,
|
|
|
|
CONF_KNX_DEFAULT_RATE_LIMIT,
|
|
|
|
CONF_KNX_DEFAULT_STATE_UPDATER,
|
|
|
|
CONF_KNX_INDIVIDUAL_ADDRESS,
|
|
|
|
CONF_KNX_KNXKEY_PASSWORD,
|
|
|
|
CONF_KNX_MCAST_GRP,
|
|
|
|
CONF_KNX_MCAST_PORT,
|
|
|
|
CONF_KNX_RATE_LIMIT,
|
2022-11-27 22:33:12 +00:00
|
|
|
CONF_KNX_ROUTING_BACKBONE_KEY,
|
2022-03-30 19:10:47 +00:00
|
|
|
CONF_KNX_SECURE_DEVICE_AUTHENTICATION,
|
|
|
|
CONF_KNX_SECURE_USER_PASSWORD,
|
|
|
|
CONF_KNX_STATE_UPDATER,
|
2022-11-26 05:49:11 +00:00
|
|
|
DEFAULT_ROUTING_IA,
|
2022-03-30 19:10:47 +00:00
|
|
|
DOMAIN as KNX_DOMAIN,
|
|
|
|
)
|
2022-01-27 22:03:20 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
2022-09-19 07:46:59 +00:00
|
|
|
from .conftest import KNXTestKit
|
|
|
|
|
2022-01-27 22:03:20 +00:00
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
2023-02-02 21:29:57 +00:00
|
|
|
from tests.typing import ClientSessionGenerator
|
2022-01-27 22:03:20 +00:00
|
|
|
|
|
|
|
|
2023-02-20 15:57:12 +00:00
|
|
|
@pytest.mark.parametrize("hass_config", [{}])
|
2022-01-27 22:03:20 +00:00
|
|
|
async def test_diagnostics(
|
|
|
|
hass: HomeAssistant,
|
2023-02-02 21:29:57 +00:00
|
|
|
hass_client: ClientSessionGenerator,
|
2022-01-27 22:03:20 +00:00
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
knx: KNXTestKit,
|
2023-02-20 15:57:12 +00:00
|
|
|
mock_hass_config: None,
|
2023-08-21 09:48:55 +00:00
|
|
|
snapshot: SnapshotAssertion,
|
2023-02-13 12:03:51 +00:00
|
|
|
) -> None:
|
2022-01-27 22:03:20 +00:00
|
|
|
"""Test diagnostics."""
|
|
|
|
await knx.setup_integration({})
|
|
|
|
|
2023-02-20 15:57:12 +00:00
|
|
|
# Overwrite the version for this test since we don't want to change this with every library bump
|
2023-08-21 09:48:55 +00:00
|
|
|
knx.xknx.version = "0.0.0"
|
|
|
|
assert (
|
|
|
|
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry)
|
|
|
|
== snapshot
|
|
|
|
)
|
2022-01-27 22:03:20 +00:00
|
|
|
|
|
|
|
|
2023-02-20 15:57:12 +00:00
|
|
|
@pytest.mark.parametrize("hass_config", [{"knx": {"wrong_key": {}}}])
|
2022-01-27 22:03:20 +00:00
|
|
|
async def test_diagnostic_config_error(
|
|
|
|
hass: HomeAssistant,
|
2023-02-20 15:57:12 +00:00
|
|
|
mock_hass_config: None,
|
2023-02-02 21:29:57 +00:00
|
|
|
hass_client: ClientSessionGenerator,
|
2022-01-27 22:03:20 +00:00
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
knx: KNXTestKit,
|
2023-08-21 09:48:55 +00:00
|
|
|
snapshot: SnapshotAssertion,
|
2023-02-13 12:03:51 +00:00
|
|
|
) -> None:
|
2022-01-27 22:03:20 +00:00
|
|
|
"""Test diagnostics."""
|
|
|
|
await knx.setup_integration({})
|
|
|
|
|
2023-02-20 15:57:12 +00:00
|
|
|
# Overwrite the version for this test since we don't want to change this with every library bump
|
2023-08-21 09:48:55 +00:00
|
|
|
knx.xknx.version = "0.0.0"
|
|
|
|
# the snapshot will contain 'configuration_error' key with the voluptuous error message
|
|
|
|
assert (
|
|
|
|
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry)
|
|
|
|
== snapshot
|
|
|
|
)
|
2022-03-30 19:10:47 +00:00
|
|
|
|
|
|
|
|
2023-02-20 15:57:12 +00:00
|
|
|
@pytest.mark.parametrize("hass_config", [{}])
|
2022-03-30 19:10:47 +00:00
|
|
|
async def test_diagnostic_redact(
|
|
|
|
hass: HomeAssistant,
|
2023-02-02 21:29:57 +00:00
|
|
|
hass_client: ClientSessionGenerator,
|
2023-02-20 15:57:12 +00:00
|
|
|
mock_hass_config: None,
|
2023-08-21 09:48:55 +00:00
|
|
|
snapshot: SnapshotAssertion,
|
2023-02-13 12:03:51 +00:00
|
|
|
) -> None:
|
2022-03-30 19:10:47 +00:00
|
|
|
"""Test diagnostics redacting data."""
|
|
|
|
mock_config_entry: MockConfigEntry = MockConfigEntry(
|
|
|
|
title="KNX",
|
|
|
|
domain=KNX_DOMAIN,
|
|
|
|
data={
|
|
|
|
CONF_KNX_CONNECTION_TYPE: CONF_KNX_AUTOMATIC,
|
|
|
|
CONF_KNX_RATE_LIMIT: CONF_KNX_DEFAULT_RATE_LIMIT,
|
|
|
|
CONF_KNX_STATE_UPDATER: CONF_KNX_DEFAULT_STATE_UPDATER,
|
|
|
|
CONF_KNX_MCAST_PORT: DEFAULT_MCAST_PORT,
|
|
|
|
CONF_KNX_MCAST_GRP: DEFAULT_MCAST_GRP,
|
2022-11-26 05:49:11 +00:00
|
|
|
CONF_KNX_INDIVIDUAL_ADDRESS: DEFAULT_ROUTING_IA,
|
2022-03-30 19:10:47 +00:00
|
|
|
CONF_KNX_KNXKEY_PASSWORD: "password",
|
|
|
|
CONF_KNX_SECURE_USER_PASSWORD: "user_password",
|
|
|
|
CONF_KNX_SECURE_DEVICE_AUTHENTICATION: "device_authentication",
|
2022-11-27 22:33:12 +00:00
|
|
|
CONF_KNX_ROUTING_BACKBONE_KEY: "bbaacc44bbaacc44bbaacc44bbaacc44",
|
2022-03-30 19:10:47 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
knx: KNXTestKit = KNXTestKit(hass, mock_config_entry)
|
|
|
|
await knx.setup_integration({})
|
|
|
|
|
2023-02-20 15:57:12 +00:00
|
|
|
# Overwrite the version for this test since we don't want to change this with every library bump
|
2023-08-21 09:48:55 +00:00
|
|
|
knx.xknx.version = "0.0.0"
|
|
|
|
assert (
|
|
|
|
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry)
|
|
|
|
== snapshot
|
|
|
|
)
|
2023-05-10 22:13:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("hass_config", [{}])
|
|
|
|
async def test_diagnostics_project(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
hass_client: ClientSessionGenerator,
|
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
knx: KNXTestKit,
|
|
|
|
mock_hass_config: None,
|
|
|
|
load_knxproj: None,
|
2023-08-21 09:48:55 +00:00
|
|
|
snapshot: SnapshotAssertion,
|
2023-05-10 22:13:22 +00:00
|
|
|
) -> None:
|
|
|
|
"""Test diagnostics."""
|
|
|
|
await knx.setup_integration({})
|
2023-08-21 09:48:55 +00:00
|
|
|
knx.xknx.version = "0.0.0"
|
|
|
|
# snapshot will contain project specific fields in `project_info`
|
|
|
|
assert (
|
|
|
|
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry)
|
|
|
|
== snapshot
|
|
|
|
)
|