Adjust power_off for TheFrame in SamsungTV (#67841)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,7 @@ from unittest.mock import DEFAULT as DEFAULT_MOCK, AsyncMock, Mock, call, patch
|
||||
import pytest
|
||||
from samsungctl import exceptions
|
||||
from samsungtvws.async_remote import SamsungTVWSAsyncRemote
|
||||
from samsungtvws.command import SamsungTVSleepCommand
|
||||
from samsungtvws.exceptions import ConnectionFailure, HttpApiError
|
||||
from samsungtvws.remote import ChannelEmitCommand, SendRemoteKey
|
||||
from websockets.exceptions import WebSocketException
|
||||
@@ -63,7 +64,7 @@ from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from .const import SAMPLE_APP_LIST
|
||||
from .const import SAMPLE_APP_LIST, SAMPLE_DEVICE_INFO_FRAME
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
@@ -660,6 +661,37 @@ async def test_turn_off_websocket(
|
||||
remotews.send_command.assert_not_called()
|
||||
|
||||
|
||||
async def test_turn_off_websocket_frame(
|
||||
hass: HomeAssistant, remotews: Mock, rest_api: Mock
|
||||
) -> None:
|
||||
"""Test for turn_off."""
|
||||
rest_api.rest_device_info.return_value = SAMPLE_DEVICE_INFO_FRAME
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.bridge.Remote",
|
||||
side_effect=[OSError("Boom"), DEFAULT_MOCK],
|
||||
):
|
||||
await setup_samsungtv(hass, MOCK_CONFIGWS)
|
||||
|
||||
remotews.send_command.reset_mock()
|
||||
|
||||
assert await hass.services.async_call(
|
||||
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: ENTITY_ID}, True
|
||||
)
|
||||
# key called
|
||||
assert remotews.send_command.call_count == 3
|
||||
command = remotews.send_command.call_args_list[0].args[0]
|
||||
assert isinstance(command, SendRemoteKey)
|
||||
assert command.params["Cmd"] == "Press"
|
||||
assert command.params["DataOfCmd"] == "KEY_POWER"
|
||||
command = remotews.send_command.call_args_list[1].args[0]
|
||||
assert isinstance(command, SamsungTVSleepCommand)
|
||||
assert command.delay == 3
|
||||
command = remotews.send_command.call_args_list[2].args[0]
|
||||
assert isinstance(command, SendRemoteKey)
|
||||
assert command.params["Cmd"] == "Release"
|
||||
assert command.params["DataOfCmd"] == "KEY_POWER"
|
||||
|
||||
|
||||
async def test_turn_off_legacy(hass: HomeAssistant, remote: Mock) -> None:
|
||||
"""Test for turn_off."""
|
||||
await setup_samsungtv(hass, MOCK_CONFIG_NOTURNON)
|
||||
|
||||
Reference in New Issue
Block a user