Add apple tv remote delay command (#46301)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
David Dix 2021-02-12 13:58:01 +00:00 committed by GitHub
parent 479ff92acb
commit a8beae3c51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,14 @@
"""Remote control support for Apple TV.""" """Remote control support for Apple TV."""
import asyncio
import logging import logging
from homeassistant.components.remote import RemoteEntity from homeassistant.components.remote import (
ATTR_DELAY_SECS,
ATTR_NUM_REPEATS,
DEFAULT_DELAY_SECS,
RemoteEntity,
)
from homeassistant.const import CONF_NAME from homeassistant.const import CONF_NAME
from . import AppleTVEntity from . import AppleTVEntity
@ -43,12 +49,19 @@ class AppleTVRemote(AppleTVEntity, RemoteEntity):
async def async_send_command(self, command, **kwargs): async def async_send_command(self, command, **kwargs):
"""Send a command to one device.""" """Send a command to one device."""
num_repeats = kwargs[ATTR_NUM_REPEATS]
delay = kwargs.get(ATTR_DELAY_SECS, DEFAULT_DELAY_SECS)
if not self.is_on: if not self.is_on:
_LOGGER.error("Unable to send commands, not connected to %s", self._name) _LOGGER.error("Unable to send commands, not connected to %s", self._name)
return return
for single_command in command: for _ in range(num_repeats):
if not hasattr(self.atv.remote_control, single_command): for single_command in command:
continue attr_value = getattr(self.atv.remote_control, single_command, None)
if not attr_value:
raise ValueError("Command not found. Exiting sequence")
await getattr(self.atv.remote_control, single_command)() _LOGGER.info("Sending command %s", single_command)
await attr_value()
await asyncio.sleep(delay)