"""Tests for the Huawei LTE selects."""

from unittest.mock import MagicMock, patch

from huawei_lte_api.enums.net import LTEBandEnum, NetworkBandEnum, NetworkModeEnum

from homeassistant.components.huawei_lte.const import DOMAIN
from homeassistant.components.select import (
    DOMAIN as SELECT_DOMAIN,
    SERVICE_SELECT_OPTION,
)
from homeassistant.const import ATTR_ENTITY_ID, ATTR_OPTION, CONF_URL
from homeassistant.core import HomeAssistant

from . import magic_client

from tests.common import MockConfigEntry

SELECT_NETWORK_MODE = "select.test_router_preferred_network_mode"


async def test_set_net_mode(hass: HomeAssistant) -> None:
    """Test setting network mode."""
    huawei_lte = MockConfigEntry(
        domain=DOMAIN, data={CONF_URL: "http://huawei-lte.example.com"}
    )
    huawei_lte.add_to_hass(hass)
    client = magic_client()
    with (
        patch("homeassistant.components.huawei_lte.Connection", MagicMock()),
        patch("homeassistant.components.huawei_lte.Client", return_value=client),
    ):
        await hass.config_entries.async_setup(huawei_lte.entry_id)
    await hass.async_block_till_done()

    await hass.services.async_call(
        SELECT_DOMAIN,
        SERVICE_SELECT_OPTION,
        {
            ATTR_ENTITY_ID: SELECT_NETWORK_MODE,
            ATTR_OPTION: NetworkModeEnum.MODE_4G_3G_AUTO.value,
        },
        blocking=True,
    )
    await hass.async_block_till_done()
    client.net.set_net_mode.assert_called_once()
    client.net.set_net_mode.assert_called_with(
        LTEBandEnum.ALL, NetworkBandEnum.ALL, NetworkModeEnum.MODE_4G_3G_AUTO.value
    )
