Migrate Vizio to has entity name (#96773)
parent
f72efa9618
commit
acca69f77a
|
@ -24,7 +24,7 @@ from homeassistant.const import (
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import entity_platform
|
from homeassistant.helpers import device_registry as dr, entity_platform
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
|
@ -131,6 +131,10 @@ async def async_setup_entry(
|
||||||
class VizioDevice(MediaPlayerEntity):
|
class VizioDevice(MediaPlayerEntity):
|
||||||
"""Media Player implementation which performs REST requests to device."""
|
"""Media Player implementation which performs REST requests to device."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
_attr_name = None
|
||||||
|
_received_device_info = False
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
|
@ -154,7 +158,7 @@ class VizioDevice(MediaPlayerEntity):
|
||||||
CONF_ADDITIONAL_CONFIGS, []
|
CONF_ADDITIONAL_CONFIGS, []
|
||||||
)
|
)
|
||||||
self._device = device
|
self._device = device
|
||||||
self._max_volume = float(self._device.get_max_volume())
|
self._max_volume = float(device.get_max_volume())
|
||||||
|
|
||||||
# Entity class attributes that will change with each update (we only include
|
# Entity class attributes that will change with each update (we only include
|
||||||
# the ones that are initialized differently from the defaults)
|
# the ones that are initialized differently from the defaults)
|
||||||
|
@ -162,10 +166,16 @@ class VizioDevice(MediaPlayerEntity):
|
||||||
self._attr_supported_features = SUPPORTED_COMMANDS[device_class]
|
self._attr_supported_features = SUPPORTED_COMMANDS[device_class]
|
||||||
|
|
||||||
# Entity class attributes that will not change
|
# Entity class attributes that will not change
|
||||||
self._attr_name = name
|
|
||||||
self._attr_icon = ICON[device_class]
|
self._attr_icon = ICON[device_class]
|
||||||
self._attr_unique_id = self._config_entry.unique_id
|
unique_id = config_entry.unique_id
|
||||||
|
assert unique_id
|
||||||
|
self._attr_unique_id = unique_id
|
||||||
self._attr_device_class = device_class
|
self._attr_device_class = device_class
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, unique_id)},
|
||||||
|
manufacturer="VIZIO",
|
||||||
|
name=name,
|
||||||
|
)
|
||||||
|
|
||||||
def _apps_list(self, apps: list[str]) -> list[str]:
|
def _apps_list(self, apps: list[str]) -> list[str]:
|
||||||
"""Return process apps list based on configured filters."""
|
"""Return process apps list based on configured filters."""
|
||||||
|
@ -195,15 +205,19 @@ class VizioDevice(MediaPlayerEntity):
|
||||||
)
|
)
|
||||||
self._attr_available = True
|
self._attr_available = True
|
||||||
|
|
||||||
if not self._attr_device_info:
|
if not self._received_device_info:
|
||||||
assert self._attr_unique_id
|
device_reg = dr.async_get(self.hass)
|
||||||
self._attr_device_info = DeviceInfo(
|
assert self._config_entry.unique_id
|
||||||
identifiers={(DOMAIN, self._attr_unique_id)},
|
device = device_reg.async_get_device(
|
||||||
manufacturer="VIZIO",
|
identifiers={(DOMAIN, self._config_entry.unique_id)}
|
||||||
|
)
|
||||||
|
if device:
|
||||||
|
device_reg.async_update_device(
|
||||||
|
device.id,
|
||||||
model=await self._device.get_model_name(log_api_exception=False),
|
model=await self._device.get_model_name(log_api_exception=False),
|
||||||
name=self._attr_name,
|
|
||||||
sw_version=await self._device.get_version(log_api_exception=False),
|
sw_version=await self._device.get_version(log_api_exception=False),
|
||||||
)
|
)
|
||||||
|
self._received_device_info = True
|
||||||
|
|
||||||
if not is_on:
|
if not is_on:
|
||||||
self._attr_state = MediaPlayerState.OFF
|
self._attr_state = MediaPlayerState.OFF
|
||||||
|
|
Loading…
Reference in New Issue