Skip to content

Commit

Permalink
Add sonos snapshot test (#124036)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Aug 19, 2024
1 parent bab930a commit 2577fb8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 8 deletions.
58 changes: 58 additions & 0 deletions tests/components/sonos/snapshots/test_media_player.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# serializer version: 1
# name: test_entity_basic[media_player.zone_a-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'media_player',
'entity_category': None,
'entity_id': 'media_player.zone_a',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <MediaPlayerDeviceClass.SPEAKER: 'speaker'>,
'original_icon': None,
'original_name': None,
'platform': 'sonos',
'previous_unique_id': None,
'supported_features': <MediaPlayerEntityFeature: 4127295>,
'translation_key': None,
'unique_id': 'RINCON_test',
'unit_of_measurement': None,
})
# ---
# name: test_entity_basic[media_player.zone_a-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'speaker',
'friendly_name': 'Zone A',
'group_members': list([
'media_player.zone_a',
]),
'is_volume_muted': False,
'media_content_type': <MediaType.MUSIC: 'music'>,
'repeat': <RepeatMode.OFF: 'off'>,
'shuffle': False,
'supported_features': <MediaPlayerEntityFeature: 4127295>,
'volume_level': 0.19,
}),
'context': <ANY>,
'entity_id': 'media_player.zone_a',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'idle',
})
# ---
20 changes: 12 additions & 8 deletions tests/components/sonos/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest.mock import patch

import pytest
from syrupy import SnapshotAssertion

from homeassistant.components.media_player import (
ATTR_INPUT_SOURCE,
Expand Down Expand Up @@ -44,10 +45,10 @@
SERVICE_VOLUME_DOWN,
SERVICE_VOLUME_SET,
SERVICE_VOLUME_UP,
STATE_IDLE,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.device_registry import (
CONNECTION_NETWORK_MAC,
CONNECTION_UPNP,
Expand Down Expand Up @@ -93,15 +94,18 @@ async def test_device_registry_not_portable(


async def test_entity_basic(
hass: HomeAssistant, async_autosetup_sonos, discover
hass: HomeAssistant,
async_autosetup_sonos,
discover,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test basic state and attributes."""
state = hass.states.get("media_player.zone_a")
assert state.state == STATE_IDLE
attributes = state.attributes
assert attributes["friendly_name"] == "Zone A"
assert attributes["is_volume_muted"] is False
assert attributes["volume_level"] == 0.19
entity_id = "media_player.zone_a"
entity_entry = entity_registry.async_get(entity_id)
assert entity_entry == snapshot(name=f"{entity_entry.entity_id}-entry")
state = hass.states.get(entity_entry.entity_id)
assert state == snapshot(name=f"{entity_entry.entity_id}-state")


@pytest.mark.parametrize(
Expand Down

0 comments on commit 2577fb8

Please sign in to comment.