Files
home-assistant-core/homeassistant/components/roku/remote.py
T
Chris Talkington 3feb55a8e4 Make roku async (#35104)
* Update manifest.json

* work on roku async.

* Update config_flow.py

* Update __init__.py

* Update media_player.py

* Update media_player.py

* Update __init__.py

* Update __init__.py

* Update media_player.py

* Update media_player.py

* Update remote.py

* Update test_media_player.py

* Update test_media_player.py

* Update test_config_flow.py

* Update media_player.py

* Update remote.py

* Update config_flow.py

* Update test_media_player.py

* Update config_flow.py

* Update test_config_flow.py
2020-05-08 16:44:34 -05:00

53 lines
1.7 KiB
Python

"""Support for the Roku remote."""
from typing import Callable, List
from homeassistant.components.remote import ATTR_NUM_REPEATS, RemoteEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType
from . import RokuDataUpdateCoordinator, RokuEntity
from .const import DOMAIN
async def async_setup_entry(
hass: HomeAssistantType,
entry: ConfigEntry,
async_add_entities: Callable[[List, bool], None],
) -> bool:
"""Load Roku remote based on a config entry."""
coordinator = hass.data[DOMAIN][entry.entry_id]
unique_id = coordinator.data.info.serial_number
async_add_entities([RokuRemote(unique_id, 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,
name=coordinator.data.info.name,
coordinator=coordinator,
)
self._unique_id = unique_id
@property
def unique_id(self) -> str:
"""Return the unique ID for this entity."""
return self._unique_id
@property
def is_on(self) -> bool:
"""Return true if device is on."""
return not self.coordinator.data.state.standby
async def async_send_command(self, command: List, **kwargs) -> None:
"""Send a command to one device."""
num_repeats = kwargs[ATTR_NUM_REPEATS]
for _ in range(num_repeats):
for single_command in command:
await self.coordinator.roku.remote(single_command)