1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Mark device actions from hidden or auxiliary entities as secondary (#70278)

This commit is contained in:
Erik Montnemery
2022-04-20 19:48:46 +02:00
committed by GitHub
parent 2a99084911
commit 64381acbaf
24 changed files with 875 additions and 164 deletions

View File

@@ -6,6 +6,8 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.number import DOMAIN, device_action
from homeassistant.helpers import config_validation as cv, device_registry
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component
from tests.common import (
@@ -47,6 +49,7 @@ async def test_get_actions(hass, device_reg, entity_reg):
"type": "set_value",
"device_id": device_entry.id,
"entity_id": "number.test_5678",
"metadata": {"secondary": False},
},
]
actions = await async_get_device_automations(
@@ -55,6 +58,54 @@ async def test_get_actions(hass, device_reg, entity_reg):
assert_lists_same(actions, expected_actions)
@pytest.mark.parametrize(
"hidden_by,entity_category",
(
(RegistryEntryHider.INTEGRATION, None),
(RegistryEntryHider.USER, None),
(None, EntityCategory.CONFIG),
(None, EntityCategory.DIAGNOSTIC),
),
)
async def test_get_actions_hidden_auxiliary(
hass,
device_reg,
entity_reg,
hidden_by,
entity_category,
):
"""Test we get the expected actions from a hidden or auxiliary entity."""
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",
"5678",
device_id=device_entry.id,
entity_category=entity_category,
hidden_by=hidden_by,
)
expected_actions = []
expected_actions += [
{
"domain": DOMAIN,
"type": action,
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_5678",
"metadata": {"secondary": True},
}
for action in ["set_value"]
]
actions = await async_get_device_automations(
hass, DeviceAutomationType.ACTION, device_entry.id
)
assert_lists_same(actions, expected_actions)
async def test_get_action_no_state(hass, device_reg, entity_reg):
"""Test we get the expected actions for an entity."""
config_entry = MockConfigEntry(domain="test", data={})
@@ -70,6 +121,7 @@ async def test_get_action_no_state(hass, device_reg, entity_reg):
"type": "set_value",
"device_id": device_entry.id,
"entity_id": "number.test_5678",
"metadata": {"secondary": False},
},
]
actions = await async_get_device_automations(