1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +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,7 @@ from homeassistant.components.NEW_DOMAIN import DOMAIN
from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry, entity_registry
from homeassistant.helpers.entity import EntityCategory
from homeassistant.setup import async_setup_component
from tests.common import (
@@ -46,16 +47,58 @@ async def test_get_actions(
expected_actions = [
{
"domain": DOMAIN,
"type": "turn_on",
"type": action,
"device_id": device_entry.id,
"entity_id": "NEW_DOMAIN.test_5678",
},
"entity_id": f"{DOMAIN}.test_5678",
}
for action in ["turn_off", "turn_on"]
]
actions = await async_get_device_automations(
hass, DeviceAutomationType.ACTION, device_entry.id
)
assert_lists_same(actions, expected_actions)
@pytest.mark.parametrize(
"hidden_by,entity_category",
(
(entity_registry.RegistryEntryHider.INTEGRATION, None),
(entity_registry.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 = [
{
"domain": DOMAIN,
"type": "turn_off",
"type": action,
"device_id": device_entry.id,
"entity_id": "NEW_DOMAIN.test_5678",
},
"entity_id": f"{DOMAIN}.test_5678",
"metadata": {"secondary": True},
}
for action in ["turn_off", "turn_on", "toggle"]
]
actions = await async_get_device_automations(
hass, DeviceAutomationType.ACTION, device_entry.id