mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Update directv remote platform tests service calls (#33793)
* Update test_remote.py * Update test_remote.py
This commit is contained in:
parent
078ce6766e
commit
d54ee77375
@ -1,22 +1,12 @@
|
|||||||
"""The tests for the DirecTV remote platform."""
|
"""The tests for the DirecTV remote platform."""
|
||||||
from typing import Any, List
|
|
||||||
|
|
||||||
from asynctest import patch
|
from asynctest import patch
|
||||||
|
|
||||||
from homeassistant.components.remote import (
|
from homeassistant.components.remote import (
|
||||||
ATTR_COMMAND,
|
ATTR_COMMAND,
|
||||||
ATTR_DELAY_SECS,
|
|
||||||
ATTR_DEVICE,
|
|
||||||
ATTR_NUM_REPEATS,
|
|
||||||
DOMAIN as REMOTE_DOMAIN,
|
DOMAIN as REMOTE_DOMAIN,
|
||||||
SERVICE_SEND_COMMAND,
|
SERVICE_SEND_COMMAND,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||||
ATTR_ENTITY_ID,
|
|
||||||
ENTITY_MATCH_ALL,
|
|
||||||
SERVICE_TURN_OFF,
|
|
||||||
SERVICE_TURN_ON,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
|
|
||||||
from tests.components.directv import setup_integration
|
from tests.components.directv import setup_integration
|
||||||
@ -30,56 +20,6 @@ UNAVAILABLE_ENTITY_ID = f"{REMOTE_DOMAIN}.unavailable_client"
|
|||||||
# pylint: disable=redefined-outer-name
|
# pylint: disable=redefined-outer-name
|
||||||
|
|
||||||
|
|
||||||
async def async_send_command(
|
|
||||||
hass: HomeAssistantType,
|
|
||||||
command: List[str],
|
|
||||||
entity_id: Any = ENTITY_MATCH_ALL,
|
|
||||||
device: str = None,
|
|
||||||
num_repeats: str = None,
|
|
||||||
delay_secs: str = None,
|
|
||||||
) -> None:
|
|
||||||
"""Send a command to a device."""
|
|
||||||
data = {ATTR_COMMAND: command}
|
|
||||||
|
|
||||||
if entity_id:
|
|
||||||
data[ATTR_ENTITY_ID] = entity_id
|
|
||||||
|
|
||||||
if device:
|
|
||||||
data[ATTR_DEVICE] = device
|
|
||||||
|
|
||||||
if num_repeats:
|
|
||||||
data[ATTR_NUM_REPEATS] = num_repeats
|
|
||||||
|
|
||||||
if delay_secs:
|
|
||||||
data[ATTR_DELAY_SECS] = delay_secs
|
|
||||||
|
|
||||||
await hass.services.async_call(REMOTE_DOMAIN, SERVICE_SEND_COMMAND, data)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_turn_on(
|
|
||||||
hass: HomeAssistantType, entity_id: Any = ENTITY_MATCH_ALL
|
|
||||||
) -> None:
|
|
||||||
"""Turn on device."""
|
|
||||||
data = {}
|
|
||||||
|
|
||||||
if entity_id:
|
|
||||||
data[ATTR_ENTITY_ID] = entity_id
|
|
||||||
|
|
||||||
await hass.services.async_call(REMOTE_DOMAIN, SERVICE_TURN_ON, data)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_turn_off(
|
|
||||||
hass: HomeAssistantType, entity_id: Any = ENTITY_MATCH_ALL
|
|
||||||
) -> None:
|
|
||||||
"""Turn off remote."""
|
|
||||||
data = {}
|
|
||||||
|
|
||||||
if entity_id:
|
|
||||||
data[ATTR_ENTITY_ID] = entity_id
|
|
||||||
|
|
||||||
await hass.services.async_call(REMOTE_DOMAIN, SERVICE_TURN_OFF, data)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_setup(
|
async def test_setup(
|
||||||
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -115,16 +55,28 @@ async def test_main_services(
|
|||||||
await setup_integration(hass, aioclient_mock)
|
await setup_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
with patch("directv.DIRECTV.remote") as remote_mock:
|
with patch("directv.DIRECTV.remote") as remote_mock:
|
||||||
await async_turn_off(hass, MAIN_ENTITY_ID)
|
await hass.services.async_call(
|
||||||
await hass.async_block_till_done()
|
REMOTE_DOMAIN,
|
||||||
|
SERVICE_TURN_OFF,
|
||||||
|
{ATTR_ENTITY_ID: MAIN_ENTITY_ID},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
remote_mock.assert_called_once_with("poweroff", "0")
|
remote_mock.assert_called_once_with("poweroff", "0")
|
||||||
|
|
||||||
with patch("directv.DIRECTV.remote") as remote_mock:
|
with patch("directv.DIRECTV.remote") as remote_mock:
|
||||||
await async_turn_on(hass, MAIN_ENTITY_ID)
|
await hass.services.async_call(
|
||||||
await hass.async_block_till_done()
|
REMOTE_DOMAIN,
|
||||||
|
SERVICE_TURN_ON,
|
||||||
|
{ATTR_ENTITY_ID: MAIN_ENTITY_ID},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
remote_mock.assert_called_once_with("poweron", "0")
|
remote_mock.assert_called_once_with("poweron", "0")
|
||||||
|
|
||||||
with patch("directv.DIRECTV.remote") as remote_mock:
|
with patch("directv.DIRECTV.remote") as remote_mock:
|
||||||
await async_send_command(hass, ["dash"], MAIN_ENTITY_ID)
|
await hass.services.async_call(
|
||||||
await hass.async_block_till_done()
|
REMOTE_DOMAIN,
|
||||||
|
SERVICE_SEND_COMMAND,
|
||||||
|
{ATTR_ENTITY_ID: MAIN_ENTITY_ID, ATTR_COMMAND: ["dash"]},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
remote_mock.assert_called_once_with("dash", "0")
|
remote_mock.assert_called_once_with("dash", "0")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user