Skip to content

Commit

Permalink
Restore remote support for IR buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 6, 2024
1 parent e0d662b commit 194a7bc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions custom_components/yandex_station/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"light",
"media_player",
"number",
"remote",
"select",
"switch",
"vacuum",
Expand Down
52 changes: 52 additions & 0 deletions custom_components/yandex_station/remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import asyncio
import logging

from homeassistant.components.remote import RemoteEntity

from .core.entity import YandexEntity
from .hass import hass_utils

_LOGGER = logging.getLogger(__name__)

INCLUDE_TYPES = ("devices.types.other",)


async def async_setup_entry(hass, entry, async_add_entities):
async_add_entities(
YandexOther(quasar, device, config)
for quasar, device, config in hass_utils.incluce_devices(hass, entry)
if device["type"] in INCLUDE_TYPES
)


# noinspection PyAbstractClass
class YandexOther(RemoteEntity, YandexEntity):
buttons: dict[str, str]

def internal_init(self, capabilities: dict, properties: dict):
self.buttons = {}
for capability in capabilities.values():
instance: str = capability["instance"]
if instance.isdecimal():
self.buttons[capability["name"]] = instance

async def async_send_command(
self,
command: list[str],
num_repeats: int = None,
delay_secs: float = None,
**kwargs,
) -> None:
if num_repeats:
command *= num_repeats

for i, cmd in enumerate(command):
if cmd not in self.buttons:
_LOGGER.warning(f"Неизвестная команда {cmd}")
continue

if delay_secs and i:
await asyncio.sleep(delay_secs)

payload = {self.buttons[cmd]: True}
await self.quasar.device_actions(self.device["id"], **payload)

0 comments on commit 194a7bc

Please sign in to comment.