mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
99 lines
2.9 KiB
Python
99 lines
2.9 KiB
Python
"""Test Tuya select platform."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from syrupy.assertion import SnapshotAssertion
|
|
from tuya_sharing import CustomerDevice
|
|
|
|
from homeassistant.components.select import (
|
|
ATTR_OPTION,
|
|
DOMAIN as SELECT_DOMAIN,
|
|
SERVICE_SELECT_OPTION,
|
|
)
|
|
from homeassistant.components.tuya import ManagerCompat
|
|
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import ServiceValidationError
|
|
from homeassistant.helpers import entity_registry as er
|
|
|
|
from . import initialize_entry
|
|
|
|
from tests.common import MockConfigEntry, snapshot_platform
|
|
|
|
|
|
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SELECT])
|
|
async def test_platform_setup_and_discovery(
|
|
hass: HomeAssistant,
|
|
mock_manager: ManagerCompat,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_devices: list[CustomerDevice],
|
|
entity_registry: er.EntityRegistry,
|
|
snapshot: SnapshotAssertion,
|
|
) -> None:
|
|
"""Test platform setup and discovery."""
|
|
await initialize_entry(hass, mock_manager, mock_config_entry, mock_devices)
|
|
|
|
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"mock_device_code",
|
|
["cl_zah67ekd"],
|
|
)
|
|
async def test_select_option(
|
|
hass: HomeAssistant,
|
|
mock_manager: ManagerCompat,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_device: CustomerDevice,
|
|
) -> None:
|
|
"""Test fan mode with windspeed."""
|
|
entity_id = "select.kitchen_blinds_motor_mode"
|
|
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
|
|
|
|
state = hass.states.get(entity_id)
|
|
assert state is not None, f"{entity_id} does not exist"
|
|
await hass.services.async_call(
|
|
SELECT_DOMAIN,
|
|
SERVICE_SELECT_OPTION,
|
|
{
|
|
ATTR_ENTITY_ID: entity_id,
|
|
ATTR_OPTION: "forward",
|
|
},
|
|
blocking=True,
|
|
)
|
|
mock_manager.send_commands.assert_called_once_with(
|
|
mock_device.id, [{"code": "control_back_mode", "value": "forward"}]
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"mock_device_code",
|
|
["cl_zah67ekd"],
|
|
)
|
|
async def test_select_invalid_option(
|
|
hass: HomeAssistant,
|
|
mock_manager: ManagerCompat,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_device: CustomerDevice,
|
|
) -> None:
|
|
"""Test fan mode with windspeed."""
|
|
entity_id = "select.kitchen_blinds_motor_mode"
|
|
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
|
|
|
|
state = hass.states.get(entity_id)
|
|
assert state is not None, f"{entity_id} does not exist"
|
|
with pytest.raises(ServiceValidationError) as exc:
|
|
await hass.services.async_call(
|
|
SELECT_DOMAIN,
|
|
SERVICE_SELECT_OPTION,
|
|
{
|
|
ATTR_ENTITY_ID: entity_id,
|
|
ATTR_OPTION: "hello",
|
|
},
|
|
blocking=True,
|
|
)
|
|
assert exc.value.translation_key == "not_valid_option"
|