2020-02-28 05:05:43 +00:00
|
|
|
"""The tests for Cover device actions."""
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
import homeassistant.components.automation as automation
|
|
|
|
from homeassistant.components.cover import DOMAIN
|
|
|
|
from homeassistant.const import CONF_PLATFORM
|
|
|
|
from homeassistant.helpers import device_registry
|
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
from tests.common import (
|
|
|
|
MockConfigEntry,
|
|
|
|
assert_lists_same,
|
|
|
|
async_get_device_automation_capabilities,
|
|
|
|
async_get_device_automations,
|
|
|
|
async_mock_service,
|
|
|
|
mock_device_registry,
|
|
|
|
mock_registry,
|
|
|
|
)
|
2021-03-02 08:02:04 +00:00
|
|
|
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def device_reg(hass):
|
|
|
|
"""Return an empty, loaded, registry."""
|
|
|
|
return mock_device_registry(hass)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def entity_reg(hass):
|
|
|
|
"""Return an empty, loaded, registry."""
|
|
|
|
return mock_registry(hass)
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
async def test_get_actions(hass, device_reg, entity_reg, enable_custom_integrations):
|
2020-02-28 05:05:43 +00:00
|
|
|
"""Test we get the expected actions from a cover."""
|
|
|
|
platform = getattr(hass.components, f"test.{DOMAIN}")
|
|
|
|
platform.init()
|
|
|
|
ent = platform.ENTITIES[0]
|
|
|
|
|
|
|
|
config_entry = MockConfigEntry(domain="test", data={})
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
device_entry = device_reg.async_get_or_create(
|
|
|
|
config_entry_id=config_entry.entry_id,
|
|
|
|
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
|
|
|
)
|
|
|
|
entity_reg.async_get_or_create(
|
|
|
|
DOMAIN, "test", ent.unique_id, device_id=device_entry.id
|
|
|
|
)
|
|
|
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
2020-08-05 12:58:19 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
expected_actions = [
|
|
|
|
{
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"type": "open",
|
|
|
|
"device_id": device_entry.id,
|
|
|
|
"entity_id": ent.entity_id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"type": "close",
|
|
|
|
"device_id": device_entry.id,
|
|
|
|
"entity_id": ent.entity_id,
|
|
|
|
},
|
2020-07-31 12:45:03 +00:00
|
|
|
{
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"type": "stop",
|
|
|
|
"device_id": device_entry.id,
|
|
|
|
"entity_id": ent.entity_id,
|
|
|
|
},
|
2020-02-28 05:05:43 +00:00
|
|
|
]
|
|
|
|
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
|
|
|
assert_lists_same(actions, expected_actions)
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
async def test_get_actions_tilt(
|
|
|
|
hass, device_reg, entity_reg, enable_custom_integrations
|
|
|
|
):
|
2020-02-28 05:05:43 +00:00
|
|
|
"""Test we get the expected actions from a cover."""
|
|
|
|
platform = getattr(hass.components, f"test.{DOMAIN}")
|
|
|
|
platform.init()
|
|
|
|
ent = platform.ENTITIES[3]
|
|
|
|
|
|
|
|
config_entry = MockConfigEntry(domain="test", data={})
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
device_entry = device_reg.async_get_or_create(
|
|
|
|
config_entry_id=config_entry.entry_id,
|
|
|
|
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
|
|
|
)
|
|
|
|
entity_reg.async_get_or_create(
|
|
|
|
DOMAIN, "test", ent.unique_id, device_id=device_entry.id
|
|
|
|
)
|
|
|
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
2020-08-05 12:58:19 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
expected_actions = [
|
|
|
|
{
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"type": "open",
|
|
|
|
"device_id": device_entry.id,
|
|
|
|
"entity_id": ent.entity_id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"type": "close",
|
|
|
|
"device_id": device_entry.id,
|
|
|
|
"entity_id": ent.entity_id,
|
|
|
|
},
|
2020-07-31 12:45:03 +00:00
|
|
|
{
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"type": "stop",
|
|
|
|
"device_id": device_entry.id,
|
|
|
|
"entity_id": ent.entity_id,
|
|
|
|
},
|
2020-02-28 05:05:43 +00:00
|
|
|
{
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"type": "open_tilt",
|
|
|
|
"device_id": device_entry.id,
|
|
|
|
"entity_id": ent.entity_id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"type": "close_tilt",
|
|
|
|
"device_id": device_entry.id,
|
|
|
|
"entity_id": ent.entity_id,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
|
|
|
assert_lists_same(actions, expected_actions)
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
async def test_get_actions_set_pos(
|
|
|
|
hass, device_reg, entity_reg, enable_custom_integrations
|
|
|
|
):
|
2020-02-28 05:05:43 +00:00
|
|
|
"""Test we get the expected actions from a cover."""
|
|
|
|
platform = getattr(hass.components, f"test.{DOMAIN}")
|
|
|
|
platform.init()
|
|
|
|
ent = platform.ENTITIES[1]
|
|
|
|
|
|
|
|
config_entry = MockConfigEntry(domain="test", data={})
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
device_entry = device_reg.async_get_or_create(
|
|
|
|
config_entry_id=config_entry.entry_id,
|
|
|
|
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
|
|
|
)
|
|
|
|
entity_reg.async_get_or_create(
|
|
|
|
DOMAIN, "test", ent.unique_id, device_id=device_entry.id
|
|
|
|
)
|
|
|
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
2020-08-05 12:58:19 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
expected_actions = [
|
|
|
|
{
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"type": "set_position",
|
|
|
|
"device_id": device_entry.id,
|
|
|
|
"entity_id": ent.entity_id,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
|
|
|
assert_lists_same(actions, expected_actions)
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
async def test_get_actions_set_tilt_pos(
|
|
|
|
hass, device_reg, entity_reg, enable_custom_integrations
|
|
|
|
):
|
2020-02-28 05:05:43 +00:00
|
|
|
"""Test we get the expected actions from a cover."""
|
|
|
|
platform = getattr(hass.components, f"test.{DOMAIN}")
|
|
|
|
platform.init()
|
|
|
|
ent = platform.ENTITIES[2]
|
|
|
|
|
|
|
|
config_entry = MockConfigEntry(domain="test", data={})
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
device_entry = device_reg.async_get_or_create(
|
|
|
|
config_entry_id=config_entry.entry_id,
|
|
|
|
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
|
|
|
)
|
|
|
|
entity_reg.async_get_or_create(
|
|
|
|
DOMAIN, "test", ent.unique_id, device_id=device_entry.id
|
|
|
|
)
|
|
|
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
2020-08-05 12:58:19 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
expected_actions = [
|
|
|
|
{
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"type": "open",
|
|
|
|
"device_id": device_entry.id,
|
|
|
|
"entity_id": ent.entity_id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"type": "close",
|
|
|
|
"device_id": device_entry.id,
|
|
|
|
"entity_id": ent.entity_id,
|
|
|
|
},
|
2020-07-31 12:45:03 +00:00
|
|
|
{
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"type": "stop",
|
|
|
|
"device_id": device_entry.id,
|
|
|
|
"entity_id": ent.entity_id,
|
|
|
|
},
|
2020-02-28 05:05:43 +00:00
|
|
|
{
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"type": "set_tilt_position",
|
|
|
|
"device_id": device_entry.id,
|
|
|
|
"entity_id": ent.entity_id,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
|
|
|
assert_lists_same(actions, expected_actions)
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
async def test_get_action_capabilities(
|
|
|
|
hass, device_reg, entity_reg, enable_custom_integrations
|
|
|
|
):
|
2020-02-28 05:05:43 +00:00
|
|
|
"""Test we get the expected capabilities from a cover action."""
|
|
|
|
platform = getattr(hass.components, f"test.{DOMAIN}")
|
|
|
|
platform.init()
|
|
|
|
ent = platform.ENTITIES[0]
|
|
|
|
|
|
|
|
config_entry = MockConfigEntry(domain="test", data={})
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
device_entry = device_reg.async_get_or_create(
|
|
|
|
config_entry_id=config_entry.entry_id,
|
|
|
|
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
|
|
|
)
|
|
|
|
entity_reg.async_get_or_create(
|
|
|
|
DOMAIN, "test", ent.unique_id, device_id=device_entry.id
|
|
|
|
)
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
2020-08-05 12:58:19 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
2020-07-31 12:45:03 +00:00
|
|
|
assert len(actions) == 3 # open, close, stop
|
2020-02-28 05:05:43 +00:00
|
|
|
for action in actions:
|
|
|
|
capabilities = await async_get_device_automation_capabilities(
|
|
|
|
hass, "action", action
|
|
|
|
)
|
|
|
|
assert capabilities == {"extra_fields": []}
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
async def test_get_action_capabilities_set_pos(
|
|
|
|
hass, device_reg, entity_reg, enable_custom_integrations
|
|
|
|
):
|
2020-02-28 05:05:43 +00:00
|
|
|
"""Test we get the expected capabilities from a cover action."""
|
|
|
|
platform = getattr(hass.components, f"test.{DOMAIN}")
|
|
|
|
platform.init()
|
|
|
|
ent = platform.ENTITIES[1]
|
|
|
|
|
|
|
|
config_entry = MockConfigEntry(domain="test", data={})
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
device_entry = device_reg.async_get_or_create(
|
|
|
|
config_entry_id=config_entry.entry_id,
|
|
|
|
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
|
|
|
)
|
|
|
|
entity_reg.async_get_or_create(
|
|
|
|
DOMAIN, "test", ent.unique_id, device_id=device_entry.id
|
|
|
|
)
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
2020-08-05 12:58:19 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
expected_capabilities = {
|
|
|
|
"extra_fields": [
|
|
|
|
{
|
|
|
|
"name": "position",
|
|
|
|
"optional": True,
|
|
|
|
"type": "integer",
|
|
|
|
"default": 0,
|
|
|
|
"valueMax": 100,
|
|
|
|
"valueMin": 0,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
|
|
|
assert len(actions) == 1 # set_position
|
|
|
|
for action in actions:
|
|
|
|
capabilities = await async_get_device_automation_capabilities(
|
|
|
|
hass, "action", action
|
|
|
|
)
|
|
|
|
if action["type"] == "set_position":
|
|
|
|
assert capabilities == expected_capabilities
|
|
|
|
else:
|
|
|
|
assert capabilities == {"extra_fields": []}
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
async def test_get_action_capabilities_set_tilt_pos(
|
|
|
|
hass, device_reg, entity_reg, enable_custom_integrations
|
|
|
|
):
|
2020-02-28 05:05:43 +00:00
|
|
|
"""Test we get the expected capabilities from a cover action."""
|
|
|
|
platform = getattr(hass.components, f"test.{DOMAIN}")
|
|
|
|
platform.init()
|
|
|
|
ent = platform.ENTITIES[2]
|
|
|
|
|
|
|
|
config_entry = MockConfigEntry(domain="test", data={})
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
device_entry = device_reg.async_get_or_create(
|
|
|
|
config_entry_id=config_entry.entry_id,
|
|
|
|
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
|
|
|
)
|
|
|
|
entity_reg.async_get_or_create(
|
|
|
|
DOMAIN, "test", ent.unique_id, device_id=device_entry.id
|
|
|
|
)
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
2020-08-05 12:58:19 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
expected_capabilities = {
|
|
|
|
"extra_fields": [
|
|
|
|
{
|
|
|
|
"name": "position",
|
|
|
|
"optional": True,
|
|
|
|
"type": "integer",
|
|
|
|
"default": 0,
|
|
|
|
"valueMax": 100,
|
|
|
|
"valueMin": 0,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
2020-07-31 12:45:03 +00:00
|
|
|
assert len(actions) == 4 # open, close, stop, set_tilt_position
|
2020-02-28 05:05:43 +00:00
|
|
|
for action in actions:
|
|
|
|
capabilities = await async_get_device_automation_capabilities(
|
|
|
|
hass, "action", action
|
|
|
|
)
|
|
|
|
if action["type"] == "set_tilt_position":
|
|
|
|
assert capabilities == expected_capabilities
|
|
|
|
else:
|
|
|
|
assert capabilities == {"extra_fields": []}
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
async def test_action(hass, enable_custom_integrations):
|
2020-02-28 05:05:43 +00:00
|
|
|
"""Test for cover actions."""
|
|
|
|
platform = getattr(hass.components, f"test.{DOMAIN}")
|
|
|
|
platform.init()
|
|
|
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
|
|
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
automation.DOMAIN,
|
|
|
|
{
|
|
|
|
automation.DOMAIN: [
|
|
|
|
{
|
|
|
|
"trigger": {"platform": "event", "event_type": "test_event_open"},
|
|
|
|
"action": {
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"device_id": "abcdefgh",
|
|
|
|
"entity_id": "cover.entity",
|
|
|
|
"type": "open",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"trigger": {"platform": "event", "event_type": "test_event_close"},
|
|
|
|
"action": {
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"device_id": "abcdefgh",
|
|
|
|
"entity_id": "cover.entity",
|
|
|
|
"type": "close",
|
|
|
|
},
|
|
|
|
},
|
2020-07-31 12:45:03 +00:00
|
|
|
{
|
|
|
|
"trigger": {"platform": "event", "event_type": "test_event_stop"},
|
|
|
|
"action": {
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"device_id": "abcdefgh",
|
|
|
|
"entity_id": "cover.entity",
|
|
|
|
"type": "stop",
|
|
|
|
},
|
|
|
|
},
|
2020-02-28 05:05:43 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
open_calls = async_mock_service(hass, "cover", "open_cover")
|
|
|
|
close_calls = async_mock_service(hass, "cover", "close_cover")
|
2020-07-31 12:45:03 +00:00
|
|
|
stop_calls = async_mock_service(hass, "cover", "stop_cover")
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
hass.bus.async_fire("test_event_open")
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert len(open_calls) == 1
|
|
|
|
assert len(close_calls) == 0
|
2020-07-31 12:45:03 +00:00
|
|
|
assert len(stop_calls) == 0
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
hass.bus.async_fire("test_event_close")
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert len(open_calls) == 1
|
|
|
|
assert len(close_calls) == 1
|
2020-07-31 12:45:03 +00:00
|
|
|
assert len(stop_calls) == 0
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
hass.bus.async_fire("test_event_stop")
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert len(open_calls) == 1
|
|
|
|
assert len(close_calls) == 1
|
2020-07-31 12:45:03 +00:00
|
|
|
assert len(stop_calls) == 1
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
async def test_action_tilt(hass, enable_custom_integrations):
|
2020-02-28 05:05:43 +00:00
|
|
|
"""Test for cover tilt actions."""
|
|
|
|
platform = getattr(hass.components, f"test.{DOMAIN}")
|
|
|
|
platform.init()
|
|
|
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
|
|
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
automation.DOMAIN,
|
|
|
|
{
|
|
|
|
automation.DOMAIN: [
|
|
|
|
{
|
|
|
|
"trigger": {"platform": "event", "event_type": "test_event_open"},
|
|
|
|
"action": {
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"device_id": "abcdefgh",
|
|
|
|
"entity_id": "cover.entity",
|
|
|
|
"type": "open_tilt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"trigger": {"platform": "event", "event_type": "test_event_close"},
|
|
|
|
"action": {
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"device_id": "abcdefgh",
|
|
|
|
"entity_id": "cover.entity",
|
|
|
|
"type": "close_tilt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
open_calls = async_mock_service(hass, "cover", "open_cover_tilt")
|
|
|
|
close_calls = async_mock_service(hass, "cover", "close_cover_tilt")
|
|
|
|
|
|
|
|
hass.bus.async_fire("test_event_open")
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert len(open_calls) == 1
|
|
|
|
assert len(close_calls) == 0
|
|
|
|
|
|
|
|
hass.bus.async_fire("test_event_close")
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert len(open_calls) == 1
|
|
|
|
assert len(close_calls) == 1
|
|
|
|
|
|
|
|
hass.bus.async_fire("test_event_stop")
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert len(open_calls) == 1
|
|
|
|
assert len(close_calls) == 1
|
|
|
|
|
|
|
|
|
2021-05-17 13:48:41 +00:00
|
|
|
async def test_action_set_position(hass, enable_custom_integrations):
|
2020-02-28 05:05:43 +00:00
|
|
|
"""Test for cover set position actions."""
|
|
|
|
platform = getattr(hass.components, f"test.{DOMAIN}")
|
|
|
|
platform.init()
|
|
|
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
|
|
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
automation.DOMAIN,
|
|
|
|
{
|
|
|
|
automation.DOMAIN: [
|
|
|
|
{
|
|
|
|
"trigger": {
|
|
|
|
"platform": "event",
|
|
|
|
"event_type": "test_event_set_pos",
|
|
|
|
},
|
|
|
|
"action": {
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"device_id": "abcdefgh",
|
|
|
|
"entity_id": "cover.entity",
|
|
|
|
"type": "set_position",
|
|
|
|
"position": 25,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"trigger": {
|
|
|
|
"platform": "event",
|
|
|
|
"event_type": "test_event_set_tilt_pos",
|
|
|
|
},
|
|
|
|
"action": {
|
|
|
|
"domain": DOMAIN,
|
|
|
|
"device_id": "abcdefgh",
|
|
|
|
"entity_id": "cover.entity",
|
|
|
|
"type": "set_tilt_position",
|
|
|
|
"position": 75,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
)
|
2020-08-05 12:58:19 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-02-28 05:05:43 +00:00
|
|
|
|
|
|
|
cover_pos_calls = async_mock_service(hass, "cover", "set_cover_position")
|
|
|
|
tilt_pos_calls = async_mock_service(hass, "cover", "set_cover_tilt_position")
|
|
|
|
|
|
|
|
hass.bus.async_fire("test_event_set_pos")
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert len(cover_pos_calls) == 1
|
|
|
|
assert cover_pos_calls[0].data["position"] == 25
|
|
|
|
assert len(tilt_pos_calls) == 0
|
|
|
|
|
|
|
|
hass.bus.async_fire("test_event_set_tilt_pos")
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert len(cover_pos_calls) == 1
|
|
|
|
assert len(tilt_pos_calls) == 1
|
|
|
|
assert tilt_pos_calls[0].data["tilt_position"] == 75
|