1
0
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:
Erik Montnemery
2022-04-20 21:41:59 +02:00
committed by GitHub
parent 7c0b0f7cc1
commit 150f173eed
18 changed files with 800 additions and 95 deletions

View File

@@ -10,11 +10,14 @@ from homeassistant.components.binary_sensor.device_condition import ENTITY_CONDI
from homeassistant.components.device_automation import DeviceAutomationType
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,
@@ -71,6 +74,7 @@ async def test_get_conditions(hass, device_reg, entity_reg, enable_custom_integr
"type": condition["type"],
"device_id": device_entry.id,
"entity_id": platform.ENTITIES[device_class].entity_id,
"metadata": {"secondary": False},
}
for device_class in BinarySensorDeviceClass
for condition in ENTITY_CONDITIONS[device_class]
@@ -78,7 +82,55 @@ async def test_get_conditions(hass, device_reg, entity_reg, enable_custom_integr
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_on", "is_off"]
]
conditions = await async_get_device_automations(
hass, DeviceAutomationType.CONDITION, device_entry.id
)
assert_lists_same(conditions, expected_conditions)
async def test_get_conditions_no_state(hass, device_reg, entity_reg):
@@ -108,6 +160,7 @@ async def test_get_conditions_no_state(hass, device_reg, entity_reg):
"type": condition["type"],
"device_id": device_entry.id,
"entity_id": entity_ids[device_class],
"metadata": {"secondary": False},
}
for device_class in BinarySensorDeviceClass
for condition in ENTITY_CONDITIONS[device_class]