mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Mark device conditions from hidden or auxiliary entities as secondary (#70333)
This commit is contained in:
@@ -9,11 +9,14 @@ from homeassistant.components.device_automation import DeviceAutomationType
|
||||
from homeassistant.components.switch import DOMAIN
|
||||
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
|
||||
from homeassistant.helpers import device_registry
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.common import (
|
||||
MockConfigEntry,
|
||||
assert_lists_same,
|
||||
async_get_device_automation_capabilities,
|
||||
async_get_device_automations,
|
||||
async_mock_service,
|
||||
@@ -54,22 +57,65 @@ async def test_get_conditions(hass, device_reg, entity_reg):
|
||||
{
|
||||
"condition": "device",
|
||||
"domain": DOMAIN,
|
||||
"type": "is_off",
|
||||
"type": condition,
|
||||
"device_id": device_entry.id,
|
||||
"entity_id": f"{DOMAIN}.test_5678",
|
||||
},
|
||||
{
|
||||
"condition": "device",
|
||||
"domain": DOMAIN,
|
||||
"type": "is_on",
|
||||
"device_id": device_entry.id,
|
||||
"entity_id": f"{DOMAIN}.test_5678",
|
||||
},
|
||||
"metadata": {"secondary": False},
|
||||
}
|
||||
for condition in ["is_off", "is_on"]
|
||||
]
|
||||
conditions = await async_get_device_automations(
|
||||
hass, DeviceAutomationType.CONDITION, device_entry.id
|
||||
)
|
||||
assert conditions == expected_conditions
|
||||
assert_lists_same(conditions, expected_conditions)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"hidden_by,entity_category",
|
||||
(
|
||||
(RegistryEntryHider.INTEGRATION, None),
|
||||
(RegistryEntryHider.USER, None),
|
||||
(None, EntityCategory.CONFIG),
|
||||
(None, EntityCategory.DIAGNOSTIC),
|
||||
),
|
||||
)
|
||||
async def test_get_conditions_hidden_auxiliary(
|
||||
hass,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
hidden_by,
|
||||
entity_category,
|
||||
):
|
||||
"""Test we get the expected conditions 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_conditions = [
|
||||
{
|
||||
"condition": "device",
|
||||
"domain": DOMAIN,
|
||||
"type": condition,
|
||||
"device_id": device_entry.id,
|
||||
"entity_id": f"{DOMAIN}.test_5678",
|
||||
"metadata": {"secondary": True},
|
||||
}
|
||||
for condition in ["is_off", "is_on"]
|
||||
]
|
||||
conditions = await async_get_device_automations(
|
||||
hass, DeviceAutomationType.CONDITION, device_entry.id
|
||||
)
|
||||
assert_lists_same(conditions, expected_conditions)
|
||||
|
||||
|
||||
async def test_get_condition_capabilities(hass, device_reg, entity_reg):
|
||||
|
||||
Reference in New Issue
Block a user