Support learning different command types with remote (#39670)
This commit is contained in:
parent
5ebce075a1
commit
c6a48d3b61
4 changed files with 11 additions and 0 deletions
|
@ -30,6 +30,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTR_ACTIVITY = "activity"
|
ATTR_ACTIVITY = "activity"
|
||||||
ATTR_COMMAND = "command"
|
ATTR_COMMAND = "command"
|
||||||
|
ATTR_COMMAND_TYPE = "command_type"
|
||||||
ATTR_DEVICE = "device"
|
ATTR_DEVICE = "device"
|
||||||
ATTR_NUM_REPEATS = "num_repeats"
|
ATTR_NUM_REPEATS = "num_repeats"
|
||||||
ATTR_DELAY_SECS = "delay_secs"
|
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_DEVICE): cv.string,
|
||||||
vol.Optional(ATTR_COMMAND): vol.All(cv.ensure_list, [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_ALTERNATIVE): cv.boolean,
|
||||||
vol.Optional(ATTR_TIMEOUT): cv.positive_int,
|
vol.Optional(ATTR_TIMEOUT): cv.positive_int,
|
||||||
},
|
},
|
||||||
|
|
|
@ -58,6 +58,9 @@ learn_command:
|
||||||
command:
|
command:
|
||||||
description: A single command or a list of commands to learn.
|
description: A single command or a list of commands to learn.
|
||||||
example: "Turn on"
|
example: "Turn on"
|
||||||
|
command_type:
|
||||||
|
description: The type of command to be learned.
|
||||||
|
example: "rf"
|
||||||
alternative:
|
alternative:
|
||||||
description: If code must be stored as alternative (useful for discrete remotes).
|
description: If code must be stored as alternative (useful for discrete remotes).
|
||||||
example: "True"
|
example: "True"
|
||||||
|
|
|
@ -7,6 +7,7 @@ from homeassistant.components.remote import (
|
||||||
ATTR_ACTIVITY,
|
ATTR_ACTIVITY,
|
||||||
ATTR_ALTERNATIVE,
|
ATTR_ALTERNATIVE,
|
||||||
ATTR_COMMAND,
|
ATTR_COMMAND,
|
||||||
|
ATTR_COMMAND_TYPE,
|
||||||
ATTR_DELAY_SECS,
|
ATTR_DELAY_SECS,
|
||||||
ATTR_DEVICE,
|
ATTR_DEVICE,
|
||||||
ATTR_NUM_REPEATS,
|
ATTR_NUM_REPEATS,
|
||||||
|
@ -81,6 +82,7 @@ def learn_command(
|
||||||
device=None,
|
device=None,
|
||||||
command=None,
|
command=None,
|
||||||
alternative=None,
|
alternative=None,
|
||||||
|
command_type=None,
|
||||||
timeout=None,
|
timeout=None,
|
||||||
):
|
):
|
||||||
"""Learn a command from a device."""
|
"""Learn a command from a device."""
|
||||||
|
@ -94,6 +96,9 @@ def learn_command(
|
||||||
if command:
|
if command:
|
||||||
data[ATTR_COMMAND] = command
|
data[ATTR_COMMAND] = command
|
||||||
|
|
||||||
|
if command_type:
|
||||||
|
data[ATTR_COMMAND_TYPE] = command_type
|
||||||
|
|
||||||
if alternative:
|
if alternative:
|
||||||
data[ATTR_ALTERNATIVE] = alternative
|
data[ATTR_ALTERNATIVE] = alternative
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,7 @@ class TestRemote(unittest.TestCase):
|
||||||
entity_id="entity_id_val",
|
entity_id="entity_id_val",
|
||||||
device="test_device",
|
device="test_device",
|
||||||
command=["test_command"],
|
command=["test_command"],
|
||||||
|
command_type="rf",
|
||||||
alternative=True,
|
alternative=True,
|
||||||
timeout=20,
|
timeout=20,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue