Use service_calls fixture in samsungtv tests (#120992)

pull/121011/head
epenet 2024-07-02 10:37:14 +02:00 committed by GitHub
parent 3df3e6d081
commit fac511aa46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 25 deletions

View File

@ -21,13 +21,10 @@ from samsungtvws.exceptions import ResponseError
from samsungtvws.remote import ChannelEmitCommand
from homeassistant.components.samsungtv.const import WEBSOCKET_SSL_PORT
from homeassistant.core import HomeAssistant, ServiceCall
import homeassistant.util.dt as dt_util
from .const import SAMPLE_DEVICE_INFO_UE48JU6400, SAMPLE_DEVICE_INFO_WIFI
from tests.common import async_mock_service
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
@ -299,9 +296,3 @@ def mac_address_fixture() -> Mock:
"""Patch getmac.get_mac_address."""
with patch("getmac.get_mac_address", return_value=None) as mac:
yield mac
@pytest.fixture
def calls(hass: HomeAssistant) -> list[ServiceCall]:
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation")

View File

@ -45,7 +45,9 @@ async def test_get_triggers(
@pytest.mark.usefixtures("remoteencws", "rest_api")
async def test_if_fires_on_turn_on_request(
hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls: list[ServiceCall]
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
service_calls: list[ServiceCall],
) -> None:
"""Test for turn_on and turn_off triggers firing."""
await setup_samsungtv_entry(hass, MOCK_ENTRYDATA_ENCRYPTED_WS)
@ -95,11 +97,11 @@ async def test_if_fires_on_turn_on_request(
)
await hass.async_block_till_done()
assert len(calls) == 2
assert calls[0].data["some"] == device.id
assert calls[0].data["id"] == 0
assert calls[1].data["some"] == entity_id
assert calls[1].data["id"] == 0
assert len(service_calls) == 3
assert service_calls[1].data["some"] == device.id
assert service_calls[1].data["id"] == 0
assert service_calls[2].data["some"] == entity_id
assert service_calls[2].data["id"] == 0
@pytest.mark.usefixtures("remoteencws", "rest_api")

View File

@ -21,7 +21,7 @@ from tests.common import MockEntity, MockEntityPlatform
@pytest.mark.parametrize("entity_domain", ["media_player", "remote"])
async def test_turn_on_trigger_device_id(
hass: HomeAssistant,
calls: list[ServiceCall],
service_calls: list[ServiceCall],
device_registry: dr.DeviceRegistry,
entity_domain: str,
) -> None:
@ -60,14 +60,14 @@ async def test_turn_on_trigger_device_id(
)
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data["some"] == device.id
assert calls[0].data["id"] == 0
assert len(service_calls) == 2
assert service_calls[1].data["some"] == device.id
assert service_calls[1].data["id"] == 0
with patch("homeassistant.config.load_yaml_dict", return_value={}):
await hass.services.async_call(automation.DOMAIN, SERVICE_RELOAD, blocking=True)
calls.clear()
service_calls.clear()
# Ensure WOL backup is called when trigger not present
with patch(
@ -78,14 +78,14 @@ async def test_turn_on_trigger_device_id(
)
await hass.async_block_till_done()
assert len(calls) == 0
assert len(service_calls) == 1
mock_send_magic_packet.assert_called()
@pytest.mark.usefixtures("remoteencws", "rest_api")
@pytest.mark.parametrize("entity_domain", ["media_player", "remote"])
async def test_turn_on_trigger_entity_id(
hass: HomeAssistant, calls: list[ServiceCall], entity_domain: str
hass: HomeAssistant, service_calls: list[ServiceCall], entity_domain: str
) -> None:
"""Test for turn_on triggers by entity_id firing."""
await setup_samsungtv_entry(hass, MOCK_ENTRYDATA_ENCRYPTED_WS)
@ -119,9 +119,9 @@ async def test_turn_on_trigger_entity_id(
)
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data["some"] == entity_id
assert calls[0].data["id"] == 0
assert len(service_calls) == 2
assert service_calls[1].data["some"] == entity_id
assert service_calls[1].data["id"] == 0
@pytest.mark.usefixtures("remoteencws", "rest_api")