Migrate Samsung TV to has entity name (#96751)

* Migrate Samsung TV to has entity name

* Fix test

* Fix tests

---------

Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
This commit is contained in:
Joost Lekkerkerker 2023-10-06 13:54:21 +02:00 committed by GitHub
parent d5f07ef45f
commit 835982ebe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 8 deletions

View File

@ -1,8 +1,6 @@
"""Base SamsungTV Entity.""" """Base SamsungTV Entity."""
from __future__ import annotations from __future__ import annotations
from typing import cast
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_MAC, CONF_MODEL, CONF_NAME from homeassistant.const import CONF_MAC, CONF_MODEL, CONF_NAME
from homeassistant.helpers import device_registry as dr from homeassistant.helpers import device_registry as dr
@ -16,17 +14,16 @@ from .const import CONF_MANUFACTURER, DOMAIN
class SamsungTVEntity(Entity): class SamsungTVEntity(Entity):
"""Defines a base SamsungTV entity.""" """Defines a base SamsungTV entity."""
_attr_has_entity_name = True
def __init__(self, *, bridge: SamsungTVBridge, config_entry: ConfigEntry) -> None: def __init__(self, *, bridge: SamsungTVBridge, config_entry: ConfigEntry) -> None:
"""Initialize the SamsungTV entity.""" """Initialize the SamsungTV entity."""
self._bridge = bridge self._bridge = bridge
self._mac = config_entry.data.get(CONF_MAC) self._mac = config_entry.data.get(CONF_MAC)
self._attr_name = config_entry.data.get(CONF_NAME)
# Fallback for legacy models that doesn't have a API to retrieve MAC or SerialNumber # Fallback for legacy models that doesn't have a API to retrieve MAC or SerialNumber
self._attr_unique_id = config_entry.unique_id or config_entry.entry_id self._attr_unique_id = config_entry.unique_id or config_entry.entry_id
self._attr_device_info = DeviceInfo( self._attr_device_info = DeviceInfo(
# Instead of setting the device name to the entity name, samsungtv name=config_entry.data.get(CONF_NAME),
# should be updated to set has_entity_name = True
name=cast(str | None, self.name),
manufacturer=config_entry.data.get(CONF_MANUFACTURER), manufacturer=config_entry.data.get(CONF_MANUFACTURER),
model=config_entry.data.get(CONF_MODEL), model=config_entry.data.get(CONF_MODEL),
) )

View File

@ -72,6 +72,7 @@ class SamsungTVDevice(SamsungTVEntity, MediaPlayerEntity):
"""Representation of a Samsung TV.""" """Representation of a Samsung TV."""
_attr_source_list: list[str] _attr_source_list: list[str]
_attr_name = None
_attr_device_class = MediaPlayerDeviceClass.TV _attr_device_class = MediaPlayerDeviceClass.TV
def __init__( def __init__(

View File

@ -24,6 +24,7 @@ async def async_setup_entry(
class SamsungTVRemote(SamsungTVEntity, RemoteEntity): class SamsungTVRemote(SamsungTVEntity, RemoteEntity):
"""Device that sends commands to a SamsungTV.""" """Device that sends commands to a SamsungTV."""
_attr_name = None
_attr_should_poll = False _attr_should_poll = False
async def async_turn_off(self, **kwargs: Any) -> None: async def async_turn_off(self, **kwargs: Any) -> None:

View File

@ -36,7 +36,7 @@
'domain': 'media_player', 'domain': 'media_player',
'entity_category': None, 'entity_category': None,
'entity_id': 'media_player.any', 'entity_id': 'media_player.any',
'has_entity_name': False, 'has_entity_name': True,
'hidden_by': None, 'hidden_by': None,
'icon': None, 'icon': None,
'id': <ANY>, 'id': <ANY>,
@ -45,7 +45,7 @@
}), }),
'original_device_class': <MediaPlayerDeviceClass.TV: 'tv'>, 'original_device_class': <MediaPlayerDeviceClass.TV: 'tv'>,
'original_icon': None, 'original_icon': None,
'original_name': 'any', 'original_name': None,
'platform': 'samsungtv', 'platform': 'samsungtv',
'supported_features': <MediaPlayerEntityFeature: 20413>, 'supported_features': <MediaPlayerEntityFeature: 20413>,
'translation_key': None, 'translation_key': None,