Add Velbus Button tests (#134186)

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Maikel Punie 2024-12-29 11:55:52 +01:00 committed by GitHub
parent 1d69cf11a5
commit da96e2077b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 91 additions and 1 deletions

View File

@ -28,6 +28,7 @@ def mock_controller(mock_button: AsyncMock) -> Generator[AsyncMock]:
):
cont = controller.return_value
cont.get_all_binary_sensor.return_value = [mock_button]
cont.get_all_button.return_value = [mock_button]
yield controller
@ -47,7 +48,6 @@ def mock_button() -> AsyncMock:
return channel
# moddify this one to set the runtime_data correctly
@pytest.fixture(name="config_entry")
async def mock_config_entry(
hass: HomeAssistant,

View File

@ -0,0 +1,47 @@
# serializer version: 1
# name: test_entities[button.buttonon-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'button',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'button.buttonon',
'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': 'ButtonOn',
'platform': 'velbus',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': 'a1b2c3d4e5f6-1',
'unit_of_measurement': None,
})
# ---
# name: test_entities[button.buttonon-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'ButtonOn',
}),
'context': <ANY>,
'entity_id': 'button.buttonon',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---

View File

@ -0,0 +1,43 @@
"""Velbus button platform tests."""
from unittest.mock import AsyncMock, patch
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
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
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
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.BUTTON]):
await init_integration(hass, config_entry)
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_button_press(
hass: HomeAssistant,
mock_button: AsyncMock,
config_entry: MockConfigEntry,
) -> None:
"""Test button press."""
await init_integration(hass, config_entry)
await hass.services.async_call(
BUTTON_DOMAIN, SERVICE_PRESS, {ATTR_ENTITY_ID: "button.buttonon"}, blocking=True
)
mock_button.press.assert_called_once_with()