Improve RemoteEntity class (#40605)

This commit is contained in:
Felipe Martins Diel authored and GitHub committed 2020-10-18 08:59:36 -05:00
1 parent 1355d285e8
commit d96a1744f0
4 files changed
+91

No files matched your search

@@ -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"
@@ -46,6 +47,7 @@ MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
SERVICE_SEND_COMMAND = "send_command"
SERVICE_LEARN_COMMAND = "learn_command"
SERVICE_DELETE_COMMAND = "delete_command"
SERVICE_SYNC = "sync"
DEFAULT_NUM_REPEATS = 1
@@ -53,6 +55,7 @@ DEFAULT_DELAY_SECS = 0.4
DEFAULT_HOLD_SECS = 0
SUPPORT_LEARN_COMMAND = 1
SUPPORT_DELETE_COMMAND = 2
REMOTE_SERVICE_ACTIVITY_SCHEMA = make_entity_service_schema(
{vol.Optional(ATTR_ACTIVITY): cv.string}
@@ -103,12 +106,22 @@ 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,
},
"async_learn_command",
)
component.async_register_entity_service(
SERVICE_DELETE_COMMAND,
{
vol.Required(ATTR_COMMAND): vol.All(cv.ensure_list, [cv.string]),
vol.Optional(ATTR_DEVICE): cv.string,
},
"async_delete_command",
)
return True
@@ -150,6 +163,17 @@ class RemoteEntity(ToggleEntity):
assert self.hass is not None
await self.hass.async_add_executor_job(ft.partial(self.learn_command, **kwargs))
def delete_command(self, **kwargs: Any) -> None:
"""Delete commands from the database."""
raise NotImplementedError()
async def async_delete_command(self, **kwargs: Any) -> None:
"""Delete commands from the database."""
assert self.hass is not None
await self.hass.async_add_executor_job(
ft.partial(self.delete_command, **kwargs)
)
class RemoteDevice(RemoteEntity):
"""Representation of a remote (for backwards compatibility)."""
@@ -58,9 +58,25 @@ 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"
timeout:
description: Timeout, in seconds, for the command to be learned.
example: "30"
delete_command:
description: Deletes a command or a list of commands from the database.
fields:
entity_id:
description: Name(s) of the remote entities holding the database.
example: "remote.bedroom"
device:
description: Name of the device from which commands will be deleted.
example: "television"
command:
description: A single command or a list of commands to delete.
example: "Mute"