From d54ee773753443f24d4d1a5ff88d32b739bc0088 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Tue, 7 Apr 2020 13:57:51 -0500 Subject: [PATCH] Update directv remote platform tests service calls (#33793) * Update test_remote.py * Update test_remote.py --- tests/components/directv/test_remote.py | 86 ++++++------------------- 1 file changed, 19 insertions(+), 67 deletions(-) diff --git a/tests/components/directv/test_remote.py b/tests/components/directv/test_remote.py index 1e598b35892..f93d839b78c 100644 --- a/tests/components/directv/test_remote.py +++ b/tests/components/directv/test_remote.py @@ -1,22 +1,12 @@ """The tests for the DirecTV remote platform.""" -from typing import Any, List - from asynctest import patch from homeassistant.components.remote import ( ATTR_COMMAND, - ATTR_DELAY_SECS, - ATTR_DEVICE, - ATTR_NUM_REPEATS, DOMAIN as REMOTE_DOMAIN, SERVICE_SEND_COMMAND, ) -from homeassistant.const import ( - ATTR_ENTITY_ID, - ENTITY_MATCH_ALL, - SERVICE_TURN_OFF, - SERVICE_TURN_ON, -) +from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON from homeassistant.helpers.typing import HomeAssistantType from tests.components.directv import setup_integration @@ -30,56 +20,6 @@ UNAVAILABLE_ENTITY_ID = f"{REMOTE_DOMAIN}.unavailable_client" # 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( hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker ) -> None: @@ -115,16 +55,28 @@ async def test_main_services( await setup_integration(hass, aioclient_mock) with patch("directv.DIRECTV.remote") as remote_mock: - await async_turn_off(hass, MAIN_ENTITY_ID) - await hass.async_block_till_done() + await hass.services.async_call( + REMOTE_DOMAIN, + SERVICE_TURN_OFF, + {ATTR_ENTITY_ID: MAIN_ENTITY_ID}, + blocking=True, + ) remote_mock.assert_called_once_with("poweroff", "0") with patch("directv.DIRECTV.remote") as remote_mock: - await async_turn_on(hass, MAIN_ENTITY_ID) - await hass.async_block_till_done() + await hass.services.async_call( + REMOTE_DOMAIN, + SERVICE_TURN_ON, + {ATTR_ENTITY_ID: MAIN_ENTITY_ID}, + blocking=True, + ) remote_mock.assert_called_once_with("poweron", "0") with patch("directv.DIRECTV.remote") as remote_mock: - await async_send_command(hass, ["dash"], MAIN_ENTITY_ID) - await hass.async_block_till_done() + await hass.services.async_call( + REMOTE_DOMAIN, + SERVICE_SEND_COMMAND, + {ATTR_ENTITY_ID: MAIN_ENTITY_ID, ATTR_COMMAND: ["dash"]}, + blocking=True, + ) remote_mock.assert_called_once_with("dash", "0")