mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Velbus select platform testcases (#134394)
This commit is contained in:
parent
85c94e6403
commit
088b097a03
@ -4,7 +4,7 @@ from collections.abc import Generator
|
||||
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,
|
||||
|
60
tests/components/velbus/snapshots/test_select.ambr
Normal file
60
tests/components/velbus/snapshots/test_select.ambr
Normal file
@ -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
tests/components/velbus/test_select.py
Normal file
52
tests/components/velbus/test_select.py
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user