Add sonos snapshot test (#124036)

This commit is contained in:
Joost Lekkerkerker 2024-08-19 11:00:33 +02:00 committed by GitHub
parent bab930a456
commit 2577fb804b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 70 additions and 8 deletions

View File

@ -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',
})
# ---

View File

@ -5,6 +5,7 @@ from typing import Any
from unittest.mock import patch
import pytest
from syrupy import SnapshotAssertion
from homeassistant.components.media_player import (
ATTR_INPUT_SOURCE,
@ -44,10 +45,10 @@ from homeassistant.const import (
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,
@ -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(