From 077ee887f07217aeb7a663875144dda96619bad0 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 10 Sep 2026 08:47:22 +0200 Subject: [PATCH] Use snapshot_platform helper in anthemav media player tests (#181817) --- .../anthemav/snapshots/test_media_player.ambr | 107 ++++++++++++++++++ .../components/anthemav/test_media_player.py | 56 ++++----- 2 files changed, 131 insertions(+), 32 deletions(-) create mode 100644 tests/components/anthemav/snapshots/test_media_player.ambr diff --git a/tests/components/anthemav/snapshots/test_media_player.ambr b/tests/components/anthemav/snapshots/test_media_player.ambr new file mode 100644 index 000000000000..5d52b23efc6c --- /dev/null +++ b/tests/components/anthemav/snapshots/test_media_player.ambr @@ -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': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + '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': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': None, + 'platform': 'anthemav', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': , + '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({ + : 'receiver', + : 'Anthem AV', + : , + }), + 'context': , + 'entity_id': 'media_player.anthem_av', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'off', + }) +# --- +# name: test_all_entities[media_player.zone_2-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + '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': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': None, + 'platform': 'anthemav', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': , + '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({ + : 'receiver', + : 'Zone 2', + : , + }), + 'context': , + 'entity_id': 'media_player.zone_2', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'off', + }) +# --- diff --git a/tests/components/anthemav/test_media_player.py b/tests/components/anthemav/test_media_player.py index a9a945c86a10..c5c79f971ab8 100644 --- a/tests/components/anthemav/test_media_player.py +++ b/tests/components/anthemav/test_media_player.py @@ -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"]