Skip to content

Commit

Permalink
Velbus select platform testcases (home-assistant#134394)
Browse files Browse the repository at this point in the history
  • Loading branch information
cereal2nd authored Jan 1, 2025
1 parent 85c94e6 commit 088b097
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/components/velbus/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
Expand All @@ -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


Expand Down Expand Up @@ -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,
Expand Down
60 changes: 60 additions & 0 deletions tests/components/velbus/snapshots/test_select.ambr
Original file line number Diff line number Diff line change
@@ -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': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'select',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'select.select',
'has_entity_name': False,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'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': <ANY>,
'entity_id': 'select.select',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'winter',
})
# ---
52 changes: 52 additions & 0 deletions tests/components/velbus/test_select.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 088b097

Please sign in to comment.