From 355ef4eac85c0db2eddca0e83739471782089774 Mon Sep 17 00:00:00 2001 From: Thijs W Date: Thu, 10 Aug 2023 10:19:27 +0200 Subject: [PATCH] Add unique_id to frontier_silicon media_player entity (#97955) --- .../frontier_silicon/media_player.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/frontier_silicon/media_player.py b/homeassistant/components/frontier_silicon/media_player.py index 62df3a12c2b..9e4db6fc3ca 100644 --- a/homeassistant/components/frontier_silicon/media_player.py +++ b/homeassistant/components/frontier_silicon/media_player.py @@ -39,7 +39,16 @@ async def async_setup_entry( afsapi: AFSAPI = hass.data[DOMAIN][config_entry.entry_id] - async_add_entities([AFSAPIDevice(config_entry.title, afsapi)], True) + async_add_entities( + [ + AFSAPIDevice( + config_entry.unique_id or config_entry.entry_id, + config_entry.title, + afsapi, + ) + ], + True, + ) class AFSAPIDevice(MediaPlayerEntity): @@ -67,15 +76,15 @@ class AFSAPIDevice(MediaPlayerEntity): | MediaPlayerEntityFeature.BROWSE_MEDIA ) - def __init__(self, name: str | None, afsapi: AFSAPI) -> None: + def __init__(self, unique_id: str, name: str | None, afsapi: AFSAPI) -> None: """Initialize the Frontier Silicon API device.""" self.fs_device = afsapi self._attr_device_info = DeviceInfo( - identifiers={(DOMAIN, afsapi.webfsapi_endpoint)}, + identifiers={(DOMAIN, unique_id)}, name=name, ) - + self._attr_unique_id = f"{unique_id}_media_player" self._max_volume: int | None = None self.__modes_by_label: dict[str, str] | None = None @@ -114,8 +123,6 @@ class AFSAPIDevice(MediaPlayerEntity): ) self._attr_available = True - if not self._attr_name: - self._attr_name = await afsapi.get_friendly_name() if not self._attr_source_list: self.__modes_by_label = {