Improve RemoteEntity class (#40605)
This commit is contained in:
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)."""
|
||||
|
||||
Reference in new issue
Block a user