From c6a48d3b611fb0797b25cbf2152a2c93243def58 Mon Sep 17 00:00:00 2001 From: Felipe Martins Diel <41558831+felipediel@users.noreply.github.com> Date: Wed, 23 Sep 2020 00:09:19 -0300 Subject: [PATCH] Support learning different command types with remote (#39670) --- homeassistant/components/remote/__init__.py | 2 ++ homeassistant/components/remote/services.yaml | 3 +++ tests/components/remote/common.py | 5 +++++ tests/components/remote/test_init.py | 1 + 4 files changed, 11 insertions(+) diff --git a/homeassistant/components/remote/__init__.py b/homeassistant/components/remote/__init__.py index ca9de0bfb62..2b481925b0f 100644 --- a/homeassistant/components/remote/__init__.py +++ b/homeassistant/components/remote/__init__.py @@ -30,6 +30,7 @@ _LOGGER = logging.getLogger(__name__) ATTR_ACTIVITY = "activity" ATTR_COMMAND = "command" +ATTR_COMMAND_TYPE = "command_type" ATTR_DEVICE = "device" ATTR_NUM_REPEATS = "num_repeats" ATTR_DELAY_SECS = "delay_secs" @@ -103,6 +104,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: { vol.Optional(ATTR_DEVICE): cv.string, vol.Optional(ATTR_COMMAND): vol.All(cv.ensure_list, [cv.string]), + vol.Optional(ATTR_COMMAND_TYPE): cv.string, vol.Optional(ATTR_ALTERNATIVE): cv.boolean, vol.Optional(ATTR_TIMEOUT): cv.positive_int, }, diff --git a/homeassistant/components/remote/services.yaml b/homeassistant/components/remote/services.yaml index fc9d170726e..3244f018fbd 100644 --- a/homeassistant/components/remote/services.yaml +++ b/homeassistant/components/remote/services.yaml @@ -58,6 +58,9 @@ learn_command: command: description: A single command or a list of commands to learn. example: "Turn on" + command_type: + description: The type of command to be learned. + example: "rf" alternative: description: If code must be stored as alternative (useful for discrete remotes). example: "True" diff --git a/tests/components/remote/common.py b/tests/components/remote/common.py index 1f4a5268440..6560b7bf7f7 100644 --- a/tests/components/remote/common.py +++ b/tests/components/remote/common.py @@ -7,6 +7,7 @@ from homeassistant.components.remote import ( ATTR_ACTIVITY, ATTR_ALTERNATIVE, ATTR_COMMAND, + ATTR_COMMAND_TYPE, ATTR_DELAY_SECS, ATTR_DEVICE, ATTR_NUM_REPEATS, @@ -81,6 +82,7 @@ def learn_command( device=None, command=None, alternative=None, + command_type=None, timeout=None, ): """Learn a command from a device.""" @@ -94,6 +96,9 @@ def learn_command( if command: data[ATTR_COMMAND] = command + if command_type: + data[ATTR_COMMAND_TYPE] = command_type + if alternative: data[ATTR_ALTERNATIVE] = alternative diff --git a/tests/components/remote/test_init.py b/tests/components/remote/test_init.py index eb47d365f83..467187985db 100644 --- a/tests/components/remote/test_init.py +++ b/tests/components/remote/test_init.py @@ -101,6 +101,7 @@ class TestRemote(unittest.TestCase): entity_id="entity_id_val", device="test_device", command=["test_command"], + command_type="rf", alternative=True, timeout=20, )