Use snapshot_platform helper in anthemav media player tests (#181817)

This commit is contained in:
epenet
2026-09-10 08:47:22 +02:00
committed by GitHub
parent 83d4514233
commit 077ee887f0
2 changed files with 131 additions and 32 deletions
@@ -0,0 +1,107 @@
# serializer version: 1
# name: test_all_entities[media_player.anthem_av-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
None,
]),
'area_id': None,
'capabilities': dict({
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'media_player',
'entity_category': None,
'entity_id': 'media_player.anthem_av',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'object_id_base': None,
'options': dict({
}),
'original_device_class': <MediaPlayerDeviceClass.RECEIVER: 'receiver'>,
'original_icon': None,
'original_name': None,
'platform': 'anthemav',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': <MediaPlayerEntityFeature: 2444>,
'translation_key': None,
'unique_id': '00:00:00:00:00:01',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[media_player.anthem_av-state]
StateSnapshot({
'attributes': ReadOnlyDict({
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'receiver',
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Anthem AV',
<EntityStateAttribute.SUPPORTED_FEATURES: 'supported_features'>: <MediaPlayerEntityFeature: 2444>,
}),
'context': <ANY>,
'entity_id': 'media_player.anthem_av',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_all_entities[media_player.zone_2-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
None,
]),
'area_id': None,
'capabilities': dict({
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'media_player',
'entity_category': None,
'entity_id': 'media_player.zone_2',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'object_id_base': None,
'options': dict({
}),
'original_device_class': <MediaPlayerDeviceClass.RECEIVER: 'receiver'>,
'original_icon': None,
'original_name': None,
'platform': 'anthemav',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': <MediaPlayerEntityFeature: 2444>,
'translation_key': None,
'unique_id': '00:00:00:00:00:01_2',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[media_player.zone_2-state]
StateSnapshot({
'attributes': ReadOnlyDict({
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'receiver',
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Zone 2',
<EntityStateAttribute.SUPPORTED_FEATURES: 'supported_features'>: <MediaPlayerEntityFeature: 2444>,
}),
'context': <ANY>,
'entity_id': 'media_player.zone_2',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
+24 -32
View File
@@ -1,44 +1,30 @@
"""Test the Anthem A/V Receivers config flow."""
"""Test the Anthem A/V Receivers media player."""
from collections.abc import Callable
from unittest.mock import AsyncMock
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.media_player import (
ATTR_APP_NAME,
ATTR_INPUT_SOURCE,
ATTR_INPUT_SOURCE_LIST,
ATTR_MEDIA_TITLE,
ATTR_MEDIA_VOLUME_LEVEL,
ATTR_MEDIA_VOLUME_MUTED,
MediaPlayerEntityCapabilityAttribute,
MediaPlayerEntityStateAttribute,
)
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.const import STATE_ON
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry
from tests.common import MockConfigEntry, snapshot_platform
@pytest.mark.parametrize(
("entity_id", "entity_name"),
[
("media_player.anthem_av", "Anthem AV"),
("media_player.zone_2", "Zone 2"),
],
)
async def test_zones_loaded(
async def test_all_entities(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
entity_id: str,
entity_name: str,
snapshot: SnapshotAssertion,
) -> None:
"""Test zones are loaded."""
"""Test all entities."""
states = hass.states.get(entity_id)
assert states
assert states.state == STATE_OFF
assert states.name == entity_name
await snapshot_platform(hass, entity_registry, snapshot, init_integration.entry_id)
async def test_update_states_zone1(
@@ -64,9 +50,15 @@ async def test_update_states_zone1(
states = hass.states.get("media_player.anthem_av")
assert states
assert states.state == STATE_ON
assert states.attributes[ATTR_MEDIA_VOLUME_LEVEL] == 42
assert states.attributes[ATTR_MEDIA_VOLUME_MUTED] is True
assert states.attributes[ATTR_INPUT_SOURCE] == "TEST INPUT"
assert states.attributes[ATTR_MEDIA_TITLE] == "TEST INPUT"
assert states.attributes[ATTR_APP_NAME] == "2.0 PCM"
assert states.attributes[ATTR_INPUT_SOURCE_LIST] == ["TEST INPUT", "INPUT 2"]
assert states.attributes[MediaPlayerEntityStateAttribute.MEDIA_VOLUME_LEVEL] == 42
assert states.attributes[MediaPlayerEntityStateAttribute.MEDIA_VOLUME_MUTED] is True
assert (
states.attributes[MediaPlayerEntityStateAttribute.INPUT_SOURCE] == "TEST INPUT"
)
assert (
states.attributes[MediaPlayerEntityStateAttribute.MEDIA_TITLE] == "TEST INPUT"
)
assert states.attributes[MediaPlayerEntityStateAttribute.APP_NAME] == "2.0 PCM"
assert states.attributes[
MediaPlayerEntityCapabilityAttribute.INPUT_SOURCE_LIST
] == ["TEST INPUT", "INPUT 2"]