"""Test the satel integra config flow."""

from typing import Any
from unittest.mock import AsyncMock, MagicMock

import pytest
from satel_integra import (
    SatelConnectFailedError,
    SatelConnectionInitializationError,
    SatelPanelBusyError,
)

from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.satel_integra.const import (
    CONF_ARM_HOME_MODE,
    CONF_ENABLE_TEMPERATURE_SENSOR,
    CONF_ENCRYPTION_KEY,
    CONF_OUTPUT_NUMBER,
    CONF_PARTITION_NUMBER,
    CONF_SWITCHABLE_OUTPUT_NUMBER,
    CONF_ZONE_NUMBER,
    CONF_ZONE_TYPE,
    DEFAULT_PORT,
    DOMAIN,
)
from homeassistant.config_entries import (
    SOURCE_RECONFIGURE,
    SOURCE_USER,
    ConfigEntryState,
    ConfigSubentry,
)
from homeassistant.const import CONF_CODE, CONF_HOST, CONF_NAME, CONF_PORT
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType

from . import (
    MOCK_CONFIG_DATA,
    MOCK_CONFIG_OPTIONS,
    MOCK_OUTPUT_SUBENTRY,
    MOCK_PARTITION_SUBENTRY,
    MOCK_SWITCHABLE_OUTPUT_SUBENTRY,
    MOCK_ZONE_SUBENTRY,
    MOCK_ZONE_TEMPERATURE_SUBENTRY,
    setup_integration,
)

from tests.common import MockConfigEntry


@pytest.mark.parametrize(
    ("user_input_connection", "user_input_code", "entry_data", "entry_options"),
    [
        (
            MOCK_CONFIG_DATA,
            MOCK_CONFIG_OPTIONS,
            MOCK_CONFIG_DATA,
            MOCK_CONFIG_OPTIONS,
        ),
        (
            {CONF_HOST: MOCK_CONFIG_DATA[CONF_HOST]},
            {},
            {
                CONF_HOST: MOCK_CONFIG_DATA[CONF_HOST],
                CONF_PORT: DEFAULT_PORT,
                CONF_ENCRYPTION_KEY: None,
            },
            {CONF_CODE: None},
        ),
    ],
)
async def test_setup_flow(
    hass: HomeAssistant,
    mock_satel: AsyncMock,
    mock_setup_entry: AsyncMock,
    user_input_connection: dict[str, Any],
    user_input_code: dict[str, Any],
    entry_data: dict[str, Any],
    entry_options: dict[str, Any],
) -> None:
    """Test the setup flow."""

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": SOURCE_USER}
    )
    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "user"
    assert result["errors"] == {}

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        user_input_connection,
    )
    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "code"

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        user_input_code,
    )
    assert result["type"] is FlowResultType.CREATE_ENTRY
    assert result["title"] == MOCK_CONFIG_DATA[CONF_HOST]
    assert result["data"] == entry_data
    assert result["options"] == entry_options

    assert len(mock_setup_entry.mock_calls) == 1


@pytest.mark.parametrize(
    ("exception", "error"),
    [
        (SatelConnectFailedError, "cannot_connect"),
        (SatelPanelBusyError, "panel_busy"),
        (SatelConnectionInitializationError, "connection_initialization_failed"),
        (Exception, "unknown"),
    ],
)
async def test_setup_connection_failed(
    hass: HomeAssistant,
    mock_satel: AsyncMock,
    mock_setup_entry: AsyncMock,
    exception: Exception,
    error: str,
) -> None:
    """Test the setup flow when connection fails."""
    user_input = MOCK_CONFIG_DATA

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": SOURCE_USER}
    )

    mock_satel.connect.side_effect = exception

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        user_input,
    )

    assert result["type"] is FlowResultType.FORM
    assert result["errors"] == {"base": error}

    mock_satel.connect.side_effect = None

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        user_input,
    )

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "code"

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {},
    )

    assert result["type"] is FlowResultType.CREATE_ENTRY
    assert len(mock_setup_entry.mock_calls) == 1


@pytest.mark.parametrize(
    ("user_input", "entry_options"),
    [
        ({CONF_CODE: "1111"}, {CONF_CODE: "1111"}),
        ({}, {CONF_CODE: None}),
    ],
)
async def test_options_flow(
    hass: HomeAssistant,
    mock_satel: AsyncMock,
    mock_reload_after_entry_update: MagicMock,
    mock_config_entry: MockConfigEntry,
    user_input: dict[str, Any],
    entry_options: dict[str, Any],
) -> None:
    """Test general options flow."""
    await setup_integration(hass, mock_config_entry)

    result = await hass.config_entries.options.async_init(mock_config_entry.entry_id)

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "init"

    result = await hass.config_entries.options.async_configure(
        result["flow_id"], user_input
    )

    assert result["type"] is FlowResultType.CREATE_ENTRY
    assert mock_config_entry.options == entry_options

    # Assert the entry is reloaded to use the updated code
    assert mock_reload_after_entry_update.call_count == 1


@pytest.mark.parametrize(
    ("user_input", "subentry"),
    [
        (MOCK_PARTITION_SUBENTRY.data, MOCK_PARTITION_SUBENTRY),
        (MOCK_ZONE_SUBENTRY.data, MOCK_ZONE_SUBENTRY),
        (MOCK_ZONE_TEMPERATURE_SUBENTRY.data, MOCK_ZONE_TEMPERATURE_SUBENTRY),
        (MOCK_OUTPUT_SUBENTRY.data, MOCK_OUTPUT_SUBENTRY),
        (MOCK_SWITCHABLE_OUTPUT_SUBENTRY.data, MOCK_SWITCHABLE_OUTPUT_SUBENTRY),
    ],
)
async def test_subentry_creation(
    hass: HomeAssistant,
    mock_satel: AsyncMock,
    mock_reload_after_entry_update: MagicMock,
    mock_config_entry: MockConfigEntry,
    user_input: dict[str, Any],
    subentry: ConfigSubentry,
) -> None:
    """Test partitions options flow."""
    await setup_integration(hass, mock_config_entry)

    result = await hass.config_entries.subentries.async_init(
        (mock_config_entry.entry_id, subentry.subentry_type),
        context={"source": SOURCE_USER},
    )

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "user"

    result = await hass.config_entries.subentries.async_configure(
        result["flow_id"],
        user_input,
    )

    assert result["type"] is FlowResultType.CREATE_ENTRY
    assert len(mock_config_entry.subentries) == 1

    subentry_id = list(mock_config_entry.subentries)[0]

    subentry_result = {
        **subentry.as_dict(),
        "subentry_id": subentry_id,
    }
    assert mock_config_entry.subentries.get(subentry_id) == ConfigSubentry(
        **subentry_result
    )

    # Assert the entry is reloaded to set up the entity
    assert mock_reload_after_entry_update.call_count == 1


@pytest.mark.parametrize(
    ("read_temperature_side_effect", "expected_errors"),
    [
        (
            None,
            {CONF_ENABLE_TEMPERATURE_SENSOR: "zone_does_not_report_temperature"},
        ),
        (Exception("Boom"), {"base": "unknown"}),
    ],
)
async def test_zone_temperature_sensor_validation_on_create(
    hass: HomeAssistant,
    mock_satel: AsyncMock,
    mock_reload_after_entry_update: MagicMock,
    mock_config_entry: MockConfigEntry,
    read_temperature_side_effect: Exception | None,
    expected_errors: dict[str, str],
) -> None:
    """Test temperature sensor enablement validation errors."""
    await setup_integration(hass, mock_config_entry)
    mock_satel.read_temperature.return_value = None
    mock_satel.read_temperature.side_effect = read_temperature_side_effect

    result = await hass.config_entries.subentries.async_init(
        (mock_config_entry.entry_id, MOCK_ZONE_SUBENTRY.subentry_type),
        context={"source": SOURCE_USER},
    )

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "user"

    result = await hass.config_entries.subentries.async_configure(
        result["flow_id"],
        MOCK_ZONE_TEMPERATURE_SUBENTRY.data,
    )

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "user"
    assert result["errors"] == expected_errors
    assert len(mock_config_entry.subentries) == 0
    mock_satel.read_temperature.assert_awaited_once_with(1)
    assert mock_reload_after_entry_update.call_count == 0


async def test_zone_temperature_sensor_validation_requires_loaded_entry(
    hass: HomeAssistant,
    mock_satel: AsyncMock,
    mock_config_entry: MockConfigEntry,
) -> None:
    """Test temperature validation only runs against a loaded config entry."""
    mock_config_entry.add_to_hass(hass)

    result = await hass.config_entries.subentries.async_init(
        (mock_config_entry.entry_id, MOCK_ZONE_SUBENTRY.subentry_type),
        context={"source": SOURCE_USER},
    )

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "user"

    result = await hass.config_entries.subentries.async_configure(
        result["flow_id"],
        MOCK_ZONE_TEMPERATURE_SUBENTRY.data,
    )

    assert result["type"] is FlowResultType.ABORT
    assert result["reason"] == "entry_not_loaded"
    mock_satel.read_temperature.assert_not_awaited()


@pytest.mark.parametrize(
    (
        "user_input",
        "subentry",
        "number_property",
    ),
    [
        (
            {CONF_NAME: "New Home", CONF_ARM_HOME_MODE: 3},
            MOCK_PARTITION_SUBENTRY,
            CONF_PARTITION_NUMBER,
        ),
        (
            {
                CONF_NAME: "Backdoor",
                CONF_ZONE_TYPE: BinarySensorDeviceClass.DOOR,
                CONF_ENABLE_TEMPERATURE_SENSOR: False,
            },
            MOCK_ZONE_SUBENTRY,
            CONF_ZONE_NUMBER,
        ),
        (
            {
                CONF_NAME: "Backdoor",
                CONF_ZONE_TYPE: BinarySensorDeviceClass.DOOR,
                CONF_ENABLE_TEMPERATURE_SENSOR: True,
            },
            MOCK_ZONE_TEMPERATURE_SUBENTRY,
            CONF_ZONE_NUMBER,
        ),
        (
            {
                CONF_NAME: "Alarm Triggered",
                CONF_ZONE_TYPE: BinarySensorDeviceClass.PROBLEM,
            },
            MOCK_OUTPUT_SUBENTRY,
            CONF_OUTPUT_NUMBER,
        ),
        (
            {CONF_NAME: "Gate Lock"},
            MOCK_SWITCHABLE_OUTPUT_SUBENTRY,
            CONF_SWITCHABLE_OUTPUT_NUMBER,
        ),
    ],
)
async def test_subentry_reconfigure(
    hass: HomeAssistant,
    mock_satel: AsyncMock,
    mock_config_entry_with_subentries: MockConfigEntry,
    user_input: dict[str, Any],
    subentry: ConfigSubentry,
    number_property: str,
) -> None:
    """Test subentry reconfiguration."""
    await setup_integration(hass, mock_config_entry_with_subentries)

    result = await hass.config_entries.subentries.async_init(
        (
            mock_config_entry_with_subentries.entry_id,
            subentry.subentry_type,
        ),
        context={
            "source": SOURCE_RECONFIGURE,
            "subentry_id": subentry.subentry_id,
        },
    )

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "reconfigure"

    result = await hass.config_entries.subentries.async_configure(
        result["flow_id"],
        user_input,
    )

    assert result["type"] is FlowResultType.ABORT
    assert result["reason"] == "reconfigure_successful"
    assert len(mock_config_entry_with_subentries.subentries) == 4

    subentry_result = {
        **subentry.as_dict(),
        "data": {**subentry.data, **user_input},
        "title": f"{user_input.get(CONF_NAME)} ({subentry.data[number_property]})",
    }

    assert mock_config_entry_with_subentries.subentries.get(
        subentry.subentry_id
    ) == ConfigSubentry(**subentry_result)


async def test_zone_temperature_sensor_validation_on_reconfigure(
    hass: HomeAssistant,
    mock_satel: AsyncMock,
    mock_reload_after_entry_update: MagicMock,
    mock_config_entry_with_subentries: MockConfigEntry,
) -> None:
    """Test enabling a temperature sensor fails if the zone returns no data."""
    await setup_integration(hass, mock_config_entry_with_subentries)
    mock_satel.read_temperature.return_value = None

    result = await hass.config_entries.subentries.async_init(
        (
            mock_config_entry_with_subentries.entry_id,
            MOCK_ZONE_SUBENTRY.subentry_type,
        ),
        context={
            "source": SOURCE_RECONFIGURE,
            "subentry_id": MOCK_ZONE_SUBENTRY.subentry_id,
        },
    )

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "reconfigure"

    result = await hass.config_entries.subentries.async_configure(
        result["flow_id"],
        {
            CONF_NAME: "Backdoor",
            CONF_ZONE_TYPE: BinarySensorDeviceClass.DOOR,
            CONF_ENABLE_TEMPERATURE_SENSOR: True,
        },
    )

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "reconfigure"
    assert result["errors"] == {
        CONF_ENABLE_TEMPERATURE_SENSOR: "zone_does_not_report_temperature"
    }
    assert (
        mock_config_entry_with_subentries.subentries.get(MOCK_ZONE_SUBENTRY.subentry_id)
        == MOCK_ZONE_SUBENTRY
    )
    mock_satel.read_temperature.assert_awaited_once_with(1)
    assert mock_reload_after_entry_update.call_count == 0


async def test_zone_temperature_sensor_validation_on_reconfigure_requires_loaded_entry(
    hass: HomeAssistant,
    mock_satel: AsyncMock,
    mock_config_entry_with_subentries: MockConfigEntry,
) -> None:
    """Test temperature validation only runs against a loaded config entry."""
    mock_config_entry_with_subentries.add_to_hass(hass)

    result = await hass.config_entries.subentries.async_init(
        (
            mock_config_entry_with_subentries.entry_id,
            MOCK_ZONE_SUBENTRY.subentry_type,
        ),
        context={
            "source": SOURCE_RECONFIGURE,
            "subentry_id": MOCK_ZONE_SUBENTRY.subentry_id,
        },
    )

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "reconfigure"

    result = await hass.config_entries.subentries.async_configure(
        result["flow_id"],
        {
            CONF_NAME: "Backdoor",
            CONF_ZONE_TYPE: BinarySensorDeviceClass.DOOR,
            CONF_ENABLE_TEMPERATURE_SENSOR: True,
        },
    )

    assert result["type"] is FlowResultType.ABORT
    assert result["reason"] == "entry_not_loaded"
    assert (
        mock_config_entry_with_subentries.subentries.get(MOCK_ZONE_SUBENTRY.subentry_id)
        == MOCK_ZONE_SUBENTRY
    )
    mock_satel.read_temperature.assert_not_awaited()


@pytest.mark.parametrize(
    ("subentry", "error_field"),
    [
        (MOCK_PARTITION_SUBENTRY, CONF_PARTITION_NUMBER),
        (MOCK_ZONE_SUBENTRY, CONF_ZONE_NUMBER),
        (MOCK_OUTPUT_SUBENTRY, CONF_OUTPUT_NUMBER),
        (MOCK_SWITCHABLE_OUTPUT_SUBENTRY, CONF_SWITCHABLE_OUTPUT_NUMBER),
    ],
)
async def test_cannot_create_same_subentry(
    hass: HomeAssistant,
    mock_satel: AsyncMock,
    mock_setup_entry: AsyncMock,
    mock_config_entry_with_subentries: MockConfigEntry,
    subentry: ConfigSubentry,
    error_field: str,
) -> None:
    """Test subentry reconfiguration."""
    await setup_integration(hass, mock_config_entry_with_subentries)
    mock_setup_entry.reset_mock()

    result = await hass.config_entries.subentries.async_init(
        (mock_config_entry_with_subentries.entry_id, subentry.subentry_type),
        context={"source": SOURCE_USER},
    )

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "user"

    result = await hass.config_entries.subentries.async_configure(
        result["flow_id"], {**subentry.data}
    )

    assert result["type"] is FlowResultType.FORM
    assert result["errors"] == {error_field: "already_configured"}
    assert len(mock_config_entry_with_subentries.subentries) == 4

    assert len(mock_setup_entry.mock_calls) == 0


async def test_reconfigure_flow_success(
    hass: HomeAssistant,
    mock_satel: AsyncMock,
    mock_setup_entry: AsyncMock,
    mock_config_entry: MockConfigEntry,
) -> None:
    """Test that reconfigure updates host/port."""
    mock_config_entry.add_to_hass(hass)

    result = await mock_config_entry.start_reconfigure_flow(hass)

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "reconfigure"

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {
            CONF_HOST: "10.0.0.2",
            CONF_PORT: 4321,
        },
    )

    assert result["type"] is FlowResultType.ABORT
    assert result["reason"] == "reconfigure_successful"

    assert mock_config_entry.data == {
        CONF_HOST: "10.0.0.2",
        CONF_PORT: 4321,
        CONF_ENCRYPTION_KEY: None,
    }

    await hass.async_block_till_done()
    assert mock_setup_entry.call_count == 1


async def test_reconfigure_flow_config_unchanged_loaded(
    hass: HomeAssistant,
    mock_satel: AsyncMock,
    mock_setup_entry: AsyncMock,
    mock_config_entry: MockConfigEntry,
) -> None:
    """Test reconfigure skips connection testing if loaded config is unchanged."""
    await setup_integration(hass, mock_config_entry)

    result = await mock_config_entry.start_reconfigure_flow(hass)

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "reconfigure"
    assert mock_config_entry.state is ConfigEntryState.LOADED

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"], dict(mock_config_entry.data)
    )

    assert result["type"] is FlowResultType.ABORT
    assert result["reason"] == "reconfigure_successful"
    assert mock_config_entry.data == MOCK_CONFIG_DATA
    assert mock_satel.connect.call_count == 0

    await hass.async_block_till_done()
    assert mock_setup_entry.call_count == 1


async def test_reconfigure_flow_config_unchanged_not_loaded(
    hass: HomeAssistant,
    mock_satel: AsyncMock,
    mock_setup_entry: AsyncMock,
    mock_config_entry: MockConfigEntry,
) -> None:
    """Test reconfigure validates unchanged config if the entry is not loaded."""
    mock_config_entry.add_to_hass(hass)

    result = await mock_config_entry.start_reconfigure_flow(hass)

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "reconfigure"
    assert mock_config_entry.state is ConfigEntryState.NOT_LOADED

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"], dict(mock_config_entry.data)
    )

    assert result["type"] is FlowResultType.ABORT
    assert result["reason"] == "reconfigure_successful"
    assert mock_config_entry.data == MOCK_CONFIG_DATA
    assert mock_satel.connect.call_count == 1
    assert mock_setup_entry.call_count == 1


@pytest.mark.parametrize(
    ("exception", "error"),
    [
        (SatelConnectFailedError, "cannot_connect"),
        (SatelPanelBusyError, "panel_busy"),
        (SatelConnectionInitializationError, "connection_initialization_failed"),
        (Exception, "unknown"),
    ],
)
async def test_reconfigure_connection_failed(
    hass: HomeAssistant,
    mock_satel: AsyncMock,
    mock_config_entry: MockConfigEntry,
    exception: Exception,
    error: str,
) -> None:
    """Failure path for the reconfigure flow."""

    mock_satel.connect.side_effect = exception

    mock_config_entry.add_to_hass(hass)

    result = await mock_config_entry.start_reconfigure_flow(hass)

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "reconfigure"

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {CONF_HOST: "1.2.3.4", CONF_PORT: 1234},
    )

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "reconfigure"
    assert result["errors"] == {"base": error}

    mock_satel.connect.side_effect = None

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {CONF_HOST: "1.2.3.4", CONF_PORT: 1234},
    )

    assert result["type"] is FlowResultType.ABORT
    assert result["reason"] == "reconfigure_successful"

    assert mock_config_entry.data == {
        CONF_HOST: "1.2.3.4",
        CONF_PORT: 1234,
        CONF_ENCRYPTION_KEY: None,
    }


async def test_same_host_config_disallowed(
    hass: HomeAssistant, mock_config_entry: MockConfigEntry
) -> None:
    """Test that only one Satel Integra configuration is allowed."""
    mock_config_entry.add_to_hass(hass)

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": SOURCE_USER}
    )

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "user"
    assert result["errors"] == {}

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        MOCK_CONFIG_DATA,
    )

    assert result["type"] is FlowResultType.ABORT
    assert result["reason"] == "already_configured"


@pytest.mark.usefixtures("mock_setup_entry")
async def test_reconfigure_encryption_key_changed(
    hass: HomeAssistant, mock_satel: AsyncMock, mock_config_entry: MockConfigEntry
) -> None:
    """Test reconfigure flow when encryption key is changed."""
    mock_config_entry.add_to_hass(hass)

    result = await mock_config_entry.start_reconfigure_flow(hass)

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "reconfigure"

    # Change encryption key
    user_input = {
        CONF_HOST: "192.168.0.2",
        CONF_PORT: DEFAULT_PORT,
        CONF_ENCRYPTION_KEY: "new_key",
    }

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"], user_input
    )

    assert result["type"] is FlowResultType.ABORT
    assert result["reason"] == "reconfigure_successful"

    expected_data = {
        CONF_HOST: "192.168.0.2",
        CONF_PORT: DEFAULT_PORT,
        CONF_ENCRYPTION_KEY: "new_key",
    }
    assert mock_config_entry.data == expected_data


@pytest.mark.usefixtures("mock_setup_entry")
async def test_reconfigure_encryption_key_removed(
    hass: HomeAssistant, mock_satel: AsyncMock, mock_config_entry: MockConfigEntry
) -> None:
    """Test reconfigure flow when encryption key is explicitly removed."""
    # Start with config that has encryption key
    mock_config_entry.add_to_hass(hass)

    result = await mock_config_entry.start_reconfigure_flow(hass)

    assert result["type"] is FlowResultType.FORM
    assert result["step_id"] == "reconfigure"

    # Explicitly set encryption key to None (empty string in UI)
    user_input = {
        CONF_HOST: "192.168.0.2",
        CONF_PORT: DEFAULT_PORT,
    }

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"], user_input
    )

    assert result["type"] is FlowResultType.ABORT
    assert result["reason"] == "reconfigure_successful"

    expected_data = {
        CONF_HOST: "192.168.0.2",
        CONF_PORT: DEFAULT_PORT,
        CONF_ENCRYPTION_KEY: None,
    }
    assert mock_config_entry.data == expected_data
