Clean up unnecessary registry mocks from Core tests (#87726)

This commit is contained in:
Franck Nijhof 2023-02-08 20:28:44 +01:00 committed by GitHub
parent 899adef590
commit 51a9f65a01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 882 additions and 1455 deletions

View file

@ -14,7 +14,7 @@ from homeassistant.const import (
STATE_ALARM_TRIGGERED, STATE_ALARM_TRIGGERED,
STATE_UNKNOWN, STATE_UNKNOWN,
) )
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -24,24 +24,10 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"set_state,features_reg,features_state,expected_action_types", "set_state,features_reg,features_state,expected_action_types",
[ [
@ -95,8 +81,8 @@ def entity_reg(hass):
) )
async def test_get_actions( async def test_get_actions(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
features_reg, features_reg,
features_state, features_state,
@ -105,11 +91,11 @@ async def test_get_actions(
"""Test we get the expected actions from a alarm_control_panel.""" """Test we get the expected actions from a alarm_control_panel."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -148,19 +134,19 @@ async def test_get_actions(
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -186,15 +172,17 @@ async def test_get_actions_hidden_auxiliary(
assert_lists_same(actions, expected_actions) assert_lists_same(actions, expected_actions)
async def test_get_actions_arm_night_only(hass, device_reg, entity_reg): async def test_get_actions_arm_night_only(hass, device_registry, entity_registry):
"""Test we get the expected actions from a alarm_control_panel.""" """Test we get the expected actions from a alarm_control_panel."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
hass.states.async_set( hass.states.async_set(
"alarm_control_panel.test_5678", "attributes", {"supported_features": 4} "alarm_control_panel.test_5678", "attributes", {"supported_features": 4}
) )
@ -221,7 +209,7 @@ async def test_get_actions_arm_night_only(hass, device_reg, entity_reg):
async def test_get_action_capabilities( async def test_get_action_capabilities(
hass, device_reg, entity_reg, enable_custom_integrations hass, device_registry, entity_registry, enable_custom_integrations
): ):
"""Test we get the expected capabilities from a sensor trigger.""" """Test we get the expected capabilities from a sensor trigger."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
@ -231,11 +219,11 @@ async def test_get_action_capabilities(
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
platform.ENTITIES["no_arm_code"].unique_id, platform.ENTITIES["no_arm_code"].unique_id,
@ -265,7 +253,7 @@ async def test_get_action_capabilities(
async def test_get_action_capabilities_arm_code( async def test_get_action_capabilities_arm_code(
hass, device_reg, entity_reg, enable_custom_integrations hass, device_registry, entity_registry, enable_custom_integrations
): ):
"""Test we get the expected capabilities from a sensor trigger.""" """Test we get the expected capabilities from a sensor trigger."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
@ -275,11 +263,11 @@ async def test_get_action_capabilities_arm_code(
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
platform.ENTITIES["arm_code"].unique_id, platform.ENTITIES["arm_code"].unique_id,

View file

@ -13,7 +13,7 @@ from homeassistant.const import (
STATE_ALARM_DISARMED, STATE_ALARM_DISARMED,
STATE_ALARM_TRIGGERED, STATE_ALARM_TRIGGERED,
) )
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -23,24 +23,10 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
@ -86,8 +72,8 @@ def calls(hass):
) )
async def test_get_conditions( async def test_get_conditions(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
features_reg, features_reg,
features_state, features_state,
@ -96,11 +82,11 @@ async def test_get_conditions(
"""Test we get the expected conditions from a alarm_control_panel.""" """Test we get the expected conditions from a alarm_control_panel."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -154,19 +140,19 @@ async def test_get_conditions(
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -15,7 +15,7 @@ from homeassistant.const import (
STATE_ALARM_PENDING, STATE_ALARM_PENDING,
STATE_ALARM_TRIGGERED, STATE_ALARM_TRIGGERED,
) )
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -28,24 +28,10 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
@ -89,8 +75,8 @@ def calls(hass):
) )
async def test_get_triggers( async def test_get_triggers(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
features_reg, features_reg,
features_state, features_state,
@ -99,11 +85,11 @@ async def test_get_triggers(
"""Test we get the expected triggers from an alarm_control_panel.""" """Test we get the expected triggers from an alarm_control_panel."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -146,19 +132,19 @@ async def test_get_triggers(
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -183,15 +169,17 @@ async def test_get_triggers_hidden_auxiliary(
assert_lists_same(triggers, expected_triggers) assert_lists_same(triggers, expected_triggers)
async def test_get_trigger_capabilities(hass, device_reg, entity_reg): async def test_get_trigger_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from an alarm_control_panel.""" """Test we get the expected capabilities from an alarm_control_panel."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
hass.states.async_set( hass.states.async_set(
"alarm_control_panel.test_5678", "attributes", {"supported_features": 15} "alarm_control_panel.test_5678", "attributes", {"supported_features": 15}
) )

View file

@ -9,7 +9,7 @@ from homeassistant.components.binary_sensor import DOMAIN, BinarySensorDeviceCla
from homeassistant.components.binary_sensor.device_condition import ENTITY_CONDITIONS from homeassistant.components.binary_sensor.device_condition import ENTITY_CONDITIONS
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -21,31 +21,19 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_conditions(hass, device_reg, entity_reg, enable_custom_integrations): async def test_get_conditions(
hass, device_registry, entity_registry, enable_custom_integrations
):
"""Test we get the expected conditions from a binary_sensor.""" """Test we get the expected conditions from a binary_sensor."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init() platform.init()
@ -54,12 +42,12 @@ async def test_get_conditions(hass, device_reg, entity_reg, enable_custom_integr
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
for device_class in BinarySensorDeviceClass: for device_class in BinarySensorDeviceClass:
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
platform.ENTITIES[device_class].unique_id, platform.ENTITIES[device_class].unique_id,
@ -95,19 +83,19 @@ async def test_get_conditions(hass, device_reg, entity_reg, enable_custom_integr
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -132,17 +120,17 @@ async def test_get_conditions_hidden_auxiliary(
assert_lists_same(conditions, expected_conditions) assert_lists_same(conditions, expected_conditions)
async def test_get_conditions_no_state(hass, device_reg, entity_reg): async def test_get_conditions_no_state(hass, device_registry, entity_registry):
"""Test we get the expected conditions from a binary_sensor.""" """Test we get the expected conditions from a binary_sensor."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_ids = {} entity_ids = {}
for device_class in BinarySensorDeviceClass: for device_class in BinarySensorDeviceClass:
entity_ids[device_class] = entity_reg.async_get_or_create( entity_ids[device_class] = entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
f"5678_{device_class}", f"5678_{device_class}",
@ -170,15 +158,17 @@ async def test_get_conditions_no_state(hass, device_reg, entity_reg):
assert conditions == expected_conditions assert conditions == expected_conditions
async def test_get_condition_capabilities(hass, device_reg, entity_reg): async def test_get_condition_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a binary_sensor condition.""" """Test we get the expected capabilities from a binary_sensor condition."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_capabilities = { expected_capabilities = {
"extra_fields": [ "extra_fields": [
{"name": "for", "optional": True, "type": "positive_time_period_dict"} {"name": "for", "optional": True, "type": "positive_time_period_dict"}

View file

@ -8,7 +8,7 @@ from homeassistant.components.binary_sensor import DOMAIN, BinarySensorDeviceCla
from homeassistant.components.binary_sensor.device_trigger import ENTITY_TRIGGERS from homeassistant.components.binary_sensor.device_trigger import ENTITY_TRIGGERS
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -21,31 +21,19 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_triggers(hass, device_reg, entity_reg, enable_custom_integrations): async def test_get_triggers(
hass, device_registry, entity_registry, enable_custom_integrations
):
"""Test we get the expected triggers from a binary_sensor.""" """Test we get the expected triggers from a binary_sensor."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init() platform.init()
@ -54,12 +42,12 @@ async def test_get_triggers(hass, device_reg, entity_reg, enable_custom_integrat
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
for device_class in BinarySensorDeviceClass: for device_class in BinarySensorDeviceClass:
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
platform.ENTITIES[device_class].unique_id, platform.ENTITIES[device_class].unique_id,
@ -95,19 +83,19 @@ async def test_get_triggers(hass, device_reg, entity_reg, enable_custom_integrat
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -132,7 +120,7 @@ async def test_get_triggers_hidden_auxiliary(
assert_lists_same(triggers, expected_triggers) assert_lists_same(triggers, expected_triggers)
async def test_get_triggers_no_state(hass, device_reg, entity_reg): async def test_get_triggers_no_state(hass, device_registry, entity_registry):
"""Test we get the expected triggers from a binary_sensor.""" """Test we get the expected triggers from a binary_sensor."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init() platform.init()
@ -140,12 +128,12 @@ async def test_get_triggers_no_state(hass, device_reg, entity_reg):
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
for device_class in BinarySensorDeviceClass: for device_class in BinarySensorDeviceClass:
entity_ids[device_class] = entity_reg.async_get_or_create( entity_ids[device_class] = entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
f"5678_{device_class}", f"5678_{device_class}",
@ -173,15 +161,17 @@ async def test_get_triggers_no_state(hass, device_reg, entity_reg):
assert_lists_same(triggers, expected_triggers) assert_lists_same(triggers, expected_triggers)
async def test_get_trigger_capabilities(hass, device_reg, entity_reg): async def test_get_trigger_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a binary_sensor trigger.""" """Test we get the expected capabilities from a binary_sensor trigger."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_capabilities = { expected_capabilities = {
"extra_fields": [ "extra_fields": [
{"name": "for", "optional": True, "type": "positive_time_period_dict"} {"name": "for", "optional": True, "type": "positive_time_period_dict"}

View file

@ -5,7 +5,7 @@ from homeassistant.components import automation
from homeassistant.components.button import DOMAIN from homeassistant.components.button import DOMAIN
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry, entity_registry from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -14,36 +14,24 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
@pytest.fixture
def device_reg(hass: HomeAssistant) -> device_registry.DeviceRegistry:
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass: HomeAssistant) -> entity_registry.EntityRegistry:
"""Return an empty, loaded, registry."""
return mock_registry(hass)
async def test_get_actions( async def test_get_actions(
hass: HomeAssistant, hass: HomeAssistant,
device_reg: device_registry.DeviceRegistry, device_registry: dr.DeviceRegistry,
entity_reg: entity_registry.EntityRegistry, entity_registry: er.EntityRegistry,
) -> None: ) -> None:
"""Test we get the expected actions from a button.""" """Test we get the expected actions from a button."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_actions = [ expected_actions = [
{ {
"domain": DOMAIN, "domain": DOMAIN,
@ -62,27 +50,27 @@ async def test_get_actions(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"hidden_by,entity_category", "hidden_by,entity_category",
( (
(entity_registry.RegistryEntryHider.INTEGRATION, None), (er.RegistryEntryHider.INTEGRATION, None),
(entity_registry.RegistryEntryHider.USER, None), (er.RegistryEntryHider.USER, None),
(None, EntityCategory.CONFIG), (None, EntityCategory.CONFIG),
(None, EntityCategory.DIAGNOSTIC), (None, EntityCategory.DIAGNOSTIC),
), ),
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass: HomeAssistant,
device_reg, device_registry: dr.DeviceRegistry,
entity_reg, entity_registry: er.EntityRegistry,
hidden_by, hidden_by: er.RegistryEntryHider | None,
entity_category, entity_category: EntityCategory | None,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -7,9 +7,8 @@ from homeassistant.components import automation
from homeassistant.components.button import DOMAIN from homeassistant.components.button import DOMAIN
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import EntityRegistry, RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import ( from tests.common import (
@ -17,23 +16,9 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
@pytest.fixture
def device_reg(hass: HomeAssistant) -> device_registry.DeviceRegistry:
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass: HomeAssistant) -> EntityRegistry:
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass: HomeAssistant) -> list[ServiceCall]: def calls(hass: HomeAssistant) -> list[ServiceCall]:
"""Track calls to a mock service.""" """Track calls to a mock service."""
@ -42,17 +27,19 @@ def calls(hass: HomeAssistant) -> list[ServiceCall]:
async def test_get_triggers( async def test_get_triggers(
hass: HomeAssistant, hass: HomeAssistant,
device_reg: device_registry.DeviceRegistry, device_registry: dr.DeviceRegistry,
entity_reg: EntityRegistry, entity_registry: er.EntityRegistry,
) -> None: ) -> None:
"""Test we get the expected triggers from a button.""" """Test we get the expected triggers from a button."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_triggers = [ expected_triggers = [
{ {
"platform": "device", "platform": "device",
@ -72,27 +59,27 @@ async def test_get_triggers(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"hidden_by,entity_category", "hidden_by,entity_category",
( (
(RegistryEntryHider.INTEGRATION, None), (er.RegistryEntryHider.INTEGRATION, None),
(RegistryEntryHider.USER, None), (er.RegistryEntryHider.USER, None),
(None, EntityCategory.CONFIG), (None, EntityCategory.CONFIG),
(None, EntityCategory.DIAGNOSTIC), (None, EntityCategory.DIAGNOSTIC),
), ),
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry: dr.DeviceRegistry,
entity_reg, entity_registry: er.EntityRegistry,
hidden_by, hidden_by: er.RegistryEntryHider | None,
entity_category, entity_category: EntityCategory | None,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -6,7 +6,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.climate import DOMAIN, HVACMode, const, device_action from homeassistant.components.climate import DOMAIN, HVACMode, const, device_action
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, device_registry from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -16,24 +16,10 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"set_state,features_reg,features_state,expected_action_types", "set_state,features_reg,features_state,expected_action_types",
[ [
@ -55,8 +41,8 @@ def entity_reg(hass):
) )
async def test_get_actions( async def test_get_actions(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
features_reg, features_reg,
features_state, features_state,
@ -65,11 +51,11 @@ async def test_get_actions(
"""Test we get the expected actions from a climate.""" """Test we get the expected actions from a climate."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -111,19 +97,19 @@ async def test_get_actions(
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -272,8 +258,8 @@ async def test_action(hass: HomeAssistant) -> None:
) )
async def test_capabilities( async def test_capabilities(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
capabilities_reg, capabilities_reg,
capabilities_state, capabilities_state,
@ -283,11 +269,11 @@ async def test_capabilities(
"""Test getting capabilities.""" """Test getting capabilities."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -325,9 +311,7 @@ async def test_capabilities(
"action,capability_name", "action,capability_name",
[("set_hvac_mode", "hvac_mode"), ("set_preset_mode", "preset_mode")], [("set_hvac_mode", "hvac_mode"), ("set_preset_mode", "preset_mode")],
) )
async def test_capabilities_missing_entity( async def test_capabilities_missing_entity(hass, action, capability_name):
hass, device_reg, entity_reg, action, capability_name
):
"""Test getting capabilities.""" """Test getting capabilities."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)

View file

@ -5,7 +5,7 @@ import voluptuous_serialize
import homeassistant.components.automation as automation import homeassistant.components.automation as automation
from homeassistant.components.climate import DOMAIN, HVACMode, const, device_condition from homeassistant.components.climate import DOMAIN, HVACMode, const, device_condition
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.helpers import config_validation as cv, device_registry from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -15,24 +15,10 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
@ -60,8 +46,8 @@ def calls(hass):
) )
async def test_get_conditions( async def test_get_conditions(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
features_reg, features_reg,
features_state, features_state,
@ -70,11 +56,11 @@ async def test_get_conditions(
"""Test we get the expected conditions from a climate.""" """Test we get the expected conditions from a climate."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -114,19 +100,19 @@ async def test_get_conditions(
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -320,8 +306,8 @@ async def test_if_state(hass, calls):
) )
async def test_capabilities( async def test_capabilities(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
capabilities_reg, capabilities_reg,
capabilities_state, capabilities_state,
@ -331,11 +317,11 @@ async def test_capabilities(
"""Test getting capabilities.""" """Test getting capabilities."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -374,9 +360,7 @@ async def test_capabilities(
"condition,capability_name", "condition,capability_name",
[("is_hvac_mode", "hvac_mode"), ("is_preset_mode", "preset_mode")], [("is_hvac_mode", "hvac_mode"), ("is_preset_mode", "preset_mode")],
) )
async def test_capabilities_missing_entity( async def test_capabilities_missing_entity(hass, condition, capability_name):
hass, device_reg, entity_reg, condition, capability_name
):
"""Test getting capabilities.""" """Test getting capabilities."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)

View file

@ -13,7 +13,7 @@ from homeassistant.components.climate import (
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.const import UnitOfTemperature from homeassistant.const import UnitOfTemperature
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, device_registry from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -23,39 +23,27 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_triggers(hass, device_reg, entity_reg): async def test_get_triggers(hass, device_registry, entity_registry):
"""Test we get the expected triggers from a climate device.""" """Test we get the expected triggers from a climate device."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
entity_id = f"{DOMAIN}.test_5678" entity_id = f"{DOMAIN}.test_5678"
hass.states.async_set( hass.states.async_set(
entity_id, entity_id,
@ -98,19 +86,19 @@ async def test_get_triggers(hass, device_reg, entity_reg):
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -5,7 +5,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.cover import DOMAIN, CoverEntityFeature from homeassistant.components.cover import DOMAIN, CoverEntityFeature
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.const import CONF_PLATFORM from homeassistant.const import CONF_PLATFORM
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -16,24 +16,10 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"set_state,features_reg,features_state,expected_action_types", "set_state,features_reg,features_state,expected_action_types",
[ [
@ -57,8 +43,8 @@ def entity_reg(hass):
) )
async def test_get_actions( async def test_get_actions(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
features_reg, features_reg,
features_state, features_state,
@ -67,11 +53,11 @@ async def test_get_actions(
"""Test we get the expected actions from a cover.""" """Test we get the expected actions from a cover."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -112,19 +98,19 @@ async def test_get_actions(
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -151,7 +137,7 @@ async def test_get_actions_hidden_auxiliary(
async def test_get_action_capabilities( async def test_get_action_capabilities(
hass, device_reg, entity_reg, enable_custom_integrations hass, device_registry, entity_registry, enable_custom_integrations
): ):
"""Test we get the expected capabilities from a cover action.""" """Test we get the expected capabilities from a cover action."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
@ -176,11 +162,11 @@ async def test_get_action_capabilities(
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, "test", ent.unique_id, device_id=device_entry.id DOMAIN, "test", ent.unique_id, device_id=device_entry.id
) )
@ -198,7 +184,7 @@ async def test_get_action_capabilities(
async def test_get_action_capabilities_set_pos( async def test_get_action_capabilities_set_pos(
hass, device_reg, entity_reg, enable_custom_integrations hass, device_registry, entity_registry, enable_custom_integrations
): ):
"""Test we get the expected capabilities from a cover action.""" """Test we get the expected capabilities from a cover action."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
@ -209,11 +195,11 @@ async def test_get_action_capabilities_set_pos(
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, "test", ent.unique_id, device_id=device_entry.id DOMAIN, "test", ent.unique_id, device_id=device_entry.id
) )
@ -246,7 +232,7 @@ async def test_get_action_capabilities_set_pos(
async def test_get_action_capabilities_set_tilt_pos( async def test_get_action_capabilities_set_tilt_pos(
hass, device_reg, entity_reg, enable_custom_integrations hass, device_registry, entity_registry, enable_custom_integrations
): ):
"""Test we get the expected capabilities from a cover action.""" """Test we get the expected capabilities from a cover action."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
@ -257,11 +243,11 @@ async def test_get_action_capabilities_set_tilt_pos(
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, "test", ent.unique_id, device_id=device_entry.id DOMAIN, "test", ent.unique_id, device_id=device_entry.id
) )

View file

@ -12,7 +12,7 @@ from homeassistant.const import (
STATE_OPENING, STATE_OPENING,
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
) )
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -23,24 +23,10 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
@ -84,8 +70,8 @@ def calls(hass):
) )
async def test_get_conditions( async def test_get_conditions(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
features_reg, features_reg,
features_state, features_state,
@ -94,11 +80,11 @@ async def test_get_conditions(
"""Test we get the expected conditions from a cover.""" """Test we get the expected conditions from a cover."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -140,19 +126,19 @@ async def test_get_conditions(
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -179,7 +165,7 @@ async def test_get_conditions_hidden_auxiliary(
async def test_get_condition_capabilities( async def test_get_condition_capabilities(
hass, device_reg, entity_reg, enable_custom_integrations hass, device_registry, entity_registry, enable_custom_integrations
): ):
"""Test we get the expected capabilities from a cover condition.""" """Test we get the expected capabilities from a cover condition."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
@ -190,11 +176,11 @@ async def test_get_condition_capabilities(
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, "test", ent.unique_id, device_id=device_entry.id DOMAIN, "test", ent.unique_id, device_id=device_entry.id
) )
@ -210,7 +196,7 @@ async def test_get_condition_capabilities(
async def test_get_condition_capabilities_set_pos( async def test_get_condition_capabilities_set_pos(
hass, device_reg, entity_reg, enable_custom_integrations hass, device_registry, entity_registry, enable_custom_integrations
): ):
"""Test we get the expected capabilities from a cover condition.""" """Test we get the expected capabilities from a cover condition."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
@ -221,11 +207,11 @@ async def test_get_condition_capabilities_set_pos(
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, "test", ent.unique_id, device_id=device_entry.id DOMAIN, "test", ent.unique_id, device_id=device_entry.id
) )
@ -264,7 +250,7 @@ async def test_get_condition_capabilities_set_pos(
async def test_get_condition_capabilities_set_tilt_pos( async def test_get_condition_capabilities_set_tilt_pos(
hass, device_reg, entity_reg, enable_custom_integrations hass, device_registry, entity_registry, enable_custom_integrations
): ):
"""Test we get the expected capabilities from a cover condition.""" """Test we get the expected capabilities from a cover condition."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
@ -275,11 +261,11 @@ async def test_get_condition_capabilities_set_tilt_pos(
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, "test", ent.unique_id, device_id=device_entry.id DOMAIN, "test", ent.unique_id, device_id=device_entry.id
) )

View file

@ -13,7 +13,7 @@ from homeassistant.const import (
STATE_OPEN, STATE_OPEN,
STATE_OPENING, STATE_OPENING,
) )
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -26,24 +26,10 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
@ -83,8 +69,8 @@ def calls(hass):
) )
async def test_get_triggers( async def test_get_triggers(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
features_reg, features_reg,
features_state, features_state,
@ -93,11 +79,11 @@ async def test_get_triggers(
"""Test we get the expected triggers from a cover.""" """Test we get the expected triggers from a cover."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -141,19 +127,19 @@ async def test_get_triggers(
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -180,7 +166,7 @@ async def test_get_triggers_hidden_auxiliary(
async def test_get_trigger_capabilities( async def test_get_trigger_capabilities(
hass, device_reg, entity_reg, enable_custom_integrations hass, device_registry, entity_registry, enable_custom_integrations
): ):
"""Test we get the expected capabilities from a cover trigger.""" """Test we get the expected capabilities from a cover trigger."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
@ -191,11 +177,11 @@ async def test_get_trigger_capabilities(
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, "test", ent.unique_id, device_id=device_entry.id DOMAIN, "test", ent.unique_id, device_id=device_entry.id
) )
@ -215,7 +201,7 @@ async def test_get_trigger_capabilities(
async def test_get_trigger_capabilities_set_pos( async def test_get_trigger_capabilities_set_pos(
hass, device_reg, entity_reg, enable_custom_integrations hass, device_registry, entity_registry, enable_custom_integrations
): ):
"""Test we get the expected capabilities from a cover trigger.""" """Test we get the expected capabilities from a cover trigger."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
@ -226,11 +212,11 @@ async def test_get_trigger_capabilities_set_pos(
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, "test", ent.unique_id, device_id=device_entry.id DOMAIN, "test", ent.unique_id, device_id=device_entry.id
) )
@ -277,7 +263,7 @@ async def test_get_trigger_capabilities_set_pos(
async def test_get_trigger_capabilities_set_tilt_pos( async def test_get_trigger_capabilities_set_tilt_pos(
hass, device_reg, entity_reg, enable_custom_integrations hass, device_registry, entity_registry, enable_custom_integrations
): ):
"""Test we get the expected capabilities from a cover trigger.""" """Test we get the expected capabilities from a cover trigger."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
@ -288,11 +274,11 @@ async def test_get_trigger_capabilities_set_tilt_pos(
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, "test", ent.unique_id, device_id=device_entry.id DOMAIN, "test", ent.unique_id, device_id=device_entry.id
) )

View file

@ -15,7 +15,7 @@ from homeassistant.components.device_automation import (
from homeassistant.components.websocket_api.const import TYPE_RESULT from homeassistant.components.websocket_api.const import TYPE_RESULT
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -23,27 +23,13 @@ from tests.common import (
MockConfigEntry, MockConfigEntry,
MockModule, MockModule,
async_mock_service, async_mock_service,
mock_device_registry,
mock_integration, mock_integration,
mock_platform, mock_platform,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
from tests.typing import WebSocketGenerator from tests.typing import WebSocketGenerator
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def fake_integration(hass): def fake_integration(hass):
"""Set up a mock integration with device automation support.""" """Set up a mock integration with device automation support."""
@ -108,17 +94,17 @@ def fake_integration(hass):
async def test_websocket_get_actions( async def test_websocket_get_actions(
hass, hass_ws_client, device_reg, entity_reg, fake_integration hass, hass_ws_client, device_registry, entity_registry, fake_integration
): ):
"""Test we get the expected actions through websocket.""" """Test we get the expected actions through websocket."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
"fake_integration", "test", "5678", device_id=device_entry.id "fake_integration", "test", "5678", device_id=device_entry.id
) )
expected_actions = [ expected_actions = [
@ -159,17 +145,17 @@ async def test_websocket_get_actions(
async def test_websocket_get_conditions( async def test_websocket_get_conditions(
hass, hass_ws_client, device_reg, entity_reg, fake_integration hass, hass_ws_client, device_registry, entity_registry, fake_integration
): ):
"""Test we get the expected conditions through websocket.""" """Test we get the expected conditions through websocket."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
"fake_integration", "test", "5678", device_id=device_entry.id "fake_integration", "test", "5678", device_id=device_entry.id
) )
expected_conditions = [ expected_conditions = [
@ -209,17 +195,17 @@ async def test_websocket_get_conditions(
async def test_websocket_get_triggers( async def test_websocket_get_triggers(
hass, hass_ws_client, device_reg, entity_reg, fake_integration hass, hass_ws_client, device_registry, entity_registry, fake_integration
): ):
"""Test we get the expected triggers through websocket.""" """Test we get the expected triggers through websocket."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
"fake_integration", "test", "5678", device_id=device_entry.id "fake_integration", "test", "5678", device_id=device_entry.id
) )
expected_triggers = [ expected_triggers = [
@ -267,17 +253,17 @@ async def test_websocket_get_triggers(
async def test_websocket_get_action_capabilities( async def test_websocket_get_action_capabilities(
hass, hass_ws_client, device_reg, entity_reg, fake_integration hass, hass_ws_client, device_registry, entity_registry, fake_integration
): ):
"""Test we get the expected action capabilities through websocket.""" """Test we get the expected action capabilities through websocket."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
"fake_integration", "test", "5678", device_id=device_entry.id "fake_integration", "test", "5678", device_id=device_entry.id
) )
expected_capabilities = { expected_capabilities = {
@ -331,7 +317,7 @@ async def test_websocket_get_action_capabilities(
async def test_websocket_get_action_capabilities_unknown_domain( async def test_websocket_get_action_capabilities_unknown_domain(
hass, hass_ws_client, device_reg, entity_reg hass, hass_ws_client, device_registry, entity_registry
): ):
"""Test we get no action capabilities for a non existing domain.""" """Test we get no action capabilities for a non existing domain."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
@ -354,7 +340,7 @@ async def test_websocket_get_action_capabilities_unknown_domain(
async def test_websocket_get_action_capabilities_no_capabilities( async def test_websocket_get_action_capabilities_no_capabilities(
hass, hass_ws_client, device_reg, entity_reg, fake_integration hass, hass_ws_client, device_registry, entity_registry, fake_integration
): ):
"""Test we get no action capabilities for a domain which has none. """Test we get no action capabilities for a domain which has none.
@ -381,7 +367,7 @@ async def test_websocket_get_action_capabilities_no_capabilities(
async def test_websocket_get_action_capabilities_bad_action( async def test_websocket_get_action_capabilities_bad_action(
hass, hass_ws_client, device_reg, entity_reg, fake_integration hass, hass_ws_client, device_registry, entity_registry, fake_integration
): ):
"""Test we get no action capabilities when there is an error.""" """Test we get no action capabilities when there is an error."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
@ -411,17 +397,17 @@ async def test_websocket_get_action_capabilities_bad_action(
async def test_websocket_get_condition_capabilities( async def test_websocket_get_condition_capabilities(
hass, hass_ws_client, device_reg, entity_reg, fake_integration hass, hass_ws_client, device_registry, entity_registry, fake_integration
): ):
"""Test we get the expected condition capabilities through websocket.""" """Test we get the expected condition capabilities through websocket."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
"fake_integration", "test", "5678", device_id=device_entry.id "fake_integration", "test", "5678", device_id=device_entry.id
) )
expected_capabilities = { expected_capabilities = {
@ -475,7 +461,7 @@ async def test_websocket_get_condition_capabilities(
async def test_websocket_get_condition_capabilities_unknown_domain( async def test_websocket_get_condition_capabilities_unknown_domain(
hass, hass_ws_client, device_reg, entity_reg hass, hass_ws_client, device_registry, entity_registry
): ):
"""Test we get no condition capabilities for a non existing domain.""" """Test we get no condition capabilities for a non existing domain."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
@ -498,7 +484,7 @@ async def test_websocket_get_condition_capabilities_unknown_domain(
async def test_websocket_get_condition_capabilities_no_capabilities( async def test_websocket_get_condition_capabilities_no_capabilities(
hass, hass_ws_client, device_reg, entity_reg, fake_integration hass, hass_ws_client, device_registry, entity_registry, fake_integration
): ):
"""Test we get no condition capabilities for a domain which has none. """Test we get no condition capabilities for a domain which has none.
@ -529,7 +515,7 @@ async def test_websocket_get_condition_capabilities_no_capabilities(
async def test_websocket_get_condition_capabilities_bad_condition( async def test_websocket_get_condition_capabilities_bad_condition(
hass, hass_ws_client, device_reg, entity_reg, fake_integration hass, hass_ws_client, device_registry, entity_registry, fake_integration
): ):
"""Test we get no condition capabilities when there is an error.""" """Test we get no condition capabilities when there is an error."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
@ -563,17 +549,19 @@ async def test_websocket_get_condition_capabilities_bad_condition(
async def test_async_get_device_automations_single_device_trigger( async def test_async_get_device_automations_single_device_trigger(
hass, device_reg, entity_reg hass, device_registry, entity_registry
): ):
"""Test we get can fetch the triggers for a device id.""" """Test we get can fetch the triggers for a device id."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
"light", "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create("light", "test", "5678", device_id=device_entry.id)
result = await device_automation.async_get_device_automations( result = await device_automation.async_get_device_automations(
hass, device_automation.DeviceAutomationType.TRIGGER, [device_entry.id] hass, device_automation.DeviceAutomationType.TRIGGER, [device_entry.id]
) )
@ -582,17 +570,19 @@ async def test_async_get_device_automations_single_device_trigger(
async def test_async_get_device_automations_all_devices_trigger( async def test_async_get_device_automations_all_devices_trigger(
hass, device_reg, entity_reg hass, device_registry, entity_registry
): ):
"""Test we get can fetch all the triggers when no device id is passed.""" """Test we get can fetch all the triggers when no device id is passed."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
"light", "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create("light", "test", "5678", device_id=device_entry.id)
result = await device_automation.async_get_device_automations( result = await device_automation.async_get_device_automations(
hass, device_automation.DeviceAutomationType.TRIGGER hass, device_automation.DeviceAutomationType.TRIGGER
) )
@ -601,17 +591,19 @@ async def test_async_get_device_automations_all_devices_trigger(
async def test_async_get_device_automations_all_devices_condition( async def test_async_get_device_automations_all_devices_condition(
hass, device_reg, entity_reg hass, device_registry, entity_registry
): ):
"""Test we get can fetch all the conditions when no device id is passed.""" """Test we get can fetch all the conditions when no device id is passed."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
"light", "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create("light", "test", "5678", device_id=device_entry.id)
result = await device_automation.async_get_device_automations( result = await device_automation.async_get_device_automations(
hass, device_automation.DeviceAutomationType.CONDITION hass, device_automation.DeviceAutomationType.CONDITION
) )
@ -620,17 +612,19 @@ async def test_async_get_device_automations_all_devices_condition(
async def test_async_get_device_automations_all_devices_action( async def test_async_get_device_automations_all_devices_action(
hass, device_reg, entity_reg hass, device_registry, entity_registry
): ):
"""Test we get can fetch all the actions when no device id is passed.""" """Test we get can fetch all the actions when no device id is passed."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
"light", "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create("light", "test", "5678", device_id=device_entry.id)
result = await device_automation.async_get_device_automations( result = await device_automation.async_get_device_automations(
hass, device_automation.DeviceAutomationType.ACTION hass, device_automation.DeviceAutomationType.ACTION
) )
@ -639,17 +633,19 @@ async def test_async_get_device_automations_all_devices_action(
async def test_async_get_device_automations_all_devices_action_exception_throw( async def test_async_get_device_automations_all_devices_action_exception_throw(
hass, device_reg, entity_reg, caplog hass, device_registry, entity_registry, caplog
): ):
"""Test we get can fetch all the actions when no device id is passed and can handle one throwing an exception.""" """Test we get can fetch all the actions when no device id is passed and can handle one throwing an exception."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
"light", "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create("light", "test", "5678", device_id=device_entry.id)
with patch( with patch(
"homeassistant.components.light.device_trigger.async_get_triggers", "homeassistant.components.light.device_trigger.async_get_triggers",
side_effect=KeyError, side_effect=KeyError,
@ -663,17 +659,17 @@ async def test_async_get_device_automations_all_devices_action_exception_throw(
async def test_websocket_get_trigger_capabilities( async def test_websocket_get_trigger_capabilities(
hass, hass_ws_client, device_reg, entity_reg, fake_integration hass, hass_ws_client, device_registry, entity_registry, fake_integration
): ):
"""Test we get the expected trigger capabilities through websocket.""" """Test we get the expected trigger capabilities through websocket."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
"fake_integration", "test", "5678", device_id=device_entry.id "fake_integration", "test", "5678", device_id=device_entry.id
) )
expected_capabilities = { expected_capabilities = {
@ -727,7 +723,7 @@ async def test_websocket_get_trigger_capabilities(
async def test_websocket_get_trigger_capabilities_unknown_domain( async def test_websocket_get_trigger_capabilities_unknown_domain(
hass, hass_ws_client, device_reg, entity_reg hass, hass_ws_client, device_registry, entity_registry
): ):
"""Test we get no trigger capabilities for a non existing domain.""" """Test we get no trigger capabilities for a non existing domain."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
@ -750,7 +746,7 @@ async def test_websocket_get_trigger_capabilities_unknown_domain(
async def test_websocket_get_trigger_capabilities_no_capabilities( async def test_websocket_get_trigger_capabilities_no_capabilities(
hass, hass_ws_client, device_reg, entity_reg, fake_integration hass, hass_ws_client, device_registry, entity_registry, fake_integration
): ):
"""Test we get no trigger capabilities for a domain which has none. """Test we get no trigger capabilities for a domain which has none.
@ -781,7 +777,7 @@ async def test_websocket_get_trigger_capabilities_no_capabilities(
async def test_websocket_get_trigger_capabilities_bad_trigger( async def test_websocket_get_trigger_capabilities_bad_trigger(
hass, hass_ws_client, device_reg, entity_reg, fake_integration hass, hass_ws_client, device_registry, entity_registry, fake_integration
): ):
"""Test we get no trigger capabilities when there is an error.""" """Test we get no trigger capabilities when there is an error."""
await async_setup_component(hass, "device_automation", {}) await async_setup_component(hass, "device_automation", {})
@ -870,7 +866,7 @@ async def test_automation_with_device_action(hass, caplog, fake_integration):
async def test_automation_with_dynamically_validated_action( async def test_automation_with_dynamically_validated_action(
hass, caplog, device_reg, fake_integration hass, caplog, device_registry, fake_integration
): ):
"""Test device automation with an action which is dynamically validated.""" """Test device automation with an action which is dynamically validated."""
@ -881,9 +877,9 @@ async def test_automation_with_dynamically_validated_action(
config_entry = MockConfigEntry(domain="fake_integration", data={}) config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
assert await async_setup_component( assert await async_setup_component(
@ -953,7 +949,7 @@ async def test_automation_with_device_condition(hass, caplog, fake_integration):
async def test_automation_with_dynamically_validated_condition( async def test_automation_with_dynamically_validated_condition(
hass, caplog, device_reg, fake_integration hass, caplog, device_registry, fake_integration
): ):
"""Test device automation with a condition which is dynamically validated.""" """Test device automation with a condition which is dynamically validated."""
@ -964,9 +960,9 @@ async def test_automation_with_dynamically_validated_condition(
config_entry = MockConfigEntry(domain="fake_integration", data={}) config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
assert await async_setup_component( assert await async_setup_component(
@ -1046,7 +1042,7 @@ async def test_automation_with_device_trigger(hass, caplog, fake_integration):
async def test_automation_with_dynamically_validated_trigger( async def test_automation_with_dynamically_validated_trigger(
hass, caplog, device_reg, entity_reg, fake_integration hass, caplog, device_registry, entity_registry, fake_integration
): ):
"""Test device automation with a trigger which is dynamically validated.""" """Test device automation with a trigger which is dynamically validated."""
@ -1058,11 +1054,11 @@ async def test_automation_with_dynamically_validated_trigger(
config_entry = MockConfigEntry(domain="fake_integration", data={}) config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.state = config_entries.ConfigEntryState.LOADED config_entry.state = config_entries.ConfigEntryState.LOADED
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
"fake_integration", "test", "5678", device_id=device_entry.id "fake_integration", "test", "5678", device_id=device_entry.id
) )
@ -1395,7 +1391,7 @@ async def test_automation_with_unknown_device(hass, caplog, fake_integration):
async def test_automation_with_device_wrong_domain( async def test_automation_with_device_wrong_domain(
hass, caplog, device_reg, fake_integration hass, caplog, device_registry, fake_integration
): ):
"""Test device automation where the device doesn't have the right config entry.""" """Test device automation where the device doesn't have the right config entry."""
@ -1403,9 +1399,9 @@ async def test_automation_with_device_wrong_domain(
module = module_cache["fake_integration.device_trigger"] module = module_cache["fake_integration.device_trigger"]
module.async_validate_trigger_config = AsyncMock() module.async_validate_trigger_config = AsyncMock()
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id="not_fake_integration_config_entry", config_entry_id="not_fake_integration_config_entry",
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
assert await async_setup_component( assert await async_setup_component(
hass, hass,
@ -1432,7 +1428,7 @@ async def test_automation_with_device_wrong_domain(
async def test_automation_with_device_component_not_loaded( async def test_automation_with_device_component_not_loaded(
hass, caplog, device_reg, fake_integration hass, caplog, device_registry, fake_integration
): ):
"""Test device automation where the device's config entry is not loaded.""" """Test device automation where the device's config entry is not loaded."""
@ -1443,9 +1439,9 @@ async def test_automation_with_device_component_not_loaded(
config_entry = MockConfigEntry(domain="fake_integration", data={}) config_entry = MockConfigEntry(domain="fake_integration", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
assert await async_setup_component( assert await async_setup_component(
hass, hass,

View file

@ -5,7 +5,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.device_tracker import DOMAIN from homeassistant.components.device_tracker import DOMAIN
from homeassistant.const import STATE_HOME from homeassistant.const import STATE_HOME
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -15,39 +15,27 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_conditions(hass, device_reg, entity_reg): async def test_get_conditions(hass, device_registry, entity_registry):
"""Test we get the expected conditions from a device_tracker.""" """Test we get the expected conditions from a device_tracker."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_conditions = [ expected_conditions = [
{ {
"condition": "device", "condition": "device",
@ -76,19 +64,19 @@ async def test_get_conditions(hass, device_reg, entity_reg):
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -6,7 +6,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.device_tracker import DOMAIN, device_trigger from homeassistant.components.device_tracker import DOMAIN, device_trigger
import homeassistant.components.zone as zone import homeassistant.components.zone as zone
from homeassistant.helpers import config_validation as cv, device_registry from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -16,8 +16,6 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@ -28,18 +26,6 @@ HOME_LATITUDE = 32.880837
HOME_LONGITUDE = -117.237561 HOME_LONGITUDE = -117.237561
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
@ -65,15 +51,17 @@ def setup_zone(hass):
) )
async def test_get_triggers(hass, device_reg, entity_reg): async def test_get_triggers(hass, device_registry, entity_registry):
"""Test we get the expected triggers from a device_tracker.""" """Test we get the expected triggers from a device_tracker."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_triggers = [ expected_triggers = [
{ {
"platform": "device", "platform": "device",
@ -102,19 +90,19 @@ async def test_get_triggers(hass, device_reg, entity_reg):
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -229,15 +217,17 @@ async def test_if_fires_on_zone_change(hass, calls):
) )
async def test_get_trigger_capabilities(hass, device_reg, entity_reg): async def test_get_trigger_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a device_tracker trigger.""" """Test we get the expected capabilities from a device_tracker trigger."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
capabilities = await device_trigger.async_get_trigger_capabilities( capabilities = await device_trigger.async_get_trigger_capabilities(
hass, hass,
{ {

View file

@ -5,7 +5,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.fan import DOMAIN from homeassistant.components.fan import DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -15,33 +15,21 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture async def test_get_actions(hass, device_registry, entity_registry):
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
async def test_get_actions(hass, device_reg, entity_reg):
"""Test we get the expected actions from a fan.""" """Test we get the expected actions from a fan."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_actions = [] expected_actions = []
expected_actions += [ expected_actions += [
{ {
@ -70,19 +58,19 @@ async def test_get_actions(hass, device_reg, entity_reg):
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -5,7 +5,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.fan import DOMAIN from homeassistant.components.fan import DOMAIN
from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -15,39 +15,27 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_conditions(hass, device_reg, entity_reg): async def test_get_conditions(hass, device_registry, entity_registry):
"""Test we get the expected conditions from a fan.""" """Test we get the expected conditions from a fan."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_conditions = [ expected_conditions = [
{ {
"condition": "device", "condition": "device",
@ -76,19 +64,19 @@ async def test_get_conditions(hass, device_reg, entity_reg):
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -7,7 +7,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.fan import DOMAIN from homeassistant.components.fan import DOMAIN
from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -20,39 +20,27 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_triggers(hass, device_reg, entity_reg): async def test_get_triggers(hass, device_registry, entity_registry):
"""Test we get the expected triggers from a fan.""" """Test we get the expected triggers from a fan."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_triggers = [ expected_triggers = [
{ {
"platform": "device", "platform": "device",
@ -81,19 +69,19 @@ async def test_get_triggers(hass, device_reg, entity_reg):
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -118,15 +106,17 @@ async def test_get_triggers_hidden_auxiliary(
assert_lists_same(triggers, expected_triggers) assert_lists_same(triggers, expected_triggers)
async def test_get_trigger_capabilities(hass, device_reg, entity_reg): async def test_get_trigger_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a switch trigger.""" """Test we get the expected capabilities from a switch trigger."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_capabilities = { expected_capabilities = {
"extra_fields": [ "extra_fields": [
{"name": "for", "optional": True, "type": "positive_time_period_dict"} {"name": "for", "optional": True, "type": "positive_time_period_dict"}

View file

@ -1,19 +1,11 @@
"""The tests for local file sensor platform.""" """The tests for local file sensor platform."""
from unittest.mock import Mock, patch from unittest.mock import Mock, patch
import pytest
from homeassistant.const import STATE_UNKNOWN from homeassistant.const import STATE_UNKNOWN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import get_fixture_path, mock_registry from tests.common import get_fixture_path
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@patch("os.path.isfile", Mock(return_value=True)) @patch("os.path.isfile", Mock(return_value=True))

View file

@ -32,7 +32,7 @@ from homeassistant.const import (
import homeassistant.core as ha import homeassistant.core as ha
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError, Unauthorized from homeassistant.exceptions import HomeAssistantError, Unauthorized
from homeassistant.helpers import entity from homeassistant.helpers import entity, entity_registry as er
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import ( from tests.common import (
@ -40,7 +40,6 @@ from tests.common import (
async_capture_events, async_capture_events,
async_mock_service, async_mock_service,
get_test_home_assistant, get_test_home_assistant,
mock_registry,
mock_service, mock_service,
patch_yaml_files, patch_yaml_files,
) )
@ -379,18 +378,19 @@ async def test_not_allowing_recursion(
), service ), service
async def test_reload_config_entry_by_entity_id(hass: HomeAssistant) -> None: async def test_reload_config_entry_by_entity_id(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test being able to reload a config entry by entity_id.""" """Test being able to reload a config entry by entity_id."""
await async_setup_component(hass, "homeassistant", {}) await async_setup_component(hass, "homeassistant", {})
entity_reg = mock_registry(hass)
entry1 = MockConfigEntry(domain="mockdomain") entry1 = MockConfigEntry(domain="mockdomain")
entry1.add_to_hass(hass) entry1.add_to_hass(hass)
entry2 = MockConfigEntry(domain="mockdomain") entry2 = MockConfigEntry(domain="mockdomain")
entry2.add_to_hass(hass) entry2.add_to_hass(hass)
reg_entity1 = entity_reg.async_get_or_create( reg_entity1 = entity_registry.async_get_or_create(
"binary_sensor", "powerwall", "battery_charging", config_entry=entry1 "binary_sensor", "powerwall", "battery_charging", config_entry=entry1
) )
reg_entity2 = entity_reg.async_get_or_create( reg_entity2 = entity_registry.async_get_or_create(
"binary_sensor", "powerwall", "battery_status", config_entry=entry2 "binary_sensor", "powerwall", "battery_status", config_entry=entry2
) )
with patch( with patch(

View file

@ -7,7 +7,7 @@ from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.humidifier import DOMAIN, const, device_action from homeassistant.components.humidifier import DOMAIN, const, device_action
from homeassistant.const import STATE_ON from homeassistant.const import STATE_ON
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, device_registry from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -17,24 +17,10 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"set_state,features_reg,features_state,expected_action_types", "set_state,features_reg,features_state,expected_action_types",
[ [
@ -46,8 +32,8 @@ def entity_reg(hass):
) )
async def test_get_actions( async def test_get_actions(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
features_reg, features_reg,
features_state, features_state,
@ -56,11 +42,11 @@ async def test_get_actions(
"""Test we get the expected actions from a humidifier.""" """Test we get the expected actions from a humidifier."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -110,19 +96,19 @@ async def test_get_actions(
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -366,8 +352,8 @@ async def test_action(hass: HomeAssistant) -> None:
) )
async def test_capabilities( async def test_capabilities(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
capabilities_reg, capabilities_reg,
capabilities_state, capabilities_state,
@ -377,11 +363,11 @@ async def test_capabilities(
"""Test getting capabilities.""" """Test getting capabilities."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -422,9 +408,7 @@ async def test_capabilities(
("set_mode", "mode", {"type": "select", "options": []}), ("set_mode", "mode", {"type": "select", "options": []}),
], ],
) )
async def test_capabilities_missing_entity( async def test_capabilities_missing_entity(hass, action, capability_name, extra):
hass, device_reg, entity_reg, action, capability_name, extra
):
"""Test getting capabilities.""" """Test getting capabilities."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)

View file

@ -6,7 +6,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.humidifier import DOMAIN, const, device_condition from homeassistant.components.humidifier import DOMAIN, const, device_condition
from homeassistant.const import ATTR_MODE, STATE_OFF, STATE_ON from homeassistant.const import ATTR_MODE, STATE_OFF, STATE_ON
from homeassistant.helpers import config_validation as cv, device_registry from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -16,24 +16,10 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
@ -51,8 +37,8 @@ def calls(hass):
) )
async def test_get_conditions( async def test_get_conditions(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
features_reg, features_reg,
features_state, features_state,
@ -61,11 +47,11 @@ async def test_get_conditions(
"""Test we get the expected conditions from a humidifier.""" """Test we get the expected conditions from a humidifier."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -117,19 +103,19 @@ async def test_get_conditions(
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -371,8 +357,8 @@ async def test_if_state(hass, calls):
) )
async def test_capabilities( async def test_capabilities(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
capabilities_reg, capabilities_reg,
capabilities_state, capabilities_state,
@ -382,11 +368,11 @@ async def test_capabilities(
"""Test getting capabilities.""" """Test getting capabilities."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -426,9 +412,7 @@ async def test_capabilities(
("is_mode", "mode", {"type": "select", "options": []}), ("is_mode", "mode", {"type": "select", "options": []}),
], ],
) )
async def test_capabilities_missing_entity( async def test_capabilities_missing_entity(hass, condition, capability_name, extra):
hass, device_reg, entity_reg, condition, capability_name, extra
):
"""Test getting capabilities.""" """Test getting capabilities."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)

View file

@ -9,7 +9,7 @@ from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.humidifier import DOMAIN, const, device_trigger from homeassistant.components.humidifier import DOMAIN, const, device_trigger
from homeassistant.const import ATTR_MODE, ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON from homeassistant.const import ATTR_MODE, ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, device_registry from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -21,39 +21,27 @@ from tests.common import (
async_fire_time_changed, async_fire_time_changed,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_triggers(hass, device_reg, entity_reg): async def test_get_triggers(hass, device_registry, entity_registry):
"""Test we get the expected triggers from a humidifier device.""" """Test we get the expected triggers from a humidifier device."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
entity_id = f"{DOMAIN}.test_5678" entity_id = f"{DOMAIN}.test_5678"
hass.states.async_set( hass.states.async_set(
entity_id, entity_id,
@ -98,19 +86,19 @@ async def test_get_triggers(hass, device_reg, entity_reg):
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -12,7 +12,7 @@ from homeassistant.components.light import (
LightEntityFeature, LightEntityFeature,
) )
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -23,39 +23,25 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_actions(hass, device_reg, entity_reg): async def test_get_actions(hass, device_registry, entity_registry):
"""Test we get the expected actions from a light.""" """Test we get the expected actions from a light."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -98,19 +84,19 @@ async def test_get_actions(hass, device_reg, entity_reg):
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -137,16 +123,16 @@ async def test_get_actions_hidden_auxiliary(
assert_lists_same(actions, expected_actions) assert_lists_same(actions, expected_actions)
async def test_get_action_capabilities(hass, device_reg, entity_reg): async def test_get_action_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a light action.""" """Test we get the expected capabilities from a light action."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
# Test with entity without optional capabilities # Test with entity without optional capabilities
entity_id = entity_reg.async_get_or_create( entity_id = entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -165,7 +151,7 @@ async def test_get_action_capabilities(hass, device_reg, entity_reg):
assert capabilities == {"extra_fields": []} assert capabilities == {"extra_fields": []}
# Test without entity # Test without entity
entity_reg.async_remove(entity_id) entity_registry.async_remove(entity_id)
for action in actions: for action in actions:
capabilities = await async_get_device_automation_capabilities( capabilities = await async_get_device_automation_capabilities(
hass, DeviceAutomationType.ACTION, action hass, DeviceAutomationType.ACTION, action
@ -266,8 +252,8 @@ async def test_get_action_capabilities(hass, device_reg, entity_reg):
) )
async def test_get_action_capabilities_features( async def test_get_action_capabilities_features(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
expected_actions, expected_actions,
supported_features_reg, supported_features_reg,
@ -279,11 +265,11 @@ async def test_get_action_capabilities_features(
"""Test we get the expected capabilities from a light action.""" """Test we get the expected capabilities from a light action."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_id = entity_reg.async_get_or_create( entity_id = entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -8,7 +8,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.light import DOMAIN from homeassistant.components.light import DOMAIN
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -20,39 +20,27 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_conditions(hass, device_reg, entity_reg): async def test_get_conditions(hass, device_registry, entity_registry):
"""Test we get the expected conditions from a light.""" """Test we get the expected conditions from a light."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_conditions = [ expected_conditions = [
{ {
"condition": "device", "condition": "device",
@ -81,19 +69,19 @@ async def test_get_conditions(hass, device_reg, entity_reg):
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -118,15 +106,17 @@ async def test_get_conditions_hidden_auxiliary(
assert_lists_same(conditions, expected_conditions) assert_lists_same(conditions, expected_conditions)
async def test_get_condition_capabilities(hass, device_reg, entity_reg): async def test_get_condition_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a light condition.""" """Test we get the expected capabilities from a light condition."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_capabilities = { expected_capabilities = {
"extra_fields": [ "extra_fields": [
{"name": "for", "optional": True, "type": "positive_time_period_dict"} {"name": "for", "optional": True, "type": "positive_time_period_dict"}

View file

@ -7,7 +7,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.light import DOMAIN from homeassistant.components.light import DOMAIN
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -20,39 +20,27 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_triggers(hass, device_reg, entity_reg): async def test_get_triggers(hass, device_registry, entity_registry):
"""Test we get the expected triggers from a light.""" """Test we get the expected triggers from a light."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_triggers = [ expected_triggers = [
{ {
"platform": "device", "platform": "device",
@ -81,19 +69,19 @@ async def test_get_triggers(hass, device_reg, entity_reg):
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -118,15 +106,17 @@ async def test_get_triggers_hidden_auxiliary(
assert_lists_same(triggers, expected_triggers) assert_lists_same(triggers, expected_triggers)
async def test_get_trigger_capabilities(hass, device_reg, entity_reg): async def test_get_trigger_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a light trigger.""" """Test we get the expected capabilities from a light trigger."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_capabilities = { expected_capabilities = {
"extra_fields": [ "extra_fields": [
{"name": "for", "optional": True, "type": "positive_time_period_dict"} {"name": "for", "optional": True, "type": "positive_time_period_dict"}

View file

@ -5,7 +5,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.lock import DOMAIN, LockEntityFeature from homeassistant.components.lock import DOMAIN, LockEntityFeature
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -15,24 +15,10 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"set_state,features_reg,features_state,expected_action_types", "set_state,features_reg,features_state,expected_action_types",
[ [
@ -44,8 +30,8 @@ def entity_reg(hass):
) )
async def test_get_actions( async def test_get_actions(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
features_reg, features_reg,
features_state, features_state,
@ -54,11 +40,11 @@ async def test_get_actions(
"""Test we get the expected actions from a lock.""" """Test we get the expected actions from a lock."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -108,19 +94,19 @@ async def test_get_actions(
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -11,7 +11,7 @@ from homeassistant.const import (
STATE_UNLOCKED, STATE_UNLOCKED,
STATE_UNLOCKING, STATE_UNLOCKING,
) )
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -21,39 +21,27 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_conditions(hass, device_reg, entity_reg): async def test_get_conditions(hass, device_registry, entity_registry):
"""Test we get the expected conditions from a lock.""" """Test we get the expected conditions from a lock."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_conditions = [ expected_conditions = [
{ {
"condition": "device", "condition": "device",
@ -88,19 +76,19 @@ async def test_get_conditions(hass, device_reg, entity_reg):
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -13,7 +13,7 @@ from homeassistant.const import (
STATE_UNLOCKED, STATE_UNLOCKED,
STATE_UNLOCKING, STATE_UNLOCKING,
) )
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -26,39 +26,27 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_triggers(hass, device_reg, entity_reg): async def test_get_triggers(hass, device_registry, entity_registry):
"""Test we get the expected triggers from a lock.""" """Test we get the expected triggers from a lock."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_triggers = [ expected_triggers = [
{ {
"platform": "device", "platform": "device",
@ -87,19 +75,19 @@ async def test_get_triggers(hass, device_reg, entity_reg):
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -124,15 +112,17 @@ async def test_get_triggers_hidden_auxiliary(
assert_lists_same(triggers, expected_triggers) assert_lists_same(triggers, expected_triggers)
async def test_get_trigger_capabilities(hass, device_reg, entity_reg): async def test_get_trigger_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a lock.""" """Test we get the expected capabilities from a lock."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id

View file

@ -12,7 +12,7 @@ from homeassistant.const import (
STATE_PAUSED, STATE_PAUSED,
STATE_PLAYING, STATE_PLAYING,
) )
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -22,39 +22,27 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_conditions(hass, device_reg, entity_reg): async def test_get_conditions(hass, device_registry, entity_registry):
"""Test we get the expected conditions from a media_player.""" """Test we get the expected conditions from a media_player."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_conditions = [ expected_conditions = [
{ {
"condition": "device", "condition": "device",
@ -90,19 +78,19 @@ async def test_get_conditions(hass, device_reg, entity_reg):
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -14,7 +14,7 @@ from homeassistant.const import (
STATE_PAUSED, STATE_PAUSED,
STATE_PLAYING, STATE_PLAYING,
) )
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -27,39 +27,27 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_triggers(hass, device_reg, entity_reg): async def test_get_triggers(hass, device_registry, entity_registry):
"""Test we get the expected triggers from a media player.""" """Test we get the expected triggers from a media player."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
trigger_types = { trigger_types = {
"buffering", "buffering",
@ -98,19 +86,19 @@ async def test_get_triggers(hass, device_reg, entity_reg):
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -143,15 +131,17 @@ async def test_get_triggers_hidden_auxiliary(
assert_lists_same(triggers, expected_triggers) assert_lists_same(triggers, expected_triggers)
async def test_get_trigger_capabilities(hass, device_reg, entity_reg): async def test_get_trigger_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a media player.""" """Test we get the expected capabilities from a media player."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id

View file

@ -6,7 +6,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.number import DOMAIN, device_action from homeassistant.components.number import DOMAIN, device_action
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, device_registry from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -16,33 +16,21 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture async def test_get_actions(hass, device_registry, entity_registry):
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
async def test_get_actions(hass, device_reg, entity_reg):
"""Test we get the expected actions for an entity.""" """Test we get the expected actions for an entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
hass.states.async_set("number.test_5678", 0.5, {"min_value": 0.0, "max_value": 1.0}) hass.states.async_set("number.test_5678", 0.5, {"min_value": 0.0, "max_value": 1.0})
expected_actions = [ expected_actions = [
{ {
@ -70,19 +58,19 @@ async def test_get_actions(hass, device_reg, entity_reg):
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -107,15 +95,17 @@ async def test_get_actions_hidden_auxiliary(
assert_lists_same(actions, expected_actions) assert_lists_same(actions, expected_actions)
async def test_get_action_no_state(hass, device_reg, entity_reg): async def test_get_action_no_state(hass, device_registry, entity_registry):
"""Test we get the expected actions for an entity.""" """Test we get the expected actions for an entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_actions = [ expected_actions = [
{ {
"domain": DOMAIN, "domain": DOMAIN,

View file

@ -5,7 +5,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.remote import DOMAIN from homeassistant.components.remote import DOMAIN
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -15,39 +15,27 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_actions(hass, device_reg, entity_reg): async def test_get_actions(hass, device_registry, entity_registry):
"""Test we get the expected actions from a remote.""" """Test we get the expected actions from a remote."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_actions = [ expected_actions = [
{ {
"domain": DOMAIN, "domain": DOMAIN,
@ -75,19 +63,19 @@ async def test_get_actions(hass, device_reg, entity_reg):
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -8,7 +8,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.remote import DOMAIN from homeassistant.components.remote import DOMAIN
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -20,39 +20,27 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_conditions(hass, device_reg, entity_reg): async def test_get_conditions(hass, device_registry, entity_registry):
"""Test we get the expected conditions from a remote.""" """Test we get the expected conditions from a remote."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_conditions = [ expected_conditions = [
{ {
"condition": "device", "condition": "device",
@ -81,19 +69,19 @@ async def test_get_conditions(hass, device_reg, entity_reg):
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -118,15 +106,17 @@ async def test_get_conditions_hidden_auxiliary(
assert_lists_same(conditions, expected_conditions) assert_lists_same(conditions, expected_conditions)
async def test_get_condition_capabilities(hass, device_reg, entity_reg): async def test_get_condition_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a remote condition.""" """Test we get the expected capabilities from a remote condition."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_capabilities = { expected_capabilities = {
"extra_fields": [ "extra_fields": [
{"name": "for", "optional": True, "type": "positive_time_period_dict"} {"name": "for", "optional": True, "type": "positive_time_period_dict"}

View file

@ -7,7 +7,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.remote import DOMAIN from homeassistant.components.remote import DOMAIN
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -20,39 +20,27 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_triggers(hass, device_reg, entity_reg): async def test_get_triggers(hass, device_registry, entity_registry):
"""Test we get the expected triggers from a remote.""" """Test we get the expected triggers from a remote."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_triggers = [ expected_triggers = [
{ {
"platform": "device", "platform": "device",
@ -81,19 +69,19 @@ async def test_get_triggers(hass, device_reg, entity_reg):
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -118,15 +106,17 @@ async def test_get_triggers_hidden_auxiliary(
assert_lists_same(triggers, expected_triggers) assert_lists_same(triggers, expected_triggers)
async def test_get_trigger_capabilities(hass, device_reg, entity_reg): async def test_get_trigger_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a remote trigger.""" """Test we get the expected capabilities from a remote trigger."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_capabilities = { expected_capabilities = {
"extra_fields": [ "extra_fields": [
{"name": "for", "optional": True, "type": "positive_time_period_dict"} {"name": "for", "optional": True, "type": "positive_time_period_dict"}

View file

@ -9,8 +9,8 @@ from homeassistant.components.select.device_action import async_get_action_capab
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import ( from homeassistant.helpers import (
config_validation as cv, config_validation as cv,
device_registry, device_registry as dr,
entity_registry, entity_registry as er,
) )
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -20,36 +20,24 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
@pytest.fixture
def device_reg(hass: HomeAssistant) -> device_registry.DeviceRegistry:
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass: HomeAssistant) -> entity_registry.EntityRegistry:
"""Return an empty, loaded, registry."""
return mock_registry(hass)
async def test_get_actions( async def test_get_actions(
hass: HomeAssistant, hass: HomeAssistant,
device_reg: device_registry.DeviceRegistry, device_registry: dr.DeviceRegistry,
entity_reg: entity_registry.EntityRegistry, entity_registry: er.EntityRegistry,
) -> None: ) -> None:
"""Test we get the expected actions from a select.""" """Test we get the expected actions from a select."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_actions = [ expected_actions = [
{ {
"domain": DOMAIN, "domain": DOMAIN,
@ -75,27 +63,27 @@ async def test_get_actions(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"hidden_by,entity_category", "hidden_by,entity_category",
( (
(entity_registry.RegistryEntryHider.INTEGRATION, None), (er.RegistryEntryHider.INTEGRATION, None),
(entity_registry.RegistryEntryHider.USER, None), (er.RegistryEntryHider.USER, None),
(None, EntityCategory.CONFIG), (None, EntityCategory.CONFIG),
(None, EntityCategory.DIAGNOSTIC), (None, EntityCategory.DIAGNOSTIC),
), ),
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -13,8 +13,8 @@ from homeassistant.components.select.device_condition import (
from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import ( from homeassistant.helpers import (
config_validation as cv, config_validation as cv,
device_registry, device_registry as dr,
entity_registry, entity_registry as er,
) )
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -24,23 +24,9 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
@pytest.fixture
def device_reg(hass: HomeAssistant) -> device_registry.DeviceRegistry:
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass: HomeAssistant) -> entity_registry.EntityRegistry:
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass: HomeAssistant) -> list[ServiceCall]: def calls(hass: HomeAssistant) -> list[ServiceCall]:
"""Track calls to a mock service.""" """Track calls to a mock service."""
@ -49,17 +35,19 @@ def calls(hass: HomeAssistant) -> list[ServiceCall]:
async def test_get_conditions( async def test_get_conditions(
hass: HomeAssistant, hass: HomeAssistant,
device_reg: device_registry.DeviceRegistry, device_registry: dr.DeviceRegistry,
entity_reg: entity_registry.EntityRegistry, entity_registry: er.EntityRegistry,
) -> None: ) -> None:
"""Test we get the expected conditions from a select.""" """Test we get the expected conditions from a select."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_conditions = [ expected_conditions = [
{ {
"condition": "device", "condition": "device",
@ -79,27 +67,27 @@ async def test_get_conditions(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"hidden_by,entity_category", "hidden_by,entity_category",
( (
(entity_registry.RegistryEntryHider.INTEGRATION, None), (er.RegistryEntryHider.INTEGRATION, None),
(entity_registry.RegistryEntryHider.USER, None), (er.RegistryEntryHider.USER, None),
(None, EntityCategory.CONFIG), (None, EntityCategory.CONFIG),
(None, EntityCategory.DIAGNOSTIC), (None, EntityCategory.DIAGNOSTIC),
), ),
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -11,7 +11,7 @@ from homeassistant.components.select.device_trigger import (
async_get_trigger_capabilities, async_get_trigger_capabilities,
) )
from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import config_validation as cv, device_registry from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import EntityRegistry, RegistryEntryHider from homeassistant.helpers.entity_registry import EntityRegistry, RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -21,23 +21,9 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
@pytest.fixture
def device_reg(hass: HomeAssistant) -> device_registry.DeviceRegistry:
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass: HomeAssistant) -> EntityRegistry:
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass: HomeAssistant) -> list[ServiceCall]: def calls(hass: HomeAssistant) -> list[ServiceCall]:
"""Track calls to a mock service.""" """Track calls to a mock service."""
@ -46,17 +32,19 @@ def calls(hass: HomeAssistant) -> list[ServiceCall]:
async def test_get_triggers( async def test_get_triggers(
hass: HomeAssistant, hass: HomeAssistant,
device_reg: device_registry.DeviceRegistry, device_registry: dr.DeviceRegistry,
entity_reg: EntityRegistry, entity_registry: EntityRegistry,
) -> None: ) -> None:
"""Test we get the expected triggers from a select.""" """Test we get the expected triggers from a select."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_triggers = [ expected_triggers = [
{ {
"platform": "device", "platform": "device",
@ -84,19 +72,19 @@ async def test_get_triggers(
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -11,7 +11,7 @@ from homeassistant.components.sensor import (
) )
from homeassistant.components.sensor.device_condition import ENTITY_CONDITIONS from homeassistant.components.sensor.device_condition import ENTITY_CONDITIONS
from homeassistant.const import CONF_PLATFORM, PERCENTAGE, STATE_UNKNOWN from homeassistant.const import CONF_PLATFORM, PERCENTAGE, STATE_UNKNOWN
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -22,32 +22,20 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
from tests.testing_config.custom_components.test.sensor import UNITS_OF_MEASUREMENT from tests.testing_config.custom_components.test.sensor import UNITS_OF_MEASUREMENT
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_conditions(hass, device_reg, entity_reg, enable_custom_integrations): async def test_get_conditions(
hass, device_registry, entity_registry, enable_custom_integrations
):
"""Test we get the expected conditions from a sensor.""" """Test we get the expected conditions from a sensor."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init() platform.init()
@ -56,12 +44,12 @@ async def test_get_conditions(hass, device_reg, entity_reg, enable_custom_integr
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
for device_class in SensorDeviceClass: for device_class in SensorDeviceClass:
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
platform.ENTITIES[device_class].unique_id, platform.ENTITIES[device_class].unique_id,
@ -100,19 +88,19 @@ async def test_get_conditions(hass, device_reg, entity_reg, enable_custom_integr
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -138,17 +126,17 @@ async def test_get_conditions_hidden_auxiliary(
assert_lists_same(conditions, expected_conditions) assert_lists_same(conditions, expected_conditions)
async def test_get_conditions_no_state(hass, device_reg, entity_reg): async def test_get_conditions_no_state(hass, device_registry, entity_registry):
"""Test we get the expected conditions from a sensor.""" """Test we get the expected conditions from a sensor."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_ids = {} entity_ids = {}
for device_class in SensorDeviceClass: for device_class in SensorDeviceClass:
entity_ids[device_class] = entity_reg.async_get_or_create( entity_ids[device_class] = entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
f"5678_{device_class}", f"5678_{device_class}",
@ -191,8 +179,8 @@ async def test_get_conditions_no_state(hass, device_reg, entity_reg):
) )
async def test_get_conditions_no_unit_or_stateclass( async def test_get_conditions_no_unit_or_stateclass(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
state_class, state_class,
unit, unit,
condition_types, condition_types,
@ -200,11 +188,11 @@ async def test_get_conditions_no_unit_or_stateclass(
"""Test we get the expected conditions from an entity with no unit or state class.""" """Test we get the expected conditions from an entity with no unit or state class."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -238,8 +226,8 @@ async def test_get_conditions_no_unit_or_stateclass(
) )
async def test_get_condition_capabilities( async def test_get_condition_capabilities(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
device_class_reg, device_class_reg,
device_class_state, device_class_state,
@ -252,11 +240,11 @@ async def test_get_condition_capabilities(
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_id = entity_reg.async_get_or_create( entity_id = entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
platform.ENTITIES["battery"].unique_id, platform.ENTITIES["battery"].unique_id,
@ -298,9 +286,7 @@ async def test_get_condition_capabilities(
assert capabilities == expected_capabilities assert capabilities == expected_capabilities
async def test_get_condition_capabilities_none( async def test_get_condition_capabilities_none(hass, enable_custom_integrations):
hass, device_reg, entity_reg, enable_custom_integrations
):
"""Test we get the expected capabilities from a sensor condition.""" """Test we get the expected capabilities from a sensor condition."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init() platform.init()

View file

@ -13,7 +13,7 @@ from homeassistant.components.sensor import (
) )
from homeassistant.components.sensor.device_trigger import ENTITY_TRIGGERS from homeassistant.components.sensor.device_trigger import ENTITY_TRIGGERS
from homeassistant.const import CONF_PLATFORM, PERCENTAGE, STATE_UNKNOWN from homeassistant.const import CONF_PLATFORM, PERCENTAGE, STATE_UNKNOWN
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -26,32 +26,20 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
from tests.testing_config.custom_components.test.sensor import UNITS_OF_MEASUREMENT from tests.testing_config.custom_components.test.sensor import UNITS_OF_MEASUREMENT
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_triggers(hass, device_reg, entity_reg, enable_custom_integrations): async def test_get_triggers(
hass, device_registry, entity_registry, enable_custom_integrations
):
"""Test we get the expected triggers from a sensor.""" """Test we get the expected triggers from a sensor."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init() platform.init()
@ -60,12 +48,12 @@ async def test_get_triggers(hass, device_reg, entity_reg, enable_custom_integrat
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
for device_class in SensorDeviceClass: for device_class in SensorDeviceClass:
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
platform.ENTITIES[device_class].unique_id, platform.ENTITIES[device_class].unique_id,
@ -104,19 +92,19 @@ async def test_get_triggers(hass, device_reg, entity_reg, enable_custom_integrat
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -154,8 +142,8 @@ async def test_get_triggers_hidden_auxiliary(
) )
async def test_get_triggers_no_unit_or_stateclass( async def test_get_triggers_no_unit_or_stateclass(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
state_class, state_class,
unit, unit,
trigger_types, trigger_types,
@ -163,11 +151,11 @@ async def test_get_triggers_no_unit_or_stateclass(
"""Test we get the expected triggers from an entity with no unit or state class.""" """Test we get the expected triggers from an entity with no unit or state class."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -201,8 +189,8 @@ async def test_get_triggers_no_unit_or_stateclass(
) )
async def test_get_trigger_capabilities( async def test_get_trigger_capabilities(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
set_state, set_state,
device_class_reg, device_class_reg,
device_class_state, device_class_state,
@ -215,11 +203,11 @@ async def test_get_trigger_capabilities(
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_id = entity_reg.async_get_or_create( entity_id = entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
platform.ENTITIES["battery"].unique_id, platform.ENTITIES["battery"].unique_id,
@ -262,9 +250,7 @@ async def test_get_trigger_capabilities(
assert capabilities == expected_capabilities assert capabilities == expected_capabilities
async def test_get_trigger_capabilities_none( async def test_get_trigger_capabilities_none(hass, enable_custom_integrations):
hass, device_reg, entity_reg, enable_custom_integrations
):
"""Test we get the expected capabilities from a sensor trigger.""" """Test we get the expected capabilities from a sensor trigger."""
platform = getattr(hass.components, f"test.{DOMAIN}") platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init() platform.init()

View file

@ -5,7 +5,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.switch import DOMAIN from homeassistant.components.switch import DOMAIN
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -15,39 +15,27 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_actions(hass, device_reg, entity_reg): async def test_get_actions(hass, device_registry, entity_registry):
"""Test we get the expected actions from a switch.""" """Test we get the expected actions from a switch."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_actions = [] expected_actions = []
expected_actions += [ expected_actions += [
{ {
@ -76,19 +64,19 @@ async def test_get_actions(hass, device_reg, entity_reg):
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -8,7 +8,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.switch import DOMAIN from homeassistant.components.switch import DOMAIN
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -20,39 +20,27 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_conditions(hass, device_reg, entity_reg): async def test_get_conditions(hass, device_registry, entity_registry):
"""Test we get the expected conditions from a switch.""" """Test we get the expected conditions from a switch."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_conditions = [ expected_conditions = [
{ {
"condition": "device", "condition": "device",
@ -81,19 +69,19 @@ async def test_get_conditions(hass, device_reg, entity_reg):
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -118,15 +106,17 @@ async def test_get_conditions_hidden_auxiliary(
assert_lists_same(conditions, expected_conditions) assert_lists_same(conditions, expected_conditions)
async def test_get_condition_capabilities(hass, device_reg, entity_reg): async def test_get_condition_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a switch condition.""" """Test we get the expected capabilities from a switch condition."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_capabilities = { expected_capabilities = {
"extra_fields": [ "extra_fields": [
{"name": "for", "optional": True, "type": "positive_time_period_dict"} {"name": "for", "optional": True, "type": "positive_time_period_dict"}

View file

@ -7,7 +7,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.switch import DOMAIN from homeassistant.components.switch import DOMAIN
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -20,39 +20,27 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_triggers(hass, device_reg, entity_reg): async def test_get_triggers(hass, device_registry, entity_registry):
"""Test we get the expected triggers from a switch.""" """Test we get the expected triggers from a switch."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_triggers = [ expected_triggers = [
{ {
"platform": "device", "platform": "device",
@ -81,19 +69,19 @@ async def test_get_triggers(hass, device_reg, entity_reg):
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -118,15 +106,17 @@ async def test_get_triggers_hidden_auxiliary(
assert_lists_same(triggers, expected_triggers) assert_lists_same(triggers, expected_triggers)
async def test_get_trigger_capabilities(hass, device_reg, entity_reg): async def test_get_trigger_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a switch trigger.""" """Test we get the expected capabilities from a switch trigger."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_capabilities = { expected_capabilities = {
"extra_fields": [ "extra_fields": [
{"name": "for", "optional": True, "type": "positive_time_period_dict"} {"name": "for", "optional": True, "type": "positive_time_period_dict"}

View file

@ -6,7 +6,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.text import DOMAIN, device_action from homeassistant.components.text import DOMAIN, device_action
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, device_registry from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -16,33 +16,21 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture async def test_get_actions(hass, device_registry, entity_registry):
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
async def test_get_actions(hass, device_reg, entity_reg):
"""Test we get the expected actions for an entity.""" """Test we get the expected actions for an entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
hass.states.async_set("text.test_5678", 0.5, {"min_value": 0.0, "max_value": 1.0}) hass.states.async_set("text.test_5678", 0.5, {"min_value": 0.0, "max_value": 1.0})
expected_actions = [ expected_actions = [
{ {
@ -70,19 +58,19 @@ async def test_get_actions(hass, device_reg, entity_reg):
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -107,15 +95,17 @@ async def test_get_actions_hidden_auxiliary(
assert_lists_same(actions, expected_actions) assert_lists_same(actions, expected_actions)
async def test_get_action_no_state(hass, device_reg, entity_reg): async def test_get_action_no_state(hass, device_registry, entity_registry):
"""Test we get the expected actions for an entity.""" """Test we get the expected actions for an entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_actions = [ expected_actions = [
{ {
"domain": DOMAIN, "domain": DOMAIN,

View file

@ -8,7 +8,7 @@ from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.update import DOMAIN from homeassistant.components.update import DOMAIN
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.device_registry import DeviceRegistry from homeassistant.helpers.device_registry import DeviceRegistry
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import EntityRegistry, RegistryEntryHider from homeassistant.helpers.entity_registry import EntityRegistry, RegistryEntryHider
@ -22,24 +22,10 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass: HomeAssistant) -> DeviceRegistry:
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass: HomeAssistant) -> EntityRegistry:
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass: HomeAssistant) -> list[ServiceCall]: def calls(hass: HomeAssistant) -> list[ServiceCall]:
"""Track calls to a mock service.""" """Track calls to a mock service."""
@ -47,16 +33,20 @@ def calls(hass: HomeAssistant) -> list[ServiceCall]:
async def test_get_triggers( async def test_get_triggers(
hass: HomeAssistant, device_reg: DeviceRegistry, entity_reg: EntityRegistry hass: HomeAssistant,
device_registry: DeviceRegistry,
entity_registry: EntityRegistry,
) -> None: ) -> None:
"""Test we get the expected triggers from a update entity.""" """Test we get the expected triggers from a update entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_triggers = [ expected_triggers = [
{ {
"platform": "device", "platform": "device",
@ -85,19 +75,19 @@ async def test_get_triggers(
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -123,16 +113,20 @@ async def test_get_triggers_hidden_auxiliary(
async def test_get_trigger_capabilities( async def test_get_trigger_capabilities(
hass: HomeAssistant, device_reg: DeviceRegistry, entity_reg: EntityRegistry hass: HomeAssistant,
device_registry: DeviceRegistry,
entity_registry: EntityRegistry,
) -> None: ) -> None:
"""Test we get the expected capabilities from a update trigger.""" """Test we get the expected capabilities from a update trigger."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_capabilities = { expected_capabilities = {
"extra_fields": [ "extra_fields": [
{"name": "for", "optional": True, "type": "positive_time_period_dict"} {"name": "for", "optional": True, "type": "positive_time_period_dict"}

View file

@ -5,7 +5,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.vacuum import DOMAIN from homeassistant.components.vacuum import DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -15,33 +15,21 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture async def test_get_actions(hass, device_registry, entity_registry):
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
async def test_get_actions(hass, device_reg, entity_reg):
"""Test we get the expected actions from a vacuum.""" """Test we get the expected actions from a vacuum."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_actions = [] expected_actions = []
expected_actions += [ expected_actions += [
{ {
@ -70,19 +58,19 @@ async def test_get_actions(hass, device_reg, entity_reg):
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -9,7 +9,7 @@ from homeassistant.components.vacuum import (
STATE_DOCKED, STATE_DOCKED,
STATE_RETURNING, STATE_RETURNING,
) )
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -19,39 +19,27 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_conditions(hass, device_reg, entity_reg): async def test_get_conditions(hass, device_registry, entity_registry):
"""Test we get the expected conditions from a vacuum.""" """Test we get the expected conditions from a vacuum."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_conditions = [ expected_conditions = [
{ {
"condition": "device", "condition": "device",
@ -80,19 +68,19 @@ async def test_get_conditions(hass, device_reg, entity_reg):
) )
async def test_get_conditions_hidden_auxiliary( async def test_get_conditions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected conditions from a hidden or auxiliary entity.""" """Test we get the expected conditions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",

View file

@ -6,7 +6,7 @@ import pytest
import homeassistant.components.automation as automation import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.vacuum import DOMAIN, STATE_CLEANING, STATE_DOCKED from homeassistant.components.vacuum import DOMAIN, STATE_CLEANING, STATE_DOCKED
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -19,39 +19,27 @@ from tests.common import (
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
@pytest.fixture @pytest.fixture
def calls(hass): def calls(hass):
"""Track calls to a mock service.""" """Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") return async_mock_service(hass, "test", "automation")
async def test_get_triggers(hass, device_reg, entity_reg): async def test_get_triggers(hass, device_registry, entity_registry):
"""Test we get the expected triggers from a vacuum.""" """Test we get the expected triggers from a vacuum."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_triggers = [ expected_triggers = [
{ {
"platform": "device", "platform": "device",
@ -80,19 +68,19 @@ async def test_get_triggers(hass, device_reg, entity_reg):
) )
async def test_get_triggers_hidden_auxiliary( async def test_get_triggers_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected triggers from a hidden or auxiliary entity.""" """Test we get the expected triggers from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",
@ -117,15 +105,17 @@ async def test_get_triggers_hidden_auxiliary(
assert_lists_same(triggers, expected_triggers) assert_lists_same(triggers, expected_triggers)
async def test_get_trigger_capabilities(hass, device_reg, entity_reg): async def test_get_trigger_capabilities(hass, device_registry, entity_registry):
"""Test we get the expected capabilities from a vacuum device.""" """Test we get the expected capabilities from a vacuum device."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id

View file

@ -5,7 +5,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.water_heater import DOMAIN from homeassistant.components.water_heater import DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import RegistryEntryHider from homeassistant.helpers.entity_registry import RegistryEntryHider
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -15,33 +15,21 @@ from tests.common import (
assert_lists_same, assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_device_registry,
mock_registry,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture async def test_get_actions(hass, device_registry, entity_registry):
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass)
async def test_get_actions(hass, device_reg, entity_reg):
"""Test we get the expected actions from a water_heater.""" """Test we get the expected actions from a water_heater."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
) )
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
expected_actions = [] expected_actions = []
expected_actions += [ expected_actions += [
{ {
@ -70,19 +58,19 @@ async def test_get_actions(hass, device_reg, entity_reg):
) )
async def test_get_actions_hidden_auxiliary( async def test_get_actions_hidden_auxiliary(
hass, hass,
device_reg, device_registry,
entity_reg, entity_registry,
hidden_by, hidden_by,
entity_category, entity_category,
): ):
"""Test we get the expected actions from a hidden or auxiliary entity.""" """Test we get the expected actions from a hidden or auxiliary entity."""
config_entry = MockConfigEntry(domain="test", data={}) config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create( device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
) )
entity_reg.async_get_or_create( entity_registry.async_get_or_create(
DOMAIN, DOMAIN,
"test", "test",
"5678", "5678",