Add webostv 100% tests cover for triggers (#64301)

This commit is contained in:
Shay Levy 2022-01-17 19:33:46 +02:00 committed by GitHub
parent e6899416e1
commit a2e1cd2632
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,11 +1,16 @@
"""The tests for WebOS TV automation triggers."""
from unittest.mock import patch
from homeassistant.components import automation
from homeassistant.components.webostv import DOMAIN
from homeassistant.const import SERVICE_RELOAD
from homeassistant.helpers.device_registry import async_get as get_dev_reg
from homeassistant.setup import async_setup_component
from . import ENTITY_ID, setup_webostv
from tests.common import MockEntity, MockEntityPlatform
async def test_webostv_turn_on_trigger_device_id(hass, calls, client):
"""Test for turn_on triggers by device_id firing."""
@ -48,6 +53,21 @@ async def test_webostv_turn_on_trigger_device_id(hass, calls, client):
assert calls[0].data["some"] == device.id
assert calls[0].data["id"] == 0
with patch("homeassistant.config.load_yaml", return_value={}):
await hass.services.async_call(automation.DOMAIN, SERVICE_RELOAD, blocking=True)
await hass.services.async_call(
"media_player",
"turn_on",
{"entity_id": ENTITY_ID},
blocking=True,
)
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data["some"] == device.id
assert calls[0].data["id"] == 0
async def test_webostv_turn_on_trigger_entity_id(hass, calls, client):
"""Test for turn_on triggers by entity_id firing."""
@ -118,3 +138,40 @@ async def test_wrong_trigger_platform_type(hass, caplog, client):
"ValueError: Unknown webOS Smart TV trigger platform webostv.wrong_type"
in caplog.text
)
async def test_trigger_invalid_entity_id(hass, caplog, client):
"""Test turn on trigger using invalid entity_id."""
await setup_webostv(hass, "fake-uuid")
platform = MockEntityPlatform(hass)
invalid_entity = f"{DOMAIN}.invalid"
await platform.async_add_entities([MockEntity(name=invalid_entity)])
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: [
{
"trigger": {
"platform": "webostv.turn_on",
"entity_id": invalid_entity,
},
"action": {
"service": "test.automation",
"data_template": {
"some": ENTITY_ID,
"id": "{{ trigger.id }}",
},
},
},
],
},
)
assert (
f"ValueError: Entity {invalid_entity} is not a valid webostv entity"
in caplog.text
)