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

+27
View File
@@ -7,11 +7,13 @@ from homeassistant.components.remote import (
ATTR_ACTIVITY,
ATTR_ALTERNATIVE,
ATTR_COMMAND,
ATTR_COMMAND_TYPE,
ATTR_DELAY_SECS,
ATTR_DEVICE,
ATTR_NUM_REPEATS,
ATTR_TIMEOUT,
DOMAIN,
SERVICE_DELETE_COMMAND,
SERVICE_LEARN_COMMAND,
SERVICE_SEND_COMMAND,
)
@@ -81,6 +83,7 @@ def learn_command(
device=None,
command=None,
alternative=None,
command_type=None,
timeout=None,
):
"""Learn a command from a device."""
@@ -94,6 +97,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
@@ -101,3 +107,24 @@ def learn_command(
data[ATTR_TIMEOUT] = timeout
hass.services.call(DOMAIN, SERVICE_LEARN_COMMAND, data)
@bind_hass
def delete_command(
hass,
entity_id=ENTITY_MATCH_ALL,
device=None,
command=None,
):
"""Delete commands from the database."""
data = {}
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
if device:
data[ATTR_DEVICE] = device
if command:
data[ATTR_COMMAND] = command
hass.services.call(DOMAIN, SERVICE_DELETE_COMMAND, data)
+24
View File
@@ -19,6 +19,7 @@ from tests.components.remote import common
TEST_PLATFORM = {remote.DOMAIN: {CONF_PLATFORM: "test"}}
SERVICE_SEND_COMMAND = "send_command"
SERVICE_LEARN_COMMAND = "learn_command"
SERVICE_DELETE_COMMAND = "delete_command"
class TestRemote(unittest.TestCase):
@@ -101,6 +102,7 @@ class TestRemote(unittest.TestCase):
entity_id="entity_id_val",
device="test_device",
command=["test_command"],
command_type="rf",
alternative=True,
timeout=20,
)
@@ -114,6 +116,28 @@ class TestRemote(unittest.TestCase):
assert call.service == SERVICE_LEARN_COMMAND
assert call.data[ATTR_ENTITY_ID] == "entity_id_val"
def test_delete_command(self):
"""Test delete_command."""
delete_command_calls = mock_service(
self.hass, remote.DOMAIN, SERVICE_DELETE_COMMAND
)
common.delete_command(
self.hass,
entity_id="entity_id_val",
device="test_device",
command=["test_command"],
)
self.hass.block_till_done()
assert len(delete_command_calls) == 1
call = delete_command_calls[-1]
assert call.domain == remote.DOMAIN
assert call.service == SERVICE_DELETE_COMMAND
assert call.data[ATTR_ENTITY_ID] == "entity_id_val"
def test_deprecated_base_class(caplog):
"""Test deprecated base class."""