From 647eb9650de54bc437481134960c492e00a72a68 Mon Sep 17 00:00:00 2001 From: Artem Draft Date: Wed, 24 Aug 2022 23:50:07 +0300 Subject: [PATCH] Add remote learn command to BraviaTV (#76655) * add bravia remote learn * unwrap --- homeassistant/components/braviatv/coordinator.py | 14 ++++++++++++++ homeassistant/components/braviatv/remote.py | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/homeassistant/components/braviatv/coordinator.py b/homeassistant/components/braviatv/coordinator.py index b5d91263b34..bb6bf59f681 100644 --- a/homeassistant/components/braviatv/coordinator.py +++ b/homeassistant/components/braviatv/coordinator.py @@ -10,6 +10,7 @@ from typing import Any, Final, TypeVar from pybravia import BraviaTV, BraviaTVError from typing_extensions import Concatenate, ParamSpec +from homeassistant.components import persistent_notification from homeassistant.components.media_player.const import ( MEDIA_TYPE_APP, MEDIA_TYPE_CHANNEL, @@ -256,3 +257,16 @@ class BraviaTVCoordinator(DataUpdateCoordinator[None]): for _ in range(repeats): for cmd in command: await self.client.send_command(cmd) + + @catch_braviatv_errors + async def async_learn_command(self, entity_id: str) -> None: + """Display a list of available commands in a persistent notification.""" + commands = await self.client.get_command_list() + codes = ", ".join(commands.keys()) + title = "Bravia TV" + message = f"**List of available commands for `{entity_id}`**:\n\n{codes}" + persistent_notification.async_create( + self.hass, + title=title, + message=message, + ) diff --git a/homeassistant/components/braviatv/remote.py b/homeassistant/components/braviatv/remote.py index f45b2d74004..411b459fced 100644 --- a/homeassistant/components/braviatv/remote.py +++ b/homeassistant/components/braviatv/remote.py @@ -47,3 +47,7 @@ class BraviaTVRemote(BraviaTVEntity, RemoteEntity): """Send a command to device.""" repeats = kwargs[ATTR_NUM_REPEATS] await self.coordinator.async_send_command(command, repeats) + + async def async_learn_command(self, **kwargs: Any) -> None: + """Learn commands from the device.""" + await self.coordinator.async_learn_command(self.entity_id)