mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Migrate roku to new entity naming (#74819)
* migrate roku to new entity naming * Update binary_sensor.py * Update sensor.py * Update test_binary_sensor.py * Update sensor.py * Update entity.py * Update media_player.py * Update remote.py * Update media_player.py * Update remote.py * Update entity.py * Update entity.py * Update entity.py * Update entity.py
This commit is contained in:
parent
e16bd1e471
commit
20432ccc76
@ -36,7 +36,7 @@ class RokuBinarySensorEntityDescription(
|
||||
BINARY_SENSORS: tuple[RokuBinarySensorEntityDescription, ...] = (
|
||||
RokuBinarySensorEntityDescription(
|
||||
key="headphones_connected",
|
||||
name="Headphones Connected",
|
||||
name="Headphones connected",
|
||||
icon="mdi:headphones",
|
||||
value_fn=lambda device: device.info.headphones_connected,
|
||||
),
|
||||
@ -49,14 +49,14 @@ BINARY_SENSORS: tuple[RokuBinarySensorEntityDescription, ...] = (
|
||||
),
|
||||
RokuBinarySensorEntityDescription(
|
||||
key="supports_ethernet",
|
||||
name="Supports Ethernet",
|
||||
name="Supports ethernet",
|
||||
icon="mdi:ethernet",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda device: device.info.ethernet_support,
|
||||
),
|
||||
RokuBinarySensorEntityDescription(
|
||||
key="supports_find_remote",
|
||||
name="Supports Find Remote",
|
||||
name="Supports find remote",
|
||||
icon="mdi:remote",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda device: device.info.supports_find_remote,
|
||||
|
@ -25,30 +25,32 @@ class RokuEntity(CoordinatorEntity[RokuDataUpdateCoordinator]):
|
||||
|
||||
if description is not None:
|
||||
self.entity_description = description
|
||||
self._attr_name = f"{coordinator.data.info.name} {description.name}"
|
||||
if device_id is not None:
|
||||
|
||||
if device_id is None:
|
||||
self._attr_name = f"{coordinator.data.info.name} {description.name}"
|
||||
|
||||
if device_id is not None:
|
||||
self._attr_has_entity_name = True
|
||||
|
||||
if description is not None:
|
||||
self._attr_unique_id = f"{device_id}_{description.key}"
|
||||
else:
|
||||
self._attr_unique_id = device_id
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo | None:
|
||||
"""Return device information about this Roku device."""
|
||||
if self._device_id is None:
|
||||
return None
|
||||
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._device_id)},
|
||||
connections={
|
||||
(CONNECTION_NETWORK_MAC, mac_address)
|
||||
for mac_address in (
|
||||
self.coordinator.data.info.wifi_mac,
|
||||
self.coordinator.data.info.ethernet_mac,
|
||||
)
|
||||
if mac_address is not None
|
||||
},
|
||||
name=self.coordinator.data.info.name,
|
||||
manufacturer=self.coordinator.data.info.brand,
|
||||
model=self.coordinator.data.info.model_name,
|
||||
hw_version=self.coordinator.data.info.model_number,
|
||||
sw_version=self.coordinator.data.info.version,
|
||||
suggested_area=self.coordinator.data.info.device_location,
|
||||
)
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, device_id)},
|
||||
connections={
|
||||
(CONNECTION_NETWORK_MAC, mac_address)
|
||||
for mac_address in (
|
||||
self.coordinator.data.info.wifi_mac,
|
||||
self.coordinator.data.info.ethernet_mac,
|
||||
)
|
||||
if mac_address is not None
|
||||
},
|
||||
name=self.coordinator.data.info.name,
|
||||
manufacturer=self.coordinator.data.info.brand,
|
||||
model=self.coordinator.data.info.model_name,
|
||||
hw_version=self.coordinator.data.info.model_number,
|
||||
sw_version=self.coordinator.data.info.version,
|
||||
suggested_area=self.coordinator.data.info.device_location,
|
||||
)
|
||||
|
@ -99,7 +99,15 @@ async def async_setup_entry(
|
||||
"""Set up the Roku config entry."""
|
||||
coordinator: RokuDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
unique_id = coordinator.data.info.serial_number
|
||||
async_add_entities([RokuMediaPlayer(unique_id, coordinator)], True)
|
||||
async_add_entities(
|
||||
[
|
||||
RokuMediaPlayer(
|
||||
device_id=unique_id,
|
||||
coordinator=coordinator,
|
||||
)
|
||||
],
|
||||
True,
|
||||
)
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
@ -127,18 +135,6 @@ class RokuMediaPlayer(RokuEntity, MediaPlayerEntity):
|
||||
| MediaPlayerEntityFeature.BROWSE_MEDIA
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self, unique_id: str | None, coordinator: RokuDataUpdateCoordinator
|
||||
) -> None:
|
||||
"""Initialize the Roku device."""
|
||||
super().__init__(
|
||||
coordinator=coordinator,
|
||||
device_id=unique_id,
|
||||
)
|
||||
|
||||
self._attr_name = coordinator.data.info.name
|
||||
self._attr_unique_id = unique_id
|
||||
|
||||
def _media_playback_trackable(self) -> bool:
|
||||
"""Detect if we have enough media data to track playback."""
|
||||
if self.coordinator.data.media is None or self.coordinator.data.media.live:
|
||||
|
@ -21,24 +21,22 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Load Roku remote based on a config entry."""
|
||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator: RokuDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
unique_id = coordinator.data.info.serial_number
|
||||
async_add_entities([RokuRemote(unique_id, coordinator)], True)
|
||||
async_add_entities(
|
||||
[
|
||||
RokuRemote(
|
||||
device_id=unique_id,
|
||||
coordinator=coordinator,
|
||||
)
|
||||
],
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class RokuRemote(RokuEntity, RemoteEntity):
|
||||
"""Device that sends commands to an Roku."""
|
||||
|
||||
def __init__(self, unique_id: str, coordinator: RokuDataUpdateCoordinator) -> None:
|
||||
"""Initialize the Roku device."""
|
||||
super().__init__(
|
||||
device_id=unique_id,
|
||||
coordinator=coordinator,
|
||||
)
|
||||
|
||||
self._attr_name = coordinator.data.info.name
|
||||
self._attr_unique_id = unique_id
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if device is on."""
|
||||
|
@ -29,7 +29,7 @@ async def test_roku_binary_sensors(
|
||||
assert entry.unique_id == f"{UPNP_SERIAL}_headphones_connected"
|
||||
assert entry.entity_category is None
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "My Roku 3 Headphones Connected"
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "My Roku 3 Headphones connected"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:headphones"
|
||||
assert ATTR_DEVICE_CLASS not in state.attributes
|
||||
|
||||
@ -51,7 +51,7 @@ async def test_roku_binary_sensors(
|
||||
assert entry.unique_id == f"{UPNP_SERIAL}_supports_ethernet"
|
||||
assert entry.entity_category == EntityCategory.DIAGNOSTIC
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "My Roku 3 Supports Ethernet"
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "My Roku 3 Supports ethernet"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:ethernet"
|
||||
assert ATTR_DEVICE_CLASS not in state.attributes
|
||||
|
||||
@ -62,7 +62,7 @@ async def test_roku_binary_sensors(
|
||||
assert entry.unique_id == f"{UPNP_SERIAL}_supports_find_remote"
|
||||
assert entry.entity_category == EntityCategory.DIAGNOSTIC
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "My Roku 3 Supports Find Remote"
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "My Roku 3 Supports find remote"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:remote"
|
||||
assert ATTR_DEVICE_CLASS not in state.attributes
|
||||
|
||||
@ -105,7 +105,7 @@ async def test_rokutv_binary_sensors(
|
||||
assert state.state == STATE_OFF
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME)
|
||||
== '58" Onn Roku TV Headphones Connected'
|
||||
== '58" Onn Roku TV Headphones connected'
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:headphones"
|
||||
assert ATTR_DEVICE_CLASS not in state.attributes
|
||||
@ -131,7 +131,7 @@ async def test_rokutv_binary_sensors(
|
||||
assert entry.entity_category == EntityCategory.DIAGNOSTIC
|
||||
assert state.state == STATE_ON
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME) == '58" Onn Roku TV Supports Ethernet'
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME) == '58" Onn Roku TV Supports ethernet'
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:ethernet"
|
||||
assert ATTR_DEVICE_CLASS not in state.attributes
|
||||
@ -147,7 +147,7 @@ async def test_rokutv_binary_sensors(
|
||||
assert state.state == STATE_ON
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME)
|
||||
== '58" Onn Roku TV Supports Find Remote'
|
||||
== '58" Onn Roku TV Supports find remote'
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:remote"
|
||||
assert ATTR_DEVICE_CLASS not in state.attributes
|
||||
|
Loading…
x
Reference in New Issue
Block a user