Make some device action tests more explicit (#59469)
* Make some device action tests more explicit * Adjust tests
This commit is contained in:
parent
731bec3145
commit
85786fd987
3 changed files with 51 additions and 12 deletions
|
@ -160,6 +160,7 @@ async def test_get_action_capabilities(
|
|||
}
|
||||
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
||||
assert len(actions) == 6
|
||||
assert {action["type"] for action in actions} == set(expected_capabilities)
|
||||
for action in actions:
|
||||
capabilities = await async_get_device_automation_capabilities(
|
||||
hass, "action", action
|
||||
|
@ -209,6 +210,7 @@ async def test_get_action_capabilities_arm_code(
|
|||
}
|
||||
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
||||
assert len(actions) == 6
|
||||
assert {action["type"] for action in actions} == set(expected_capabilities)
|
||||
for action in actions:
|
||||
capabilities = await async_get_device_automation_capabilities(
|
||||
hass, "action", action
|
||||
|
|
|
@ -11,6 +11,7 @@ from homeassistant.components.cover import (
|
|||
SUPPORT_SET_POSITION,
|
||||
SUPPORT_SET_TILT_POSITION,
|
||||
SUPPORT_STOP,
|
||||
SUPPORT_STOP_TILT,
|
||||
)
|
||||
from homeassistant.const import CONF_PLATFORM
|
||||
from homeassistant.helpers import device_registry
|
||||
|
@ -109,8 +110,22 @@ async def test_get_action_capabilities(
|
|||
):
|
||||
"""Test we get the expected capabilities from a cover action."""
|
||||
platform = getattr(hass.components, f"test.{DOMAIN}")
|
||||
platform.init()
|
||||
ent = platform.ENTITIES[2]
|
||||
platform.init(empty=True)
|
||||
platform.ENTITIES.append(
|
||||
platform.MockCover(
|
||||
name="Set position cover",
|
||||
is_on=True,
|
||||
unique_id="unique_set_pos_cover",
|
||||
current_cover_position=50,
|
||||
supported_features=SUPPORT_OPEN
|
||||
| SUPPORT_CLOSE
|
||||
| SUPPORT_STOP
|
||||
| SUPPORT_OPEN_TILT
|
||||
| SUPPORT_CLOSE_TILT
|
||||
| SUPPORT_STOP_TILT,
|
||||
),
|
||||
)
|
||||
ent = platform.ENTITIES[0]
|
||||
|
||||
config_entry = MockConfigEntry(domain="test", data={})
|
||||
config_entry.add_to_hass(hass)
|
||||
|
@ -126,7 +141,9 @@ async def test_get_action_capabilities(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
||||
assert len(actions) == 4 # open, close, stop, set_position
|
||||
assert len(actions) == 5 # open, close, open_tilt, close_tilt
|
||||
action_types = {action["type"] for action in actions}
|
||||
assert action_types == {"open", "close", "stop", "open_tilt", "close_tilt"}
|
||||
for action in actions:
|
||||
capabilities = await async_get_device_automation_capabilities(
|
||||
hass, "action", action
|
||||
|
@ -169,6 +186,8 @@ async def test_get_action_capabilities_set_pos(
|
|||
}
|
||||
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
||||
assert len(actions) == 1 # set_position
|
||||
action_types = {action["type"] for action in actions}
|
||||
assert action_types == {"set_position"}
|
||||
for action in actions:
|
||||
capabilities = await async_get_device_automation_capabilities(
|
||||
hass, "action", action
|
||||
|
@ -185,7 +204,7 @@ async def test_get_action_capabilities_set_tilt_pos(
|
|||
"""Test we get the expected capabilities from a cover action."""
|
||||
platform = getattr(hass.components, f"test.{DOMAIN}")
|
||||
platform.init()
|
||||
ent = platform.ENTITIES[2]
|
||||
ent = platform.ENTITIES[3]
|
||||
|
||||
config_entry = MockConfigEntry(domain="test", data={})
|
||||
config_entry.add_to_hass(hass)
|
||||
|
@ -213,7 +232,9 @@ async def test_get_action_capabilities_set_tilt_pos(
|
|||
]
|
||||
}
|
||||
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
||||
assert len(actions) == 4 # open, close, stop, set_tilt_position
|
||||
assert len(actions) == 3
|
||||
action_types = {action["type"] for action in actions}
|
||||
assert action_types == {"open", "close", "set_tilt_position"}
|
||||
for action in actions:
|
||||
capabilities = await async_get_device_automation_capabilities(
|
||||
hass, "action", action
|
||||
|
|
|
@ -118,6 +118,8 @@ async def test_get_action_capabilities(hass, device_reg, entity_reg):
|
|||
).entity_id
|
||||
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
||||
assert len(actions) == 3
|
||||
action_types = {action["type"] for action in actions}
|
||||
assert action_types == {"turn_on", "toggle", "turn_off"}
|
||||
for action in actions:
|
||||
capabilities = await async_get_device_automation_capabilities(
|
||||
hass, "action", action
|
||||
|
@ -134,11 +136,17 @@ async def test_get_action_capabilities(hass, device_reg, entity_reg):
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"set_state,num_actions,supported_features_reg,supported_features_state,capabilities_reg,attributes_state,expected_capabilities",
|
||||
"set_state,expected_actions,supported_features_reg,supported_features_state,capabilities_reg,attributes_state,expected_capabilities",
|
||||
[
|
||||
(
|
||||
False,
|
||||
5,
|
||||
{
|
||||
"turn_on",
|
||||
"toggle",
|
||||
"turn_off",
|
||||
"brightness_increase",
|
||||
"brightness_decrease",
|
||||
},
|
||||
0,
|
||||
0,
|
||||
{ATTR_SUPPORTED_COLOR_MODES: [COLOR_MODE_BRIGHTNESS]},
|
||||
|
@ -157,7 +165,13 @@ async def test_get_action_capabilities(hass, device_reg, entity_reg):
|
|||
),
|
||||
(
|
||||
True,
|
||||
5,
|
||||
{
|
||||
"turn_on",
|
||||
"toggle",
|
||||
"turn_off",
|
||||
"brightness_increase",
|
||||
"brightness_decrease",
|
||||
},
|
||||
0,
|
||||
0,
|
||||
None,
|
||||
|
@ -176,7 +190,7 @@ async def test_get_action_capabilities(hass, device_reg, entity_reg):
|
|||
),
|
||||
(
|
||||
False,
|
||||
4,
|
||||
{"turn_on", "toggle", "turn_off", "flash"},
|
||||
SUPPORT_FLASH,
|
||||
0,
|
||||
None,
|
||||
|
@ -194,7 +208,7 @@ async def test_get_action_capabilities(hass, device_reg, entity_reg):
|
|||
),
|
||||
(
|
||||
True,
|
||||
4,
|
||||
{"turn_on", "toggle", "turn_off", "flash"},
|
||||
0,
|
||||
SUPPORT_FLASH,
|
||||
None,
|
||||
|
@ -217,7 +231,7 @@ async def test_get_action_capabilities_features(
|
|||
device_reg,
|
||||
entity_reg,
|
||||
set_state,
|
||||
num_actions,
|
||||
expected_actions,
|
||||
supported_features_reg,
|
||||
supported_features_state,
|
||||
capabilities_reg,
|
||||
|
@ -247,7 +261,9 @@ async def test_get_action_capabilities_features(
|
|||
)
|
||||
|
||||
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
||||
assert len(actions) == num_actions
|
||||
assert len(actions) == len(expected_actions)
|
||||
action_types = {action["type"] for action in actions}
|
||||
assert action_types == expected_actions
|
||||
for action in actions:
|
||||
capabilities = await async_get_device_automation_capabilities(
|
||||
hass, "action", action
|
||||
|
|
Loading…
Add table
Reference in a new issue