2016-12-01 20:48:08 +00:00
|
|
|
"""The tests for the demo remote component."""
|
2020-10-19 21:29:44 +00:00
|
|
|
import pytest
|
2016-12-01 20:48:08 +00:00
|
|
|
|
|
|
|
import homeassistant.components.remote as remote
|
2020-10-19 21:29:44 +00:00
|
|
|
from homeassistant.components.remote import ATTR_COMMAND
|
|
|
|
from homeassistant.const import (
|
|
|
|
ATTR_ENTITY_ID,
|
|
|
|
SERVICE_TURN_OFF,
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
STATE_OFF,
|
|
|
|
STATE_ON,
|
|
|
|
)
|
2023-02-08 12:01:44 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2020-10-19 21:29:44 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2016-12-01 20:48:08 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
ENTITY_ID = "remote.remote_one"
|
2020-10-19 21:29:44 +00:00
|
|
|
SERVICE_SEND_COMMAND = "send_command"
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
async def setup_component(hass):
|
|
|
|
"""Initialize components."""
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass, remote.DOMAIN, {"remote": {"platform": "demo"}}
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
2023-02-08 12:01:44 +00:00
|
|
|
async def test_methods(hass: HomeAssistant) -> None:
|
2020-10-19 21:29:44 +00:00
|
|
|
"""Test if services call the entity methods as expected."""
|
|
|
|
await hass.services.async_call(
|
|
|
|
remote.DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_ID}
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
state = hass.states.get(ENTITY_ID)
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
remote.DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: ENTITY_ID}
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
state = hass.states.get(ENTITY_ID)
|
|
|
|
assert state.state == STATE_OFF
|
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
remote.DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_ID}
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
state = hass.states.get(ENTITY_ID)
|
|
|
|
assert state.state == STATE_ON
|
|
|
|
|
|
|
|
data = {
|
|
|
|
ATTR_ENTITY_ID: ENTITY_ID,
|
|
|
|
ATTR_COMMAND: ["test"],
|
|
|
|
}
|
|
|
|
|
|
|
|
await hass.services.async_call(remote.DOMAIN, SERVICE_SEND_COMMAND, data)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
state = hass.states.get(ENTITY_ID)
|
|
|
|
assert state.attributes == {
|
|
|
|
"friendly_name": "Remote One",
|
|
|
|
"last_command_sent": "test",
|
|
|
|
"supported_features": 0,
|
|
|
|
}
|