Use common registry fixtures in solarlog (#121005)

This commit is contained in:
epenet 2024-07-02 12:36:30 +02:00 committed by GitHub
parent cdc3897319
commit 02dffcde1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 23 deletions

View File

@ -7,16 +7,10 @@ import pytest
from homeassistant.components.solarlog.const import DOMAIN as SOLARLOG_DOMAIN
from homeassistant.const import CONF_HOST, CONF_NAME
from homeassistant.core import HomeAssistant
from .const import HOST, NAME
from tests.common import (
MockConfigEntry,
load_json_object_fixture,
mock_device_registry,
mock_registry,
)
from tests.common import MockConfigEntry, load_json_object_fixture
@pytest.fixture
@ -76,15 +70,3 @@ def mock_test_connection():
return_value=True,
):
yield
@pytest.fixture(name="device_reg")
def device_reg_fixture(hass: HomeAssistant):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture(name="entity_reg")
def entity_reg_fixture(hass: HomeAssistant):
"""Return an empty, loaded, registry."""
return mock_registry(hass)

View File

@ -50,7 +50,9 @@ async def test_raise_config_entry_not_ready_when_offline(
async def test_migrate_config_entry(
hass: HomeAssistant, device_reg: DeviceRegistry, entity_reg: EntityRegistry
hass: HomeAssistant,
device_registry: DeviceRegistry,
entity_registry: EntityRegistry,
) -> None:
"""Test successful migration of entry data."""
entry = MockConfigEntry(
@ -64,13 +66,13 @@ async def test_migrate_config_entry(
)
entry.add_to_hass(hass)
device = device_reg.async_get_or_create(
device = device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, entry.entry_id)},
manufacturer="Solar-Log",
name="solarlog",
)
sensor_entity = entity_reg.async_get_or_create(
sensor_entity = entity_registry.async_get_or_create(
config_entry=entry,
platform=DOMAIN,
domain=Platform.SENSOR,
@ -85,7 +87,7 @@ async def test_migrate_config_entry(
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
entity_migrated = entity_reg.async_get(sensor_entity.entity_id)
entity_migrated = entity_registry.async_get(sensor_entity.entity_id)
assert entity_migrated
assert entity_migrated.unique_id == f"{entry.entry_id}_last_updated"