Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
1.9 KiB
Python
Raw Permalink Normal View History

2024-04-29 00:47:05 -07:00
"""Tests for the TotalConnect buttons."""
2025-08-10 13:26:43 -07:00
from unittest.mock import AsyncMock, patch
2024-04-29 00:47:05 -07:00
from syrupy.assertion import SnapshotAssertion
2024-04-29 00:47:05 -07:00
2025-08-10 13:26:43 -07:00
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
from homeassistant.const import ATTR_ENTITY_ID, Platform
2024-04-29 00:47:05 -07:00
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
2025-08-10 13:26:43 -07:00
from . import setup_integration
2024-04-29 00:47:05 -07:00
2025-08-10 13:26:43 -07:00
from tests.common import MockConfigEntry, snapshot_platform
2024-04-29 00:47:05 -07:00
async def test_entity_registry(
2025-08-10 13:26:43 -07:00
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_client: AsyncMock,
mock_config_entry: MockConfigEntry,
snapshot: SnapshotAssertion,
2024-04-29 00:47:05 -07:00
) -> None:
"""Test the button is registered in entity registry."""
2025-08-10 13:26:43 -07:00
with patch("homeassistant.components.totalconnect.PLATFORMS", [Platform.BUTTON]):
await setup_integration(hass, mock_config_entry)
2024-04-29 00:47:05 -07:00
2025-08-10 13:26:43 -07:00
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
2024-04-29 00:47:05 -07:00
2025-03-12 00:52:28 -07:00
async def test_bypass_button(
2025-08-10 13:26:43 -07:00
hass: HomeAssistant,
mock_client: AsyncMock,
mock_config_entry: MockConfigEntry,
mock_location: AsyncMock,
2025-03-12 00:52:28 -07:00
) -> None:
2024-04-29 00:47:05 -07:00
"""Test pushing a bypass button."""
2025-08-10 13:26:43 -07:00
await setup_integration(hass, mock_config_entry)
await hass.services.async_call(
BUTTON_DOMAIN,
SERVICE_PRESS,
{ATTR_ENTITY_ID: "button.security_bypass"},
blocking=True,
2024-04-29 00:47:05 -07:00
)
2025-08-10 13:26:43 -07:00
assert mock_location.zones[2].bypass.call_count == 1
async def test_clear_button(
hass: HomeAssistant,
mock_client: AsyncMock,
mock_config_entry: MockConfigEntry,
mock_location: AsyncMock,
) -> None:
"""Test pushing the clear bypass button."""
await setup_integration(hass, mock_config_entry)
await hass.services.async_call(
BUTTON_DOMAIN,
SERVICE_PRESS,
{ATTR_ENTITY_ID: "button.test_clear_bypass"},
blocking=True,
)
assert mock_location.clear_bypass.call_count == 1