diff --git a/tests/components/velbus/conftest.py b/tests/components/velbus/conftest.py index 1007b435212e2..0413a2d1af764 100644 --- a/tests/components/velbus/conftest.py +++ b/tests/components/velbus/conftest.py @@ -4,7 +4,7 @@ from unittest.mock import AsyncMock, MagicMock, patch import pytest -from velbusaio.channels import Button, Relay, Temperature +from velbusaio.channels import Button, Relay, SelectedProgram, Temperature from homeassistant.components.velbus import VelbusConfigEntry from homeassistant.components.velbus.const import DOMAIN @@ -21,6 +21,7 @@ def mock_controller( mock_button: AsyncMock, mock_relay: AsyncMock, mock_temperature: AsyncMock, + mock_select: AsyncMock, ) -> Generator[AsyncMock]: """Mock a successful velbus controller.""" with ( @@ -35,6 +36,7 @@ def mock_controller( cont.get_all_button.return_value = [mock_button] cont.get_all_switch.return_value = [mock_relay] cont.get_all_climate.return_value = [mock_temperature] + cont.get_all_select.return_value = [mock_select] yield controller @@ -95,6 +97,23 @@ def mock_relay() -> AsyncMock: return channel +@pytest.fixture +def mock_select() -> AsyncMock: + """Mock a successful velbus channel.""" + channel = AsyncMock(spec=SelectedProgram) + channel.get_categories.return_value = ["select"] + channel.get_name.return_value = "select" + channel.get_module_address.return_value = 55 + channel.get_channel_number.return_value = 33 + channel.get_module_type_name.return_value = "VMB4RYNO" + channel.get_full_name.return_value = "Full module name" + channel.get_module_sw_version.return_value = "1.1.1" + channel.get_module_serial.return_value = "qwerty1234567" + channel.get_options.return_value = ["none", "summer", "winter", "holiday"] + channel.get_selected_program.return_value = "winter" + return channel + + @pytest.fixture(name="config_entry") async def mock_config_entry( hass: HomeAssistant, diff --git a/tests/components/velbus/snapshots/test_select.ambr b/tests/components/velbus/snapshots/test_select.ambr new file mode 100644 index 0000000000000..5678c0ded5f9d --- /dev/null +++ b/tests/components/velbus/snapshots/test_select.ambr @@ -0,0 +1,60 @@ +# serializer version: 1 +# name: test_entities[select.select-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'options': list([ + 'none', + 'summer', + 'winter', + 'holiday', + ]), + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'select', + 'entity_category': , + 'entity_id': 'select.select', + 'has_entity_name': False, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'select', + 'platform': 'velbus', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'qwerty1234567-33-program_select', + 'unit_of_measurement': None, + }) +# --- +# name: test_entities[select.select-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'select', + 'options': list([ + 'none', + 'summer', + 'winter', + 'holiday', + ]), + }), + 'context': , + 'entity_id': 'select.select', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'winter', + }) +# --- diff --git a/tests/components/velbus/test_select.py b/tests/components/velbus/test_select.py new file mode 100644 index 0000000000000..64ac2c98009f4 --- /dev/null +++ b/tests/components/velbus/test_select.py @@ -0,0 +1,52 @@ +"""Velbus select platform tests.""" + +from unittest.mock import AsyncMock, patch + +import pytest +from syrupy.assertion import SnapshotAssertion + +from homeassistant.components.select import ( + ATTR_OPTION, + DOMAIN as SELECT_DOMAIN, + SERVICE_SELECT_OPTION, +) +from homeassistant.const import ATTR_ENTITY_ID, Platform +from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er + +from . import init_integration + +from tests.common import MockConfigEntry, snapshot_platform + + +async def test_entities( + hass: HomeAssistant, + snapshot: SnapshotAssertion, + config_entry: MockConfigEntry, + entity_registry: er.EntityRegistry, +) -> None: + """Test all entities.""" + with patch("homeassistant.components.velbus.PLATFORMS", [Platform.SELECT]): + await init_integration(hass, config_entry) + + await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id) + + +@pytest.mark.parametrize( + ("set_program"), [("none"), ("summer"), ("winter"), ("holiday")] +) +async def test_select_program( + hass: HomeAssistant, + mock_select: AsyncMock, + config_entry: MockConfigEntry, + set_program: str, +) -> None: + """Test program selection.""" + await init_integration(hass, config_entry) + await hass.services.async_call( + SELECT_DOMAIN, + SERVICE_SELECT_OPTION, + {ATTR_ENTITY_ID: "select.select", ATTR_OPTION: set_program}, + blocking=True, + ) + mock_select.set_selected_program.assert_called_once_with(set_program)