mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add disconnect/reconnect tests to Cambridge Audio (#131100)
This commit is contained in:
parent
0b7fbe1d17
commit
d2f862b7b9
@ -1,5 +1,9 @@
|
||||
"""Tests for the Cambridge Audio integration."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from aiostreammagic.models import CallbackType
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
@ -11,3 +15,11 @@ async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry)
|
||||
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def mock_state_update(
|
||||
client: AsyncMock, callback_type: CallbackType = CallbackType.STATE
|
||||
) -> None:
|
||||
"""Trigger a callback in the media player."""
|
||||
for callback in client.register_state_update_callbacks.call_args_list:
|
||||
await callback[0][0](client, callback_type)
|
||||
|
@ -1,8 +1,10 @@
|
||||
"""Tests for the Cambridge Audio integration."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
from aiostreammagic import StreamMagicError
|
||||
from aiostreammagic.models import CallbackType
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.cambridge_audio.const import DOMAIN
|
||||
@ -10,7 +12,7 @@ from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from . import setup_integration
|
||||
from . import mock_state_update, setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@ -43,3 +45,23 @@ async def test_device_info(
|
||||
)
|
||||
assert device_entry is not None
|
||||
assert device_entry == snapshot
|
||||
|
||||
|
||||
async def test_disconnect_reconnect_log(
|
||||
hass: HomeAssistant,
|
||||
snapshot: SnapshotAssertion,
|
||||
mock_stream_magic_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test device registry integration."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
mock_stream_magic_client.is_connected = Mock(return_value=False)
|
||||
await mock_state_update(mock_stream_magic_client, CallbackType.CONNECTION)
|
||||
assert "Disconnected from device at 192.168.20.218" in caplog.text
|
||||
|
||||
mock_stream_magic_client.is_connected = Mock(return_value=True)
|
||||
await mock_state_update(mock_stream_magic_client, CallbackType.CONNECTION)
|
||||
assert "Reconnected to device at 192.168.20.218" in caplog.text
|
||||
|
@ -7,7 +7,6 @@ from aiostreammagic import (
|
||||
ShuffleMode,
|
||||
TransportControl,
|
||||
)
|
||||
from aiostreammagic.models import CallbackType
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.media_player import (
|
||||
@ -49,18 +48,12 @@ from homeassistant.const import (
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
|
||||
from . import setup_integration
|
||||
from . import mock_state_update, setup_integration
|
||||
from .const import ENTITY_ID
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def mock_state_update(client: AsyncMock) -> None:
|
||||
"""Trigger a callback in the media player."""
|
||||
for callback in client.register_state_update_callbacks.call_args_list:
|
||||
await callback[0][0](client, CallbackType.STATE)
|
||||
|
||||
|
||||
async def test_entity_supported_features(
|
||||
hass: HomeAssistant,
|
||||
mock_stream_magic_client: AsyncMock,
|
||||
|
Loading…
x
Reference in New Issue
Block a user