Add webostv payload option to command service (#36164)

* added optional argument to command service

* Fixed crash when optional argument is not provided

* Updated argument description

* fixed lint error

* Fix isort error

* switched to use dict for optional field instead of json string

* switched to use ATTR_PAYLOAD

* fixed test

* actually fixed test
This commit is contained in:
David Zhu authored and GitHub committed 2020-05-27 15:51:39 +02:00
1 parent c7e97f0cf8
commit 6f4829c390
5 files changed
+34 -7

No files matched your search

+20 -3
View File
@@ -12,6 +12,7 @@ from homeassistant.components.media_player.const import (
from homeassistant.components.webostv.const import (
ATTR_BUTTON,
ATTR_COMMAND,
ATTR_PAYLOAD,
DOMAIN,
SERVICE_BUTTON,
SERVICE_COMMAND,
@@ -102,8 +103,7 @@ async def test_button(hass, client):
async def test_command(hass, client):
"""Test generic button functionality."""
"""Test generic command functionality."""
await setup_webostv(hass)
data = {
@@ -113,4 +113,21 @@ async def test_command(hass, client):
await hass.services.async_call(DOMAIN, SERVICE_COMMAND, data)
await hass.async_block_till_done()
client.request.assert_called_with("test")
client.request.assert_called_with("test", payload=None)
async def test_command_with_optional_arg(hass, client):
"""Test generic command functionality."""
await setup_webostv(hass)
data = {
ATTR_ENTITY_ID: ENTITY_ID,
ATTR_COMMAND: "test",
ATTR_PAYLOAD: {"target": "https://www.google.com"},
}
await hass.services.async_call(DOMAIN, SERVICE_COMMAND, data)
await hass.async_block_till_done()
client.request.assert_called_with(
"test", payload={"target": "https://www.google.com"}
)