Improve roku remote (#35419)
* Update remote.py * Create test_remote.py * Update .coveragerc
This commit is contained in:
parent
2148f63d89
commit
06ddda8c95
3 changed files with 78 additions and 1 deletions
|
@ -618,7 +618,6 @@ omit =
|
||||||
homeassistant/components/ring/camera.py
|
homeassistant/components/ring/camera.py
|
||||||
homeassistant/components/ripple/sensor.py
|
homeassistant/components/ripple/sensor.py
|
||||||
homeassistant/components/rocketchat/notify.py
|
homeassistant/components/rocketchat/notify.py
|
||||||
homeassistant/components/roku/remote.py
|
|
||||||
homeassistant/components/roomba/binary_sensor.py
|
homeassistant/components/roomba/binary_sensor.py
|
||||||
homeassistant/components/roomba/braava.py
|
homeassistant/components/roomba/braava.py
|
||||||
homeassistant/components/roomba/irobot_base.py
|
homeassistant/components/roomba/irobot_base.py
|
||||||
|
|
|
@ -43,6 +43,14 @@ class RokuRemote(RokuEntity, RemoteEntity):
|
||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
return not self.coordinator.data.state.standby
|
return not self.coordinator.data.state.standby
|
||||||
|
|
||||||
|
async def async_turn_on(self, **kwargs) -> None:
|
||||||
|
"""Turn the device on."""
|
||||||
|
await self.coordinator.roku.remote("poweron")
|
||||||
|
|
||||||
|
async def async_turn_off(self, **kwargs) -> None:
|
||||||
|
"""Turn the device off."""
|
||||||
|
await self.coordinator.roku.remote("poweroff")
|
||||||
|
|
||||||
async def async_send_command(self, command: List, **kwargs) -> None:
|
async def async_send_command(self, command: List, **kwargs) -> None:
|
||||||
"""Send a command to one device."""
|
"""Send a command to one device."""
|
||||||
num_repeats = kwargs[ATTR_NUM_REPEATS]
|
num_repeats = kwargs[ATTR_NUM_REPEATS]
|
||||||
|
|
70
tests/components/roku/test_remote.py
Normal file
70
tests/components/roku/test_remote.py
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
"""The tests for the Roku remote platform."""
|
||||||
|
from homeassistant.components.remote import (
|
||||||
|
ATTR_COMMAND,
|
||||||
|
DOMAIN as REMOTE_DOMAIN,
|
||||||
|
SERVICE_SEND_COMMAND,
|
||||||
|
)
|
||||||
|
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||||
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
|
|
||||||
|
from tests.async_mock import patch
|
||||||
|
from tests.components.roku import UPNP_SERIAL, setup_integration
|
||||||
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
|
MAIN_ENTITY_ID = f"{REMOTE_DOMAIN}.my_roku_3"
|
||||||
|
|
||||||
|
# pylint: disable=redefined-outer-name
|
||||||
|
|
||||||
|
|
||||||
|
async def test_setup(
|
||||||
|
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
|
"""Test setup with basic config."""
|
||||||
|
await setup_integration(hass, aioclient_mock)
|
||||||
|
assert hass.states.get(MAIN_ENTITY_ID)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_unique_id(
|
||||||
|
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
|
"""Test unique id."""
|
||||||
|
await setup_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
|
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||||
|
|
||||||
|
main = entity_registry.async_get(MAIN_ENTITY_ID)
|
||||||
|
assert main.unique_id == UPNP_SERIAL
|
||||||
|
|
||||||
|
|
||||||
|
async def test_main_services(
|
||||||
|
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
|
"""Test the different services."""
|
||||||
|
await setup_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
|
with patch("homeassistant.components.roku.Roku.remote") as remote_mock:
|
||||||
|
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")
|
||||||
|
|
||||||
|
with patch("homeassistant.components.roku.Roku.remote") as remote_mock:
|
||||||
|
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")
|
||||||
|
|
||||||
|
with patch("homeassistant.components.roku.Roku.remote") as remote_mock:
|
||||||
|
await hass.services.async_call(
|
||||||
|
REMOTE_DOMAIN,
|
||||||
|
SERVICE_SEND_COMMAND,
|
||||||
|
{ATTR_ENTITY_ID: MAIN_ENTITY_ID, ATTR_COMMAND: ["home"]},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
remote_mock.assert_called_once_with("home")
|
Loading…
Add table
Reference in a new issue