mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Clean up unnecessary registry mocks from scaffolding templates (#87732)
This commit is contained in:
parent
76bf6f164f
commit
769e0356ad
@ -5,7 +5,7 @@ from homeassistant.components import automation
|
|||||||
from homeassistant.components.NEW_DOMAIN import DOMAIN
|
from homeassistant.components.NEW_DOMAIN 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 NEW_DOMAIN."""
|
"""Test we get the expected actions from a NEW_DOMAIN."""
|
||||||
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",
|
||||||
|
@ -8,7 +8,7 @@ from homeassistant.components.NEW_DOMAIN import DOMAIN
|
|||||||
from homeassistant.components.device_automation import DeviceAutomationType
|
from homeassistant.components.device_automation import DeviceAutomationType
|
||||||
from homeassistant.const import STATE_OFF, STATE_ON
|
from homeassistant.const import STATE_OFF, STATE_ON
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall
|
from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
from homeassistant.helpers import device_registry, entity_registry
|
from homeassistant.helpers import device_registry as dr, 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 (
|
||||||
@ -16,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) -> 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."""
|
||||||
@ -41,17 +27,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 NEW_DOMAIN."""
|
"""Test we get the expected conditions from a NEW_DOMAIN."""
|
||||||
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",
|
||||||
|
@ -5,7 +5,8 @@ from homeassistant.components import automation
|
|||||||
from homeassistant.components.NEW_DOMAIN import DOMAIN
|
from homeassistant.components.NEW_DOMAIN import DOMAIN
|
||||||
from homeassistant.components.device_automation import DeviceAutomationType
|
from homeassistant.components.device_automation import DeviceAutomationType
|
||||||
from homeassistant.const import STATE_OFF, STATE_ON
|
from homeassistant.const import STATE_OFF, STATE_ON
|
||||||
from homeassistant.helpers import device_registry
|
from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
|
from homeassistant.helpers import device_registry as dr, 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 (
|
||||||
@ -13,38 +14,30 @@ 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
|
@pytest.fixture
|
||||||
def device_reg(hass):
|
def calls(hass: HomeAssistant) -> list[ServiceCall]:
|
||||||
"""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
|
|
||||||
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: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
"""Test we get the expected triggers from a NEW_DOMAIN."""
|
"""Test we get the expected triggers from a NEW_DOMAIN."""
|
||||||
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",
|
||||||
@ -67,7 +60,9 @@ async def test_get_triggers(hass, device_reg, entity_reg):
|
|||||||
assert_lists_same(triggers, expected_triggers)
|
assert_lists_same(triggers, expected_triggers)
|
||||||
|
|
||||||
|
|
||||||
async def test_if_fires_on_state_change(hass, calls):
|
async def test_if_fires_on_state_change(
|
||||||
|
hass: HomeAssistant, calls: list[ServiceCall]
|
||||||
|
) -> None:
|
||||||
"""Test for turn_on and turn_off triggers firing."""
|
"""Test for turn_on and turn_off triggers firing."""
|
||||||
hass.states.async_set("NEW_DOMAIN.entity", STATE_OFF)
|
hass.states.async_set("NEW_DOMAIN.entity", STATE_OFF)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user