From c29aebd60e9dc4e1bc76a3dda8c1e62776cff005 Mon Sep 17 00:00:00 2001 From: jasonjhofmann Date: Mon, 15 Jun 2026 23:11:25 -0700 Subject: [PATCH] Add network MAC connection to PlayStation 4 devices (#173681) Co-authored-by: Claude Opus 4.8 (1M context) --- homeassistant/components/ps4/media_player.py | 4 +++ .../ps4/snapshots/test_media_player.ambr | 36 +++++++++++++++++++ tests/components/ps4/test_media_player.py | 19 ++++++++++ 3 files changed, 59 insertions(+) create mode 100644 tests/components/ps4/snapshots/test_media_player.ambr diff --git a/homeassistant/components/ps4/media_player.py b/homeassistant/components/ps4/media_player.py index ea866aa3942..c12b26b9162 100644 --- a/homeassistant/components/ps4/media_player.py +++ b/homeassistant/components/ps4/media_player.py @@ -352,6 +352,8 @@ class PS4Device(MediaPlayerEntity): for device in d_registry.devices.get_devices_for_config_entry_id( self._entry_id ): + # Rebuilt from the existing device entry, which already carries + # the network MAC connection added by the live-status branch. self._attr_device_info = DeviceInfo( identifiers=device.identifiers, manufacturer=device.manufacturer, @@ -365,7 +367,9 @@ class PS4Device(MediaPlayerEntity): _sw_version = status["system-version"] _sw_version = _sw_version[1:4] sw_version = f"{_sw_version[0]}.{_sw_version[1:]}" + # status["host-id"] is the console's network MAC address. self._attr_device_info = DeviceInfo( + connections={(dr.CONNECTION_NETWORK_MAC, status["host-id"])}, identifiers={(DOMAIN, status["host-id"])}, manufacturer="Sony Interactive Entertainment Inc.", model="PlayStation 4", diff --git a/tests/components/ps4/snapshots/test_media_player.ambr b/tests/components/ps4/snapshots/test_media_player.ambr new file mode 100644 index 00000000000..c4a9da3f2d5 --- /dev/null +++ b/tests/components/ps4/snapshots/test_media_player.ambr @@ -0,0 +1,36 @@ +# serializer version: 1 +# name: test_device_registry + DeviceRegistryEntrySnapshot({ + 'area_id': None, + 'config_entries': , + 'config_entries_subentries': , + 'configuration_url': None, + 'connections': set({ + tuple( + 'mac', + 'a0:00:0a:0a:a0:00', + ), + }), + 'disabled_by': None, + 'entry_type': None, + 'hw_version': None, + 'id': , + 'identifiers': set({ + tuple( + 'ps4', + 'A0000A0AA000', + ), + }), + 'labels': set({ + }), + 'manufacturer': 'Sony Interactive Entertainment Inc.', + 'model': 'PlayStation 4', + 'model_id': None, + 'name': 'Fake PS4', + 'name_by_user': None, + 'primary_config_entry': , + 'serial_number': None, + 'sw_version': '9.87', + 'via_device_id': None, + }) +# --- diff --git a/tests/components/ps4/test_media_player.py b/tests/components/ps4/test_media_player.py index 5746a5fa7d3..c55771b8c4c 100644 --- a/tests/components/ps4/test_media_player.py +++ b/tests/components/ps4/test_media_player.py @@ -6,6 +6,7 @@ from unittest.mock import MagicMock, patch from pyps4_2ndscreen.credential import get_ddp_message from pyps4_2ndscreen.ddp import DEFAULT_UDP_PORT from pyps4_2ndscreen.media_art import TYPE_APP as PS_TYPE_APP +from syrupy.assertion import SnapshotAssertion from homeassistant.components import ps4 from homeassistant.components.media_player import ( @@ -323,6 +324,24 @@ async def test_device_info_is_set_from_status_correctly( assert mock_entry.identifiers == {(DOMAIN, MOCK_HOST_ID)} +async def test_device_registry( + hass: HomeAssistant, + patch_get_status: MagicMock, + device_registry: dr.DeviceRegistry, + snapshot: SnapshotAssertion, +) -> None: + """Test the device registry entry, including the network MAC connection.""" + patch_get_status.return_value = MOCK_STATUS_STANDBY + await setup_mock_component(hass) + + await hass.async_block_till_done() + + device_entry = device_registry.async_get_device( + identifiers={(DOMAIN, MOCK_HOST_ID)} + ) + assert device_entry == snapshot + + async def test_device_info_is_assummed( hass: HomeAssistant, device_registry: dr.DeviceRegistry,