Mark device conditions from hidden or auxiliary entities as secondary (#70333)
This commit is contained in:
parent
7c0b0f7cc1
commit
150f173eed
18 changed files with 800 additions and 95 deletions
|
@ -7,6 +7,8 @@ from homeassistant.components.device_automation import DeviceAutomationType
|
|||
from homeassistant.components.humidifier import DOMAIN, const, device_condition
|
||||
from homeassistant.const import ATTR_MODE, STATE_OFF, STATE_ON
|
||||
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 (
|
||||
|
@ -83,6 +85,7 @@ async def test_get_conditions(
|
|||
"type": condition,
|
||||
"device_id": device_entry.id,
|
||||
"entity_id": f"{DOMAIN}.test_5678",
|
||||
"metadata": {"secondary": False},
|
||||
}
|
||||
for condition in basic_condition_types
|
||||
]
|
||||
|
@ -93,6 +96,7 @@ async def test_get_conditions(
|
|||
"type": condition,
|
||||
"device_id": device_entry.id,
|
||||
"entity_id": f"{DOMAIN}.test_5678",
|
||||
"metadata": {"secondary": False},
|
||||
}
|
||||
for condition in expected_condition_types
|
||||
]
|
||||
|
@ -102,6 +106,54 @@ async def test_get_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_if_state(hass, calls):
|
||||
"""Test for turn_on and turn_off conditions."""
|
||||
hass.states.async_set("humidifier.entity", STATE_ON, {ATTR_MODE: const.MODE_AWAY})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue