From 914baaa2ba14acbc3fd2c3872d994f40857bffee Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Fri, 11 Aug 2023 04:10:46 +0200 Subject: [PATCH] Migrate DirecTV to has entity name (#98159) * Migrate DirecTV to has entity name * Migrate DirecTV to has entity name --- homeassistant/components/directv/entity.py | 18 ++++++------------ .../components/directv/media_player.py | 2 +- homeassistant/components/directv/remote.py | 2 +- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/directv/entity.py b/homeassistant/components/directv/entity.py index cd4017eb389..0da2cfcb9d6 100644 --- a/homeassistant/components/directv/entity.py +++ b/homeassistant/components/directv/entity.py @@ -1,8 +1,6 @@ """Base DirecTV Entity.""" from __future__ import annotations -from typing import cast - from directv import DIRECTV from homeassistant.helpers.device_registry import DeviceInfo @@ -14,23 +12,19 @@ from .const import DOMAIN class DIRECTVEntity(Entity): """Defines a base DirecTV entity.""" - def __init__(self, *, dtv: DIRECTV, address: str = "0") -> None: + _attr_has_entity_name = True + _attr_name = None + + def __init__(self, *, dtv: DIRECTV, name: str, address: str = "0") -> None: """Initialize the DirecTV entity.""" self._address = address self._device_id = address if address != "0" else dtv.device.info.receiver_id self._is_client = address != "0" self.dtv = dtv - - @property - def device_info(self) -> DeviceInfo: - """Return device information about this DirecTV receiver.""" - return DeviceInfo( + self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, self._device_id)}, manufacturer=self.dtv.device.info.brand, - # Instead of setting the device name to the entity name, directv - # should be updated to set has_entity_name = True, and set the entity - # name to None - name=cast(str | None, self.name), + name=name, sw_version=self.dtv.device.info.version, via_device=(DOMAIN, self.dtv.device.info.receiver_id), ) diff --git a/homeassistant/components/directv/media_player.py b/homeassistant/components/directv/media_player.py index 8c1570db159..63d086564ee 100644 --- a/homeassistant/components/directv/media_player.py +++ b/homeassistant/components/directv/media_player.py @@ -80,11 +80,11 @@ class DIRECTVMediaPlayer(DIRECTVEntity, MediaPlayerEntity): """Initialize DirecTV media player.""" super().__init__( dtv=dtv, + name=name, address=address, ) self._attr_unique_id = self._device_id - self._attr_name = name self._attr_device_class = MediaPlayerDeviceClass.RECEIVER self._attr_available = False diff --git a/homeassistant/components/directv/remote.py b/homeassistant/components/directv/remote.py index c8c84a7f0cc..d100abd3495 100644 --- a/homeassistant/components/directv/remote.py +++ b/homeassistant/components/directv/remote.py @@ -49,11 +49,11 @@ class DIRECTVRemote(DIRECTVEntity, RemoteEntity): """Initialize DirecTV remote.""" super().__init__( dtv=dtv, + name=name, address=address, ) self._attr_unique_id = self._device_id - self._attr_name = name self._attr_available = False self._attr_is_on = True