Update m* tests to use entity & device registry fixtures (#103980)

This commit is contained in:
Jan-Philipp Benecke 2023-11-15 10:33:11 +01:00 committed by GitHub
parent 51c1ea85f3
commit 9326ea09a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 361 additions and 298 deletions

View File

@ -90,6 +90,7 @@ async def test_occupancy_sensor(
@pytest.mark.parametrize("expected_lingering_tasks", [True]) @pytest.mark.parametrize("expected_lingering_tasks", [True])
async def test_battery_sensor( async def test_battery_sensor(
hass: HomeAssistant, hass: HomeAssistant,
entity_registry: er.EntityRegistry,
matter_client: MagicMock, matter_client: MagicMock,
door_lock: MatterNode, door_lock: MatterNode,
) -> None: ) -> None:
@ -108,7 +109,6 @@ async def test_battery_sensor(
assert state assert state
assert state.state == "on" assert state.state == "on"
entity_registry = er.async_get(hass)
entry = entity_registry.async_get(entity_id) entry = entity_registry.async_get(entity_id)
assert entry assert entry

View File

@ -81,6 +81,7 @@ async def test_config_entry_diagnostics(
async def test_device_diagnostics( async def test_device_diagnostics(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
device_registry: dr.DeviceRegistry,
matter_client: MagicMock, matter_client: MagicMock,
config_entry_diagnostics: dict[str, Any], config_entry_diagnostics: dict[str, Any],
device_diagnostics: dict[str, Any], device_diagnostics: dict[str, Any],
@ -102,8 +103,9 @@ async def test_device_diagnostics(
) )
matter_client.get_diagnostics.return_value = server_diagnostics matter_client.get_diagnostics.return_value = server_diagnostics
config_entry = hass.config_entries.async_entries(DOMAIN)[0] config_entry = hass.config_entries.async_entries(DOMAIN)[0]
dev_reg = dr.async_get(hass) device = dr.async_entries_for_config_entry(device_registry, config_entry.entry_id)[
device = dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id)[0] 0
]
assert device assert device
diagnostics = await get_diagnostics_for_device( diagnostics = await get_diagnostics_for_device(

View File

@ -37,10 +37,10 @@ async def test_get_device_id(
@pytest.mark.parametrize("expected_lingering_tasks", [True]) @pytest.mark.parametrize("expected_lingering_tasks", [True])
async def test_get_node_from_device_entry( async def test_get_node_from_device_entry(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
matter_client: MagicMock, matter_client: MagicMock,
) -> None: ) -> None:
"""Test get_node_from_device_entry.""" """Test get_node_from_device_entry."""
device_registry = dr.async_get(hass)
other_domain = "other_domain" other_domain = "other_domain"
other_config_entry = MockConfigEntry(domain=other_domain) other_config_entry = MockConfigEntry(domain=other_domain)
other_config_entry.add_to_hass(hass) other_config_entry.add_to_hass(hass)

View File

@ -612,6 +612,8 @@ async def test_remove_entry(
@pytest.mark.parametrize("expected_lingering_tasks", [True]) @pytest.mark.parametrize("expected_lingering_tasks", [True])
async def test_remove_config_entry_device( async def test_remove_config_entry_device(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
matter_client: MagicMock, matter_client: MagicMock,
hass_ws_client: WebSocketGenerator, hass_ws_client: WebSocketGenerator,
) -> None: ) -> None:
@ -621,11 +623,9 @@ async def test_remove_config_entry_device(
await hass.async_block_till_done() await hass.async_block_till_done()
config_entry = hass.config_entries.async_entries(DOMAIN)[0] config_entry = hass.config_entries.async_entries(DOMAIN)[0]
device_registry = dr.async_get(hass)
device_entry = dr.async_entries_for_config_entry( device_entry = dr.async_entries_for_config_entry(
device_registry, config_entry.entry_id device_registry, config_entry.entry_id
)[0] )[0]
entity_registry = er.async_get(hass)
entity_id = "light.m5stamp_lighting_app" entity_id = "light.m5stamp_lighting_app"
assert device_entry assert device_entry
@ -654,6 +654,7 @@ async def test_remove_config_entry_device(
@pytest.mark.parametrize("expected_lingering_tasks", [True]) @pytest.mark.parametrize("expected_lingering_tasks", [True])
async def test_remove_config_entry_device_no_node( async def test_remove_config_entry_device_no_node(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
matter_client: MagicMock, matter_client: MagicMock,
integration: MockConfigEntry, integration: MockConfigEntry,
hass_ws_client: WebSocketGenerator, hass_ws_client: WebSocketGenerator,
@ -661,7 +662,6 @@ async def test_remove_config_entry_device_no_node(
"""Test that a device can be removed ok without an existing node.""" """Test that a device can be removed ok without an existing node."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
config_entry = integration config_entry = integration
device_registry = dr.async_get(hass)
device_entry = device_registry.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,
identifiers={ identifiers={

View File

@ -187,6 +187,7 @@ async def test_temperature_sensor(
@pytest.mark.parametrize("expected_lingering_tasks", [True]) @pytest.mark.parametrize("expected_lingering_tasks", [True])
async def test_battery_sensor( async def test_battery_sensor(
hass: HomeAssistant, hass: HomeAssistant,
entity_registry: er.EntityRegistry,
matter_client: MagicMock, matter_client: MagicMock,
eve_contact_sensor_node: MatterNode, eve_contact_sensor_node: MatterNode,
) -> None: ) -> None:
@ -203,7 +204,6 @@ async def test_battery_sensor(
assert state assert state
assert state.state == "50" assert state.state == "50"
entity_registry = er.async_get(hass)
entry = entity_registry.async_get(entity_id) entry = entity_registry.async_get(entity_id)
assert entry assert entry

View File

@ -23,10 +23,12 @@ BATTERY_ENTITY_ID = f"{ENTITY_ID}_battery"
async def test_window_shuttler( async def test_window_shuttler(
hass: HomeAssistant, cube: MaxCube, windowshutter: MaxWindowShutter hass: HomeAssistant,
entity_registry: er.EntityRegistry,
cube: MaxCube,
windowshutter: MaxWindowShutter,
) -> None: ) -> None:
"""Test a successful setup with a shuttler device.""" """Test a successful setup with a shuttler device."""
entity_registry = er.async_get(hass)
assert entity_registry.async_is_registered(ENTITY_ID) assert entity_registry.async_is_registered(ENTITY_ID)
entity = entity_registry.async_get(ENTITY_ID) entity = entity_registry.async_get(ENTITY_ID)
assert entity.unique_id == "AABBCCDD03" assert entity.unique_id == "AABBCCDD03"
@ -47,10 +49,12 @@ async def test_window_shuttler(
async def test_window_shuttler_battery( async def test_window_shuttler_battery(
hass: HomeAssistant, cube: MaxCube, windowshutter: MaxWindowShutter hass: HomeAssistant,
entity_registry: er.EntityRegistry,
cube: MaxCube,
windowshutter: MaxWindowShutter,
) -> None: ) -> None:
"""Test battery binary_state with a shuttler device.""" """Test battery binary_state with a shuttler device."""
entity_registry = er.async_get(hass)
assert entity_registry.async_is_registered(BATTERY_ENTITY_ID) assert entity_registry.async_is_registered(BATTERY_ENTITY_ID)
entity = entity_registry.async_get(BATTERY_ENTITY_ID) entity = entity_registry.async_get(BATTERY_ENTITY_ID)
assert entity.unique_id == "AABBCCDD03_battery" assert entity.unique_id == "AABBCCDD03_battery"

View File

@ -60,9 +60,10 @@ WALL_ENTITY_ID = "climate.testroom_testwallthermostat"
VALVE_POSITION = "valve_position" VALVE_POSITION = "valve_position"
async def test_setup_thermostat(hass: HomeAssistant, cube: MaxCube) -> None: async def test_setup_thermostat(
hass: HomeAssistant, entity_registry: er.EntityRegistry, cube: MaxCube
) -> None:
"""Test a successful setup of a thermostat device.""" """Test a successful setup of a thermostat device."""
entity_registry = er.async_get(hass)
assert entity_registry.async_is_registered(ENTITY_ID) assert entity_registry.async_is_registered(ENTITY_ID)
entity = entity_registry.async_get(ENTITY_ID) entity = entity_registry.async_get(ENTITY_ID)
assert entity.unique_id == "AABBCCDD01" assert entity.unique_id == "AABBCCDD01"
@ -96,9 +97,10 @@ async def test_setup_thermostat(hass: HomeAssistant, cube: MaxCube) -> None:
assert state.attributes.get(VALVE_POSITION) == 25 assert state.attributes.get(VALVE_POSITION) == 25
async def test_setup_wallthermostat(hass: HomeAssistant, cube: MaxCube) -> None: async def test_setup_wallthermostat(
hass: HomeAssistant, entity_registry: er.EntityRegistry, cube: MaxCube
) -> None:
"""Test a successful setup of a wall thermostat device.""" """Test a successful setup of a wall thermostat device."""
entity_registry = er.async_get(hass)
assert entity_registry.async_is_registered(WALL_ENTITY_ID) assert entity_registry.async_is_registered(WALL_ENTITY_ID)
entity = entity_registry.async_get(WALL_ENTITY_ID) entity = entity_registry.async_get(WALL_ENTITY_ID)
assert entity.unique_id == "AABBCCDD02" assert entity.unique_id == "AABBCCDD02"

View File

@ -52,13 +52,15 @@ async def test_fail_default_home_entry(
async def test_removing_incorrect_devices( async def test_removing_incorrect_devices(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, mock_weather hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
caplog: pytest.LogCaptureFixture,
mock_weather,
) -> None: ) -> None:
"""Test we remove incorrect devices.""" """Test we remove incorrect devices."""
entry = await init_integration(hass) entry = await init_integration(hass)
device_reg = dr.async_get(hass) device_registry.async_get_or_create(
device_reg.async_get_or_create(
config_entry_id=entry.entry_id, config_entry_id=entry.entry_id,
name="Forecast_legacy", name="Forecast_legacy",
entry_type=dr.DeviceEntryType.SERVICE, entry_type=dr.DeviceEntryType.SERVICE,
@ -71,6 +73,6 @@ async def test_removing_incorrect_devices(
assert await hass.config_entries.async_reload(entry.entry_id) assert await hass.config_entries.async_reload(entry.entry_id)
assert len(hass.config_entries.async_entries(DOMAIN)) == 1 assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert not device_reg.async_get_device(identifiers={(DOMAIN,)}) assert not device_registry.async_get_device(identifiers={(DOMAIN,)})
assert device_reg.async_get_device(identifiers={(DOMAIN, entry.entry_id)}) assert device_registry.async_get_device(identifiers={(DOMAIN, entry.entry_id)})
assert "Removing improper device Forecast_legacy" in caplog.text assert "Removing improper device Forecast_legacy" in caplog.text

View File

@ -6,21 +6,23 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
async def test_new_config_entry(hass: HomeAssistant, mock_weather) -> None: async def test_new_config_entry(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_weather
) -> None:
"""Test the expected entities are created.""" """Test the expected entities are created."""
registry = er.async_get(hass)
await hass.config_entries.flow.async_init("met", context={"source": "onboarding"}) await hass.config_entries.flow.async_init("met", context={"source": "onboarding"})
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(hass.states.async_entity_ids("weather")) == 1 assert len(hass.states.async_entity_ids("weather")) == 1
entry = hass.config_entries.async_entries()[0] entry = hass.config_entries.async_entries()[0]
assert len(er.async_entries_for_config_entry(registry, entry.entry_id)) == 1 assert len(er.async_entries_for_config_entry(entity_registry, entry.entry_id)) == 1
async def test_legacy_config_entry(hass: HomeAssistant, mock_weather) -> None: async def test_legacy_config_entry(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_weather
) -> None:
"""Test the expected entities are created.""" """Test the expected entities are created."""
registry = er.async_get(hass) entity_registry.async_get_or_create(
registry.async_get_or_create(
WEATHER_DOMAIN, WEATHER_DOMAIN,
DOMAIN, DOMAIN,
"home-hourly", "home-hourly",
@ -30,7 +32,7 @@ async def test_legacy_config_entry(hass: HomeAssistant, mock_weather) -> None:
assert len(hass.states.async_entity_ids("weather")) == 2 assert len(hass.states.async_entity_ids("weather")) == 2
entry = hass.config_entries.async_entries()[0] entry = hass.config_entries.async_entries()[0]
assert len(er.async_entries_for_config_entry(registry, entry.entry_id)) == 2 assert len(er.async_entries_for_config_entry(entity_registry, entry.entry_id)) == 2
async def test_tracking_home(hass: HomeAssistant, mock_weather) -> None: async def test_tracking_home(hass: HomeAssistant, mock_weather) -> None:

View File

@ -32,20 +32,22 @@ async def setup_config_entry(hass: HomeAssistant) -> ConfigEntry:
return mock_data return mock_data
async def test_new_config_entry(hass: HomeAssistant, mock_weather) -> None: async def test_new_config_entry(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_weather
) -> None:
"""Test the expected entities are created.""" """Test the expected entities are created."""
registry = er.async_get(hass)
await setup_config_entry(hass) await setup_config_entry(hass)
assert len(hass.states.async_entity_ids("weather")) == 1 assert len(hass.states.async_entity_ids("weather")) == 1
entry = hass.config_entries.async_entries()[0] entry = hass.config_entries.async_entries()[0]
assert len(er.async_entries_for_config_entry(registry, entry.entry_id)) == 1 assert len(er.async_entries_for_config_entry(entity_registry, entry.entry_id)) == 1
async def test_legacy_config_entry(hass: HomeAssistant, mock_weather) -> None: async def test_legacy_config_entry(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_weather
) -> None:
"""Test the expected entities are created.""" """Test the expected entities are created."""
registry = er.async_get(hass) entity_registry.async_get_or_create(
registry.async_get_or_create(
WEATHER_DOMAIN, WEATHER_DOMAIN,
DOMAIN, DOMAIN,
"10-20-hourly", "10-20-hourly",
@ -54,7 +56,7 @@ async def test_legacy_config_entry(hass: HomeAssistant, mock_weather) -> None:
assert len(hass.states.async_entity_ids("weather")) == 2 assert len(hass.states.async_entity_ids("weather")) == 2
entry = hass.config_entries.async_entries()[0] entry = hass.config_entries.async_entries()[0]
assert len(er.async_entries_for_config_entry(registry, entry.entry_id)) == 2 assert len(er.async_entries_for_config_entry(entity_registry, entry.entry_id)) == 2
async def test_weather(hass: HomeAssistant, mock_weather) -> None: async def test_weather(hass: HomeAssistant, mock_weather) -> None:

View File

@ -89,6 +89,7 @@ from tests.common import MockConfigEntry
) )
async def test_migrate_unique_id( async def test_migrate_unique_id(
hass: HomeAssistant, hass: HomeAssistant,
entity_registry: er.EntityRegistry,
old_unique_id: str, old_unique_id: str,
new_unique_id: str, new_unique_id: str,
migration_needed: bool, migration_needed: bool,
@ -102,9 +103,7 @@ async def test_migrate_unique_id(
) )
entry.add_to_hass(hass) entry.add_to_hass(hass)
ent_reg = er.async_get(hass) entity: er.RegistryEntry = entity_registry.async_get_or_create(
entity: er.RegistryEntry = ent_reg.async_get_or_create(
suggested_object_id="my_sensor", suggested_object_id="my_sensor",
disabled_by=None, disabled_by=None,
domain=SENSOR_DOMAIN, domain=SENSOR_DOMAIN,
@ -118,9 +117,12 @@ async def test_migrate_unique_id(
await hass.async_block_till_done() await hass.async_block_till_done()
if migration_needed: if migration_needed:
assert ent_reg.async_get_entity_id(SENSOR_DOMAIN, DOMAIN, old_unique_id) is None assert (
entity_registry.async_get_entity_id(SENSOR_DOMAIN, DOMAIN, old_unique_id)
is None
)
assert ( assert (
ent_reg.async_get_entity_id(SENSOR_DOMAIN, DOMAIN, new_unique_id) entity_registry.async_get_entity_id(SENSOR_DOMAIN, DOMAIN, new_unique_id)
== "sensor.my_sensor" == "sensor.my_sensor"
) )

View File

@ -100,13 +100,15 @@ async def test_site_cannot_connect(
@pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC)) @pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC))
async def test_site_cannot_update( async def test_site_cannot_update(
hass: HomeAssistant, requests_mock: requests_mock.Mocker, wavertree_data hass: HomeAssistant,
entity_registry: er.EntityRegistry,
requests_mock: requests_mock.Mocker,
wavertree_data,
) -> None: ) -> None:
"""Test we handle cannot connect error.""" """Test we handle cannot connect error."""
registry = er.async_get(hass)
# Pre-create the hourly entity # Pre-create the hourly entity
registry.async_get_or_create( entity_registry.async_get_or_create(
WEATHER_DOMAIN, WEATHER_DOMAIN,
DOMAIN, DOMAIN,
"53.38374_-2.90929", "53.38374_-2.90929",
@ -143,13 +145,15 @@ async def test_site_cannot_update(
@pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC)) @pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC))
async def test_one_weather_site_running( async def test_one_weather_site_running(
hass: HomeAssistant, requests_mock: requests_mock.Mocker, wavertree_data hass: HomeAssistant,
entity_registry: er.EntityRegistry,
requests_mock: requests_mock.Mocker,
wavertree_data,
) -> None: ) -> None:
"""Test the Met Office weather platform.""" """Test the Met Office weather platform."""
registry = er.async_get(hass)
# Pre-create the hourly entity # Pre-create the hourly entity
registry.async_get_or_create( entity_registry.async_get_or_create(
WEATHER_DOMAIN, WEATHER_DOMAIN,
DOMAIN, DOMAIN,
"53.38374_-2.90929", "53.38374_-2.90929",
@ -219,19 +223,21 @@ async def test_one_weather_site_running(
@pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC)) @pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC))
async def test_two_weather_sites_running( async def test_two_weather_sites_running(
hass: HomeAssistant, requests_mock: requests_mock.Mocker, wavertree_data hass: HomeAssistant,
entity_registry: er.EntityRegistry,
requests_mock: requests_mock.Mocker,
wavertree_data,
) -> None: ) -> None:
"""Test we handle two different weather sites both running.""" """Test we handle two different weather sites both running."""
registry = er.async_get(hass)
# Pre-create the hourly entities # Pre-create the hourly entities
registry.async_get_or_create( entity_registry.async_get_or_create(
WEATHER_DOMAIN, WEATHER_DOMAIN,
DOMAIN, DOMAIN,
"53.38374_-2.90929", "53.38374_-2.90929",
suggested_object_id="met_office_wavertree_3_hourly", suggested_object_id="met_office_wavertree_3_hourly",
) )
registry.async_get_or_create( entity_registry.async_get_or_create(
WEATHER_DOMAIN, WEATHER_DOMAIN,
DOMAIN, DOMAIN,
"52.75556_0.44231", "52.75556_0.44231",
@ -369,9 +375,10 @@ async def test_two_weather_sites_running(
@pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC)) @pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC))
async def test_new_config_entry(hass: HomeAssistant, no_sensor, wavertree_data) -> None: async def test_new_config_entry(
hass: HomeAssistant, entity_registry: er.EntityRegistry, no_sensor, wavertree_data
) -> None:
"""Test the expected entities are created.""" """Test the expected entities are created."""
registry = er.async_get(hass)
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -383,17 +390,16 @@ async def test_new_config_entry(hass: HomeAssistant, no_sensor, wavertree_data)
assert len(hass.states.async_entity_ids(WEATHER_DOMAIN)) == 1 assert len(hass.states.async_entity_ids(WEATHER_DOMAIN)) == 1
entry = hass.config_entries.async_entries()[0] entry = hass.config_entries.async_entries()[0]
assert len(er.async_entries_for_config_entry(registry, entry.entry_id)) == 1 assert len(er.async_entries_for_config_entry(entity_registry, entry.entry_id)) == 1
@pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC)) @pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC))
async def test_legacy_config_entry( async def test_legacy_config_entry(
hass: HomeAssistant, no_sensor, wavertree_data hass: HomeAssistant, entity_registry: er.EntityRegistry, no_sensor, wavertree_data
) -> None: ) -> None:
"""Test the expected entities are created.""" """Test the expected entities are created."""
registry = er.async_get(hass)
# Pre-create the hourly entity # Pre-create the hourly entity
registry.async_get_or_create( entity_registry.async_get_or_create(
WEATHER_DOMAIN, WEATHER_DOMAIN,
DOMAIN, DOMAIN,
"53.38374_-2.90929", "53.38374_-2.90929",
@ -411,7 +417,7 @@ async def test_legacy_config_entry(
assert len(hass.states.async_entity_ids("weather")) == 2 assert len(hass.states.async_entity_ids("weather")) == 2
entry = hass.config_entries.async_entries()[0] entry = hass.config_entries.async_entries()[0]
assert len(er.async_entries_for_config_entry(registry, entry.entry_id)) == 2 assert len(er.async_entries_for_config_entry(entity_registry, entry.entry_id)) == 2
@pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC)) @pytest.mark.freeze_time(datetime.datetime(2020, 4, 25, 12, tzinfo=datetime.UTC))
@ -510,6 +516,7 @@ async def test_forecast_service(
async def test_forecast_subscription( async def test_forecast_subscription(
hass: HomeAssistant, hass: HomeAssistant,
hass_ws_client: WebSocketGenerator, hass_ws_client: WebSocketGenerator,
entity_registry: er.EntityRegistry,
freezer: FrozenDateTimeFactory, freezer: FrozenDateTimeFactory,
snapshot: SnapshotAssertion, snapshot: SnapshotAssertion,
no_sensor, no_sensor,
@ -519,9 +526,8 @@ async def test_forecast_subscription(
"""Test multiple forecast.""" """Test multiple forecast."""
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
registry = er.async_get(hass)
# Pre-create the hourly entity # Pre-create the hourly entity
registry.async_get_or_create( entity_registry.async_get_or_create(
WEATHER_DOMAIN, WEATHER_DOMAIN,
DOMAIN, DOMAIN,
"53.38374_-2.90929", "53.38374_-2.90929",

View File

@ -208,29 +208,30 @@ async def test_hub_wifiwave2(hass: HomeAssistant, mock_device_registry_devices)
assert device_4.attributes["host_name"] == "Device_4" assert device_4.attributes["host_name"] == "Device_4"
async def test_restoring_devices(hass: HomeAssistant) -> None: async def test_restoring_devices(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test restoring existing device_tracker entities if not detected on startup.""" """Test restoring existing device_tracker entities if not detected on startup."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=mikrotik.DOMAIN, data=MOCK_DATA, options=MOCK_OPTIONS domain=mikrotik.DOMAIN, data=MOCK_DATA, options=MOCK_OPTIONS
) )
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
registry = er.async_get(hass) entity_registry.async_get_or_create(
registry.async_get_or_create(
device_tracker.DOMAIN, device_tracker.DOMAIN,
mikrotik.DOMAIN, mikrotik.DOMAIN,
"00:00:00:00:00:01", "00:00:00:00:00:01",
suggested_object_id="device_1", suggested_object_id="device_1",
config_entry=config_entry, config_entry=config_entry,
) )
registry.async_get_or_create( entity_registry.async_get_or_create(
device_tracker.DOMAIN, device_tracker.DOMAIN,
mikrotik.DOMAIN, mikrotik.DOMAIN,
"00:00:00:00:00:02", "00:00:00:00:00:02",
suggested_object_id="device_2", suggested_object_id="device_2",
config_entry=config_entry, config_entry=config_entry,
) )
registry.async_get_or_create( entity_registry.async_get_or_create(
device_tracker.DOMAIN, device_tracker.DOMAIN,
mikrotik.DOMAIN, mikrotik.DOMAIN,
"00:00:00:00:00:03", "00:00:00:00:00:03",

View File

@ -11,6 +11,7 @@ from tests.common import MockConfigEntry
@pytest.mark.parametrize("platform", ("sensor",)) @pytest.mark.parametrize("platform", ("sensor",))
async def test_setup_and_remove_config_entry( async def test_setup_and_remove_config_entry(
hass: HomeAssistant, hass: HomeAssistant,
entity_registry: er.EntityRegistry,
platform: str, platform: str,
) -> None: ) -> None:
"""Test setting up and removing a config entry.""" """Test setting up and removing a config entry."""
@ -19,7 +20,6 @@ async def test_setup_and_remove_config_entry(
input_sensors = ["sensor.input_one", "sensor.input_two"] input_sensors = ["sensor.input_one", "sensor.input_two"]
registry = er.async_get(hass)
min_max_entity_id = f"{platform}.my_min_max" min_max_entity_id = f"{platform}.my_min_max"
# Setup the config entry # Setup the config entry
@ -39,7 +39,7 @@ async def test_setup_and_remove_config_entry(
await hass.async_block_till_done() await hass.async_block_till_done()
# Check the entity is registered in the entity registry # Check the entity is registered in the entity registry
assert registry.async_get(min_max_entity_id) is not None assert entity_registry.async_get(min_max_entity_id) is not None
# Check the platform is setup correctly # Check the platform is setup correctly
state = hass.states.get(min_max_entity_id) state = hass.states.get(min_max_entity_id)
@ -51,4 +51,4 @@ async def test_setup_and_remove_config_entry(
# Check the state and entity registry entry are removed # Check the state and entity registry entry are removed
assert hass.states.get(min_max_entity_id) is None assert hass.states.get(min_max_entity_id) is None
assert registry.async_get(min_max_entity_id) is None assert entity_registry.async_get(min_max_entity_id) is None

View File

@ -60,7 +60,9 @@ async def test_default_name_sensor(hass: HomeAssistant) -> None:
assert entity_ids[2] == state.attributes.get("min_entity_id") assert entity_ids[2] == state.attributes.get("min_entity_id")
async def test_min_sensor(hass: HomeAssistant) -> None: async def test_min_sensor(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test the min sensor.""" """Test the min sensor."""
config = { config = {
"sensor": { "sensor": {
@ -87,8 +89,7 @@ async def test_min_sensor(hass: HomeAssistant) -> None:
assert entity_ids[2] == state.attributes.get("min_entity_id") assert entity_ids[2] == state.attributes.get("min_entity_id")
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entity_reg = er.async_get(hass) entity = entity_registry.async_get("sensor.test_min")
entity = entity_reg.async_get("sensor.test_min")
assert entity.unique_id == "very_unique_id" assert entity.unique_id == "very_unique_id"
@ -470,7 +471,9 @@ async def test_sensor_incorrect_state(
assert "Unable to store state. Only numerical states are supported" in caplog.text assert "Unable to store state. Only numerical states are supported" in caplog.text
async def test_sum_sensor(hass: HomeAssistant) -> None: async def test_sum_sensor(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test the sum sensor.""" """Test the sum sensor."""
config = { config = {
"sensor": { "sensor": {
@ -496,8 +499,7 @@ async def test_sum_sensor(hass: HomeAssistant) -> None:
assert str(float(SUM_VALUE)) == state.state assert str(float(SUM_VALUE)) == state.state
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entity_reg = er.async_get(hass) entity = entity_registry.async_get("sensor.test_sum")
entity = entity_reg.async_get("sensor.test_sum")
assert entity.unique_id == "very_unique_id_sum_sensor" assert entity.unique_id == "very_unique_id_sum_sensor"

View File

@ -178,7 +178,10 @@ async def test_setup_entry_not_ready(
async def test_entry_migration( async def test_entry_migration(
hass: HomeAssistant, v1_mock_config_entry: MockConfigEntry hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
v1_mock_config_entry: MockConfigEntry,
) -> None: ) -> None:
"""Test entry migration from version 1 to 3, where host and port is required for the connection to the server.""" """Test entry migration from version 1 to 3, where host and port is required for the connection to the server."""
v1_mock_config_entry.add_to_hass(hass) v1_mock_config_entry.add_to_hass(hass)
@ -218,12 +221,10 @@ async def test_entry_migration(
assert migrated_config_entry.state == ConfigEntryState.LOADED assert migrated_config_entry.state == ConfigEntryState.LOADED
# Test migrated device entry. # Test migrated device entry.
device_registry = dr.async_get(hass)
device_entry = device_registry.async_get(device_entry_id) device_entry = device_registry.async_get(device_entry_id)
assert device_entry.identifiers == {(DOMAIN, migrated_config_entry.entry_id)} assert device_entry.identifiers == {(DOMAIN, migrated_config_entry.entry_id)}
# Test migrated sensor entity entries. # Test migrated sensor entity entries.
entity_registry = er.async_get(hass)
for mapping in sensor_entity_id_key_mapping_list: for mapping in sensor_entity_id_key_mapping_list:
entity_entry = entity_registry.async_get(mapping["entity_id"]) entity_entry = entity_registry.async_get(mapping["entity_id"])
assert ( assert (

View File

@ -9,7 +9,10 @@ from homeassistant.helpers import device_registry as dr
async def test_sensor( async def test_sensor(
hass: HomeAssistant, create_registrations, webhook_client hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
create_registrations,
webhook_client,
) -> None: ) -> None:
"""Test that sensors can be registered and updated.""" """Test that sensors can be registered and updated."""
webhook_id = create_registrations[1]["webhook_id"] webhook_id = create_registrations[1]["webhook_id"]
@ -77,8 +80,7 @@ async def test_sensor(
assert updated_entity.state == "off" assert updated_entity.state == "off"
assert "foo" not in updated_entity.attributes assert "foo" not in updated_entity.attributes
dev_reg = dr.async_get(hass) assert len(device_registry.devices) == len(create_registrations)
assert len(dev_reg.devices) == len(create_registrations)
# Reload to verify state is restored # Reload to verify state is restored
config_entry = hass.config_entries.async_entries("mobile_app")[1] config_entry = hass.config_entries.async_entries("mobile_app")[1]

View File

@ -28,14 +28,16 @@ async def test_unload_unloads(
assert len(calls) == 1 assert len(calls) == 1
async def test_remove_entry(hass: HomeAssistant, create_registrations) -> None: async def test_remove_entry(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
create_registrations,
) -> None:
"""Test we clean up when we remove entry.""" """Test we clean up when we remove entry."""
for config_entry in hass.config_entries.async_entries("mobile_app"): for config_entry in hass.config_entries.async_entries("mobile_app"):
await hass.config_entries.async_remove(config_entry.entry_id) await hass.config_entries.async_remove(config_entry.entry_id)
assert config_entry.data["webhook_id"] in hass.data[DOMAIN][DATA_DELETED_IDS] assert config_entry.data["webhook_id"] in hass.data[DOMAIN][DATA_DELETED_IDS]
dev_reg = dr.async_get(hass) assert len(device_registry.devices) == 0
assert len(dev_reg.devices) == 0 assert len(entity_registry.entities) == 0
ent_reg = er.async_get(hass)
assert len(ent_reg.entities) == 0

View File

@ -25,6 +25,8 @@ from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM
) )
async def test_sensor( async def test_sensor(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
create_registrations, create_registrations,
webhook_client, webhook_client,
unit_system, unit_system,
@ -77,9 +79,7 @@ async def test_sensor(
assert entity.state == state1 assert entity.state == state1
assert ( assert (
er.async_get(hass) entity_registry.async_get("sensor.test_1_battery_temperature").entity_category
.async_get("sensor.test_1_battery_temperature")
.entity_category
== "diagnostic" == "diagnostic"
) )
@ -109,8 +109,7 @@ async def test_sensor(
assert updated_entity.state == state2 assert updated_entity.state == state2
assert "foo" not in updated_entity.attributes assert "foo" not in updated_entity.attributes
dev_reg = dr.async_get(hass) assert len(device_registry.devices) == len(create_registrations)
assert len(dev_reg.devices) == len(create_registrations)
# Reload to verify state is restored # Reload to verify state is restored
config_entry = hass.config_entries.async_entries("mobile_app")[1] config_entry = hass.config_entries.async_entries("mobile_app")[1]
@ -503,7 +502,10 @@ async def test_sensor_datetime(
async def test_default_disabling_entity( async def test_default_disabling_entity(
hass: HomeAssistant, create_registrations, webhook_client hass: HomeAssistant,
entity_registry: er.EntityRegistry,
create_registrations,
webhook_client,
) -> None: ) -> None:
"""Test that sensors can be disabled by default upon registration.""" """Test that sensors can be disabled by default upon registration."""
webhook_id = create_registrations[1]["webhook_id"] webhook_id = create_registrations[1]["webhook_id"]
@ -532,13 +534,16 @@ async def test_default_disabling_entity(
assert entity is None assert entity is None
assert ( assert (
er.async_get(hass).async_get("sensor.test_1_battery_state").disabled_by entity_registry.async_get("sensor.test_1_battery_state").disabled_by
== er.RegistryEntryDisabler.INTEGRATION == er.RegistryEntryDisabler.INTEGRATION
) )
async def test_updating_disabled_sensor( async def test_updating_disabled_sensor(
hass: HomeAssistant, create_registrations, webhook_client hass: HomeAssistant,
entity_registry: er.EntityRegistry,
create_registrations,
webhook_client,
) -> None: ) -> None:
"""Test that sensors return error if disabled in instance.""" """Test that sensors return error if disabled in instance."""
webhook_id = create_registrations[1]["webhook_id"] webhook_id = create_registrations[1]["webhook_id"]
@ -580,7 +585,7 @@ async def test_updating_disabled_sensor(
assert json["battery_state"]["success"] is True assert json["battery_state"]["success"] is True
assert "is_disabled" not in json["battery_state"] assert "is_disabled" not in json["battery_state"]
er.async_get(hass).async_update_entity( entity_registry.async_update_entity(
"sensor.test_1_battery_state", disabled_by=er.RegistryEntryDisabler.USER "sensor.test_1_battery_state", disabled_by=er.RegistryEntryDisabler.USER
) )

View File

@ -854,12 +854,13 @@ async def test_webhook_camera_stream_stream_available_but_errors(
async def test_webhook_handle_scan_tag( async def test_webhook_handle_scan_tag(
hass: HomeAssistant, create_registrations, webhook_client hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
create_registrations,
webhook_client,
) -> None: ) -> None:
"""Test that we can scan tags.""" """Test that we can scan tags."""
device = dr.async_get(hass).async_get_device( device = device_registry.async_get_device(identifiers={(DOMAIN, "mock-device-id")})
identifiers={(DOMAIN, "mock-device-id")}
)
assert device is not None assert device is not None
events = async_capture_events(hass, EVENT_TAG_SCANNED) events = async_capture_events(hass, EVENT_TAG_SCANNED)
@ -920,7 +921,10 @@ async def test_register_sensor_limits_state_class(
async def test_reregister_sensor( async def test_reregister_sensor(
hass: HomeAssistant, create_registrations, webhook_client hass: HomeAssistant,
entity_registry: er.EntityRegistry,
create_registrations,
webhook_client,
) -> None: ) -> None:
"""Test that we can add more info in re-registration.""" """Test that we can add more info in re-registration."""
webhook_id = create_registrations[1]["webhook_id"] webhook_id = create_registrations[1]["webhook_id"]
@ -941,8 +945,7 @@ async def test_reregister_sensor(
assert reg_resp.status == HTTPStatus.CREATED assert reg_resp.status == HTTPStatus.CREATED
ent_reg = er.async_get(hass) entry = entity_registry.async_get("sensor.test_1_battery_state")
entry = ent_reg.async_get("sensor.test_1_battery_state")
assert entry.original_name == "Test 1 Battery State" assert entry.original_name == "Test 1 Battery State"
assert entry.device_class is None assert entry.device_class is None
assert entry.unit_of_measurement is None assert entry.unit_of_measurement is None
@ -970,7 +973,7 @@ async def test_reregister_sensor(
) )
assert reg_resp.status == HTTPStatus.CREATED assert reg_resp.status == HTTPStatus.CREATED
entry = ent_reg.async_get("sensor.test_1_battery_state") entry = entity_registry.async_get("sensor.test_1_battery_state")
assert entry.original_name == "Test 1 New Name" assert entry.original_name == "Test 1 New Name"
assert entry.device_class == "battery" assert entry.device_class == "battery"
assert entry.unit_of_measurement == "%" assert entry.unit_of_measurement == "%"
@ -992,7 +995,7 @@ async def test_reregister_sensor(
) )
assert reg_resp.status == HTTPStatus.CREATED assert reg_resp.status == HTTPStatus.CREATED
entry = ent_reg.async_get("sensor.test_1_battery_state") entry = entity_registry.async_get("sensor.test_1_battery_state")
assert entry.disabled_by is None assert entry.disabled_by is None
reg_resp = await webhook_client.post( reg_resp = await webhook_client.post(
@ -1014,7 +1017,7 @@ async def test_reregister_sensor(
) )
assert reg_resp.status == HTTPStatus.CREATED assert reg_resp.status == HTTPStatus.CREATED
entry = ent_reg.async_get("sensor.test_1_battery_state") entry = entity_registry.async_get("sensor.test_1_battery_state")
assert entry.original_name == "Test 1 New Name 2" assert entry.original_name == "Test 1 New Name 2"
assert entry.device_class is None assert entry.device_class is None
assert entry.unit_of_measurement is None assert entry.unit_of_measurement is None
@ -1067,6 +1070,7 @@ async def test_webhook_handle_conversation_process(
async def test_sending_sensor_state( async def test_sending_sensor_state(
hass: HomeAssistant, hass: HomeAssistant,
entity_registry: er.EntityRegistry,
create_registrations, create_registrations,
webhook_client, webhook_client,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
@ -1105,8 +1109,7 @@ async def test_sending_sensor_state(
assert reg_resp.status == HTTPStatus.CREATED assert reg_resp.status == HTTPStatus.CREATED
ent_reg = er.async_get(hass) entry = entity_registry.async_get("sensor.test_1_battery_state")
entry = ent_reg.async_get("sensor.test_1_battery_state")
assert entry.original_name == "Test 1 Battery State" assert entry.original_name == "Test 1 Battery State"
assert entry.device_class is None assert entry.device_class is None
assert entry.unit_of_measurement is None assert entry.unit_of_measurement is None

View File

@ -445,11 +445,14 @@ async def test_config_virtual_binary_sensor(hass: HomeAssistant, mock_modbus) ->
], ],
) )
async def test_virtual_binary_sensor( async def test_virtual_binary_sensor(
hass: HomeAssistant, expected, slaves, mock_do_cycle hass: HomeAssistant,
entity_registry: er.EntityRegistry,
expected,
slaves,
mock_do_cycle,
) -> None: ) -> None:
"""Run test for given config.""" """Run test for given config."""
assert hass.states.get(ENTITY_ID).state == expected assert hass.states.get(ENTITY_ID).state == expected
entity_registry = er.async_get(hass)
for i, slave in enumerate(slaves): for i, slave in enumerate(slaves):
entity_id = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}_{i+1}".replace(" ", "_") entity_id = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}_{i+1}".replace(" ", "_")

View File

@ -869,9 +869,10 @@ async def test_all_sensor(hass: HomeAssistant, mock_do_cycle, expected) -> None:
), ),
], ],
) )
async def test_virtual_sensor(hass: HomeAssistant, mock_do_cycle, expected) -> None: async def test_virtual_sensor(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_do_cycle, expected
) -> None:
"""Run test for sensor.""" """Run test for sensor."""
entity_registry = er.async_get(hass)
for i in range(0, len(expected)): for i in range(0, len(expected)):
entity_id = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}".replace(" ", "_") entity_id = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}".replace(" ", "_")
unique_id = f"{SLAVE_UNIQUE_ID}" unique_id = f"{SLAVE_UNIQUE_ID}"

View File

@ -11,20 +11,20 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_binary_sensors( async def test_binary_sensors(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker hass: HomeAssistant,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
) -> None: ) -> None:
"""Test the creation and values of the Modern Forms sensors.""" """Test the creation and values of the Modern Forms sensors."""
registry = er.async_get(hass) entity_registry.async_get_or_create(
registry.async_get_or_create(
BINARY_SENSOR_DOMAIN, BINARY_SENSOR_DOMAIN,
DOMAIN, DOMAIN,
"AA:BB:CC:DD:EE:FF_light_sleep_timer_active", "AA:BB:CC:DD:EE:FF_light_sleep_timer_active",
suggested_object_id="modernformsfan_light_sleep_timer_active", suggested_object_id="modernformsfan_light_sleep_timer_active",
disabled_by=None, disabled_by=None,
) )
registry.async_get_or_create( entity_registry.async_get_or_create(
BINARY_SENSOR_DOMAIN, BINARY_SENSOR_DOMAIN,
DOMAIN, DOMAIN,
"AA:BB:CC:DD:EE:FF_fan_sleep_timer_active", "AA:BB:CC:DD:EE:FF_fan_sleep_timer_active",

View File

@ -35,13 +35,13 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_fan_state( async def test_fan_state(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker hass: HomeAssistant,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
) -> None: ) -> None:
"""Test the creation and values of the Modern Forms fans.""" """Test the creation and values of the Modern Forms fans."""
await init_integration(hass, aioclient_mock) await init_integration(hass, aioclient_mock)
entity_registry = er.async_get(hass)
state = hass.states.get("fan.modernformsfan_fan") state = hass.states.get("fan.modernformsfan_fan")
assert state assert state
assert state.attributes.get(ATTR_PERCENTAGE) == 50 assert state.attributes.get(ATTR_PERCENTAGE) == 50

View File

@ -38,13 +38,14 @@ async def test_unload_config_entry(
async def test_fan_only_device( async def test_fan_only_device(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker hass: HomeAssistant,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
) -> None: ) -> None:
"""Test we set unique ID if not set yet.""" """Test we set unique ID if not set yet."""
await init_integration( await init_integration(
hass, aioclient_mock, mock_type=modern_forms_no_light_call_mock hass, aioclient_mock, mock_type=modern_forms_no_light_call_mock
) )
entity_registry = er.async_get(hass)
fan_entry = entity_registry.async_get("fan.modernformsfan_fan") fan_entry = entity_registry.async_get("fan.modernformsfan_fan")
assert fan_entry assert fan_entry

View File

@ -28,13 +28,13 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_light_state( async def test_light_state(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker hass: HomeAssistant,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
) -> None: ) -> None:
"""Test the creation and values of the Modern Forms lights.""" """Test the creation and values of the Modern Forms lights."""
await init_integration(hass, aioclient_mock) await init_integration(hass, aioclient_mock)
entity_registry = er.async_get(hass)
state = hass.states.get("light.modernformsfan_light") state = hass.states.get("light.modernformsfan_light")
assert state assert state
assert state.attributes.get(ATTR_BRIGHTNESS) == 128 assert state.attributes.get(ATTR_BRIGHTNESS) == 128

View File

@ -4,7 +4,6 @@ from datetime import datetime
from homeassistant.components.sensor import SensorDeviceClass from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.const import ATTR_DEVICE_CLASS, ATTR_ICON from homeassistant.const import ATTR_DEVICE_CLASS, ATTR_ICON
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from . import init_integration, modern_forms_timers_set_mock from . import init_integration, modern_forms_timers_set_mock
@ -18,7 +17,6 @@ async def test_sensors(
# await init_integration(hass, aioclient_mock) # await init_integration(hass, aioclient_mock)
await init_integration(hass, aioclient_mock) await init_integration(hass, aioclient_mock)
er.async_get(hass)
# Light timer remaining time # Light timer remaining time
state = hass.states.get("sensor.modernformsfan_light_sleep_time") state = hass.states.get("sensor.modernformsfan_light_sleep_time")
@ -42,7 +40,6 @@ async def test_active_sensors(
# await init_integration(hass, aioclient_mock) # await init_integration(hass, aioclient_mock)
await init_integration(hass, aioclient_mock, mock_type=modern_forms_timers_set_mock) await init_integration(hass, aioclient_mock, mock_type=modern_forms_timers_set_mock)
er.async_get(hass)
# Light timer remaining time # Light timer remaining time
state = hass.states.get("sensor.modernformsfan_light_sleep_time") state = hass.states.get("sensor.modernformsfan_light_sleep_time")

View File

@ -22,13 +22,13 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_switch_state( async def test_switch_state(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker hass: HomeAssistant,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
) -> None: ) -> None:
"""Test the creation and values of the Modern Forms switches.""" """Test the creation and values of the Modern Forms switches."""
await init_integration(hass, aioclient_mock) await init_integration(hass, aioclient_mock)
entity_registry = er.async_get(hass)
state = hass.states.get("switch.modernformsfan_away_mode") state = hass.states.get("switch.modernformsfan_away_mode")
assert state assert state
assert state.attributes.get(ATTR_ICON) == "mdi:airplane-takeoff" assert state.attributes.get(ATTR_ICON) == "mdi:airplane-takeoff"

View File

@ -489,45 +489,45 @@ async def test_volume_up_down(hass: HomeAssistant) -> None:
assert monoprice.zones[11].volume == 37 assert monoprice.zones[11].volume == 37
async def test_first_run_with_available_zones(hass: HomeAssistant) -> None: async def test_first_run_with_available_zones(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test first run with all zones available.""" """Test first run with all zones available."""
monoprice = MockMonoprice() monoprice = MockMonoprice()
await _setup_monoprice(hass, monoprice) await _setup_monoprice(hass, monoprice)
registry = er.async_get(hass) entry = entity_registry.async_get(ZONE_7_ID)
entry = registry.async_get(ZONE_7_ID)
assert not entry.disabled assert not entry.disabled
async def test_first_run_with_failing_zones(hass: HomeAssistant) -> None: async def test_first_run_with_failing_zones(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test first run with failed zones.""" """Test first run with failed zones."""
monoprice = MockMonoprice() monoprice = MockMonoprice()
with patch.object(MockMonoprice, "zone_status", side_effect=SerialException): with patch.object(MockMonoprice, "zone_status", side_effect=SerialException):
await _setup_monoprice(hass, monoprice) await _setup_monoprice(hass, monoprice)
registry = er.async_get(hass) entry = entity_registry.async_get(ZONE_1_ID)
entry = registry.async_get(ZONE_1_ID)
assert not entry.disabled assert not entry.disabled
entry = registry.async_get(ZONE_7_ID) entry = entity_registry.async_get(ZONE_7_ID)
assert entry.disabled assert entry.disabled
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
async def test_not_first_run_with_failing_zone(hass: HomeAssistant) -> None: async def test_not_first_run_with_failing_zone(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test first run with failed zones.""" """Test first run with failed zones."""
monoprice = MockMonoprice() monoprice = MockMonoprice()
with patch.object(MockMonoprice, "zone_status", side_effect=SerialException): with patch.object(MockMonoprice, "zone_status", side_effect=SerialException):
await _setup_monoprice_not_first_run(hass, monoprice) await _setup_monoprice_not_first_run(hass, monoprice)
registry = er.async_get(hass) entry = entity_registry.async_get(ZONE_1_ID)
entry = registry.async_get(ZONE_1_ID)
assert not entry.disabled assert not entry.disabled
entry = registry.async_get(ZONE_7_ID) entry = entity_registry.async_get(ZONE_7_ID)
assert not entry.disabled assert not entry.disabled

View File

@ -39,6 +39,8 @@ from tests.common import MockConfigEntry
) )
async def test_moon_day( async def test_moon_day(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
mock_config_entry: MockConfigEntry, mock_config_entry: MockConfigEntry,
moon_value: float, moon_value: float,
native_value: str, native_value: str,
@ -70,13 +72,11 @@ async def test_moon_day(
STATE_WANING_CRESCENT, STATE_WANING_CRESCENT,
] ]
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("sensor.moon_phase") entry = entity_registry.async_get("sensor.moon_phase")
assert entry assert entry
assert entry.unique_id == mock_config_entry.entry_id assert entry.unique_id == mock_config_entry.entry_id
assert entry.translation_key == "phase" assert entry.translation_key == "phase"
device_registry = dr.async_get(hass)
assert entry.device_id assert entry.device_id
device_entry = device_registry.async_get(entry.device_id) device_entry = device_registry.async_get(entry.device_id)
assert device_entry assert device_entry

View File

@ -135,10 +135,12 @@ async def test_setup_camera_new_data_same(hass: HomeAssistant) -> None:
assert hass.states.get(TEST_CAMERA_ENTITY_ID) assert hass.states.get(TEST_CAMERA_ENTITY_ID)
async def test_setup_camera_new_data_camera_removed(hass: HomeAssistant) -> None: async def test_setup_camera_new_data_camera_removed(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test a data refresh with a removed camera.""" """Test a data refresh with a removed camera."""
device_registry = dr.async_get(hass)
entity_registry = er.async_get(hass)
client = create_mock_motioneye_client() client = create_mock_motioneye_client()
config_entry = await setup_mock_motioneye_config_entry(hass, client=client) config_entry = await setup_mock_motioneye_config_entry(hass, client=client)
@ -315,12 +317,15 @@ async def test_state_attributes(hass: HomeAssistant) -> None:
assert not entity_state.attributes.get("motion_detection") assert not entity_state.attributes.get("motion_detection")
async def test_device_info(hass: HomeAssistant) -> None: async def test_device_info(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Verify device information includes expected details.""" """Verify device information includes expected details."""
entry = await setup_mock_motioneye_config_entry(hass) entry = await setup_mock_motioneye_config_entry(hass)
device_identifier = get_motioneye_device_identifier(entry.entry_id, TEST_CAMERA_ID) device_identifier = get_motioneye_device_identifier(entry.entry_id, TEST_CAMERA_ID)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device(identifiers={device_identifier}) device = device_registry.async_get_device(identifiers={device_identifier})
assert device assert device
@ -330,7 +335,6 @@ async def test_device_info(hass: HomeAssistant) -> None:
assert device.model == MOTIONEYE_MANUFACTURER assert device.model == MOTIONEYE_MANUFACTURER
assert device.name == TEST_CAMERA_NAME assert device.name == TEST_CAMERA_NAME
entity_registry = er.async_get(hass)
entities_from_device = [ entities_from_device = [
entry.entity_id entry.entity_id
for entry in er.async_entries_for_device(entity_registry, device.id) for entry in er.async_entries_for_device(entity_registry, device.id)

View File

@ -78,13 +78,14 @@ async def setup_media_source(hass) -> None:
assert await async_setup_component(hass, "media_source", {}) assert await async_setup_component(hass, "media_source", {})
async def test_async_browse_media_success(hass: HomeAssistant) -> None: async def test_async_browse_media_success(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test successful browse media.""" """Test successful browse media."""
client = create_mock_motioneye_client() client = create_mock_motioneye_client()
config = await setup_mock_motioneye_config_entry(hass, client=client) config = await setup_mock_motioneye_config_entry(hass, client=client)
device_registry = dr.async_get(hass)
device = device_registry.async_get_or_create( device = device_registry.async_get_or_create(
config_entry_id=config.entry_id, config_entry_id=config.entry_id,
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER}, identifiers={TEST_CAMERA_DEVICE_IDENTIFIER},
@ -295,13 +296,14 @@ async def test_async_browse_media_success(hass: HomeAssistant) -> None:
} }
async def test_async_browse_media_images_success(hass: HomeAssistant) -> None: async def test_async_browse_media_images_success(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test successful browse media of images.""" """Test successful browse media of images."""
client = create_mock_motioneye_client() client = create_mock_motioneye_client()
config = await setup_mock_motioneye_config_entry(hass, client=client) config = await setup_mock_motioneye_config_entry(hass, client=client)
device_registry = dr.async_get(hass)
device = device_registry.async_get_or_create( device = device_registry.async_get_or_create(
config_entry_id=config.entry_id, config_entry_id=config.entry_id,
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER}, identifiers={TEST_CAMERA_DEVICE_IDENTIFIER},
@ -346,14 +348,15 @@ async def test_async_browse_media_images_success(hass: HomeAssistant) -> None:
} }
async def test_async_resolve_media_success(hass: HomeAssistant) -> None: async def test_async_resolve_media_success(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test successful resolve media.""" """Test successful resolve media."""
client = create_mock_motioneye_client() client = create_mock_motioneye_client()
config = await setup_mock_motioneye_config_entry(hass, client=client) config = await setup_mock_motioneye_config_entry(hass, client=client)
device_registry = dr.async_get(hass)
device = device_registry.async_get_or_create( device = device_registry.async_get_or_create(
config_entry_id=config.entry_id, config_entry_id=config.entry_id,
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER}, identifiers={TEST_CAMERA_DEVICE_IDENTIFIER},
@ -380,14 +383,15 @@ async def test_async_resolve_media_success(hass: HomeAssistant) -> None:
assert client.get_image_url.call_args == call(TEST_CAMERA_ID, "/foo.jpg") assert client.get_image_url.call_args == call(TEST_CAMERA_ID, "/foo.jpg")
async def test_async_resolve_media_failure(hass: HomeAssistant) -> None: async def test_async_resolve_media_failure(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test failed resolve media calls.""" """Test failed resolve media calls."""
client = create_mock_motioneye_client() client = create_mock_motioneye_client()
config = await setup_mock_motioneye_config_entry(hass, client=client) config = await setup_mock_motioneye_config_entry(hass, client=client)
device_registry = dr.async_get(hass)
device = device_registry.async_get_or_create( device = device_registry.async_get_or_create(
config_entry_id=config.entry_id, config_entry_id=config.entry_id,
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER}, identifiers={TEST_CAMERA_DEVICE_IDENTIFIER},

View File

@ -73,7 +73,11 @@ async def test_sensor_actions(
assert entity_state.attributes.get(KEY_ACTIONS) is None assert entity_state.attributes.get(KEY_ACTIONS) is None
async def test_sensor_device_info(hass: HomeAssistant) -> None: async def test_sensor_device_info(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Verify device information includes expected details.""" """Verify device information includes expected details."""
# Enable the action sensor (it is disabled by default). # Enable the action sensor (it is disabled by default).
@ -91,11 +95,9 @@ async def test_sensor_device_info(hass: HomeAssistant) -> None:
config_entry.entry_id, TEST_CAMERA_ID config_entry.entry_id, TEST_CAMERA_ID
) )
device_registry = dr.async_get(hass)
device = device_registry.async_get_device(identifiers={device_identifer}) device = device_registry.async_get_device(identifiers={device_identifer})
assert device assert device
entity_registry = er.async_get(hass)
entities_from_device = [ entities_from_device = [
entry.entity_id entry.entity_id
for entry in er.async_entries_for_device(entity_registry, device.id) for entry in er.async_entries_for_device(entity_registry, device.id)
@ -104,12 +106,13 @@ async def test_sensor_device_info(hass: HomeAssistant) -> None:
async def test_sensor_actions_can_be_enabled( async def test_sensor_actions_can_be_enabled(
hass: HomeAssistant, freezer: FrozenDateTimeFactory hass: HomeAssistant,
entity_registry: er.EntityRegistry,
freezer: FrozenDateTimeFactory,
) -> None: ) -> None:
"""Verify the action sensor can be enabled.""" """Verify the action sensor can be enabled."""
client = create_mock_motioneye_client() client = create_mock_motioneye_client()
await setup_mock_motioneye_config_entry(hass, client=client) await setup_mock_motioneye_config_entry(hass, client=client)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get(TEST_SENSOR_ACTION_ENTITY_ID) entry = entity_registry.async_get(TEST_SENSOR_ACTION_ENTITY_ID)
assert entry assert entry

View File

@ -152,7 +152,9 @@ async def test_switch_has_correct_entities(hass: HomeAssistant) -> None:
async def test_disabled_switches_can_be_enabled( async def test_disabled_switches_can_be_enabled(
hass: HomeAssistant, freezer: FrozenDateTimeFactory hass: HomeAssistant,
entity_registry: er.EntityRegistry,
freezer: FrozenDateTimeFactory,
) -> None: ) -> None:
"""Verify disabled switches can be enabled.""" """Verify disabled switches can be enabled."""
client = create_mock_motioneye_client() client = create_mock_motioneye_client()
@ -165,7 +167,6 @@ async def test_disabled_switches_can_be_enabled(
for switch_key in disabled_switch_keys: for switch_key in disabled_switch_keys:
entity_id = f"{TEST_SWITCH_ENTITY_ID_BASE}_{switch_key}" entity_id = f"{TEST_SWITCH_ENTITY_ID_BASE}_{switch_key}"
entity_registry = er.async_get(hass)
entry = entity_registry.async_get(entity_id) entry = entity_registry.async_get(entity_id)
assert entry assert entry
assert entry.disabled assert entry.disabled
@ -191,19 +192,21 @@ async def test_disabled_switches_can_be_enabled(
assert entity_state assert entity_state
async def test_switch_device_info(hass: HomeAssistant) -> None: async def test_switch_device_info(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Verify device information includes expected details.""" """Verify device information includes expected details."""
config_entry = await setup_mock_motioneye_config_entry(hass) config_entry = await setup_mock_motioneye_config_entry(hass)
device_identifer = get_motioneye_device_identifier( device_identifer = get_motioneye_device_identifier(
config_entry.entry_id, TEST_CAMERA_ID config_entry.entry_id, TEST_CAMERA_ID
) )
device_registry = dr.async_get(hass)
device = device_registry.async_get_device(identifiers={device_identifer}) device = device_registry.async_get_device(identifiers={device_identifer})
assert device assert device
entity_registry = er.async_get(hass)
entities_from_device = [ entities_from_device = [
entry.entity_id entry.entity_id
for entry in er.async_entries_for_device(entity_registry, device.id) for entry in er.async_entries_for_device(entity_registry, device.id)

View File

@ -63,12 +63,13 @@ WEB_HOOK_FILE_STORED_QUERY_STRING = (
) )
async def test_setup_camera_without_webhook(hass: HomeAssistant) -> None: async def test_setup_camera_without_webhook(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test a camera with no webhook.""" """Test a camera with no webhook."""
client = create_mock_motioneye_client() client = create_mock_motioneye_client()
config_entry = await setup_mock_motioneye_config_entry(hass, client=client) config_entry = await setup_mock_motioneye_config_entry(hass, client=client)
device_registry = dr.async_get(hass)
device = device_registry.async_get_device( device = device_registry.async_get_device(
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER} identifiers={TEST_CAMERA_DEVICE_IDENTIFIER}
) )
@ -95,6 +96,7 @@ async def test_setup_camera_without_webhook(hass: HomeAssistant) -> None:
async def test_setup_camera_with_wrong_webhook( async def test_setup_camera_with_wrong_webhook(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
) -> None: ) -> None:
"""Test camera with wrong web hook.""" """Test camera with wrong web hook."""
wrong_url = "http://wrong-url" wrong_url = "http://wrong-url"
@ -123,7 +125,6 @@ async def test_setup_camera_with_wrong_webhook(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
device_registry = dr.async_get(hass)
device = device_registry.async_get_device( device = device_registry.async_get_device(
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER} identifiers={TEST_CAMERA_DEVICE_IDENTIFIER}
) )
@ -151,6 +152,7 @@ async def test_setup_camera_with_wrong_webhook(
async def test_setup_camera_with_old_webhook( async def test_setup_camera_with_old_webhook(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
) -> None: ) -> None:
"""Verify that webhooks are overwritten if they are from this integration. """Verify that webhooks are overwritten if they are from this integration.
@ -176,7 +178,6 @@ async def test_setup_camera_with_old_webhook(
) )
assert client.async_set_camera.called assert client.async_set_camera.called
device_registry = dr.async_get(hass)
device = device_registry.async_get_device( device = device_registry.async_get_device(
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER} identifiers={TEST_CAMERA_DEVICE_IDENTIFIER}
) )
@ -204,6 +205,7 @@ async def test_setup_camera_with_old_webhook(
async def test_setup_camera_with_correct_webhook( async def test_setup_camera_with_correct_webhook(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
) -> None: ) -> None:
"""Verify that webhooks are not overwritten if they are already correct.""" """Verify that webhooks are not overwritten if they are already correct."""
@ -212,7 +214,6 @@ async def test_setup_camera_with_correct_webhook(
hass, data={CONF_URL: TEST_URL, CONF_WEBHOOK_ID: "webhook_secret_id"} hass, data={CONF_URL: TEST_URL, CONF_WEBHOOK_ID: "webhook_secret_id"}
) )
device_registry = dr.async_get(hass)
device = device_registry.async_get_or_create( device = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id, config_entry_id=config_entry.entry_id,
identifiers={TEST_CAMERA_DEVICE_IDENTIFIER}, identifiers={TEST_CAMERA_DEVICE_IDENTIFIER},
@ -278,12 +279,13 @@ async def test_setup_camera_with_no_home_assistant_urls(
async def test_good_query( async def test_good_query(
hass: HomeAssistant, hass_client_no_auth: ClientSessionGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
hass_client_no_auth: ClientSessionGenerator,
) -> None: ) -> None:
"""Test good callbacks.""" """Test good callbacks."""
await async_setup_component(hass, "http", {"http": {}}) await async_setup_component(hass, "http", {"http": {}})
device_registry = dr.async_get(hass)
client = create_mock_motioneye_client() client = create_mock_motioneye_client()
config_entry = await setup_mock_motioneye_config_entry(hass, client=client) config_entry = await setup_mock_motioneye_config_entry(hass, client=client)
@ -377,12 +379,13 @@ async def test_bad_query_cannot_decode(
async def test_event_media_data( async def test_event_media_data(
hass: HomeAssistant, hass_client_no_auth: ClientSessionGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
hass_client_no_auth: ClientSessionGenerator,
) -> None: ) -> None:
"""Test an event with a file path generates media data.""" """Test an event with a file path generates media data."""
await async_setup_component(hass, "http", {"http": {}}) await async_setup_component(hass, "http", {"http": {}})
device_registry = dr.async_get(hass)
client = create_mock_motioneye_client() client = create_mock_motioneye_client()
config_entry = await setup_mock_motioneye_config_entry(hass, client=client) config_entry = await setup_mock_motioneye_config_entry(hass, client=client)

View File

@ -973,11 +973,12 @@ async def test_attach_remove_late2(
async def test_entity_device_info_with_connection( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test MQTT device registry integration.""" """Test MQTT device registry integration."""
await mqtt_mock_entry() await mqtt_mock_entry()
registry = dr.async_get(hass)
data = json.dumps( data = json.dumps(
{ {
@ -998,7 +999,7 @@ async def test_entity_device_info_with_connection(
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data) async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device( device = device_registry.async_get_device(
connections={(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")} connections={(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")}
) )
assert device is not None assert device is not None
@ -1011,11 +1012,12 @@ async def test_entity_device_info_with_connection(
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test MQTT device registry integration.""" """Test MQTT device registry integration."""
await mqtt_mock_entry() await mqtt_mock_entry()
registry = dr.async_get(hass)
data = json.dumps( data = json.dumps(
{ {
@ -1036,7 +1038,7 @@ async def test_entity_device_info_with_identifier(
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data) async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device(identifiers={("mqtt", "helloworld")}) device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None assert device is not None
assert device.identifiers == {("mqtt", "helloworld")} assert device.identifiers == {("mqtt", "helloworld")}
assert device.manufacturer == "Whatever" assert device.manufacturer == "Whatever"
@ -1047,11 +1049,12 @@ async def test_entity_device_info_with_identifier(
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await mqtt_mock_entry() await mqtt_mock_entry()
registry = dr.async_get(hass)
config = { config = {
"automation_type": "trigger", "automation_type": "trigger",
@ -1072,7 +1075,7 @@ async def test_entity_device_info_update(
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data) async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device(identifiers={("mqtt", "helloworld")}) device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None assert device is not None
assert device.name == "Beer" assert device.name == "Beer"
@ -1081,7 +1084,7 @@ async def test_entity_device_info_update(
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data) async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device(identifiers={("mqtt", "helloworld")}) device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None assert device is not None
assert device.name == "Milk" assert device.name == "Milk"
@ -1390,14 +1393,15 @@ async def test_cleanup_device_with_entity2(
async def test_trigger_debug_info( async def test_trigger_debug_info(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test debug_info. """Test debug_info.
This is a test helper for MQTT debug_info. This is a test helper for MQTT debug_info.
""" """
await mqtt_mock_entry() await mqtt_mock_entry()
registry = dr.async_get(hass)
config1 = { config1 = {
"platform": "mqtt", "platform": "mqtt",
@ -1429,7 +1433,7 @@ async def test_trigger_debug_info(
async_fire_mqtt_message(hass, "homeassistant/device_automation/bla2/config", data) async_fire_mqtt_message(hass, "homeassistant/device_automation/bla2/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device( device = device_registry.async_get_device(
connections={(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")} connections={(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")}
) )
assert device is not None assert device is not None

View File

@ -500,14 +500,15 @@ async def test_entity_id_update_discovery_update(
async def test_entity_device_info_with_hub( async def test_entity_device_info_with_hub(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test MQTT event device registry integration.""" """Test MQTT event device registry integration."""
await mqtt_mock_entry() await mqtt_mock_entry()
other_config_entry = MockConfigEntry() other_config_entry = MockConfigEntry()
other_config_entry.add_to_hass(hass) other_config_entry.add_to_hass(hass)
registry = dr.async_get(hass) hub = device_registry.async_get_or_create(
hub = registry.async_get_or_create(
config_entry_id=other_config_entry.entry_id, config_entry_id=other_config_entry.entry_id,
connections=set(), connections=set(),
identifiers={("mqtt", "hub-id")}, identifiers={("mqtt", "hub-id")},
@ -527,7 +528,7 @@ async def test_entity_device_info_with_hub(
async_fire_mqtt_message(hass, "homeassistant/event/bla/config", data) async_fire_mqtt_message(hass, "homeassistant/event/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device(identifiers={("mqtt", "helloworld")}) device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None assert device is not None
assert device.via_device_id == hub.id assert device.via_device_id == hub.id

View File

@ -3050,7 +3050,9 @@ async def test_mqtt_ws_get_device_debug_info_binary(
async def test_debug_info_multiple_devices( async def test_debug_info_multiple_devices(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test we get correct debug_info when multiple devices are present.""" """Test we get correct debug_info when multiple devices are present."""
await mqtt_mock_entry() await mqtt_mock_entry()
@ -3097,8 +3099,6 @@ async def test_debug_info_multiple_devices(
}, },
] ]
registry = dr.async_get(hass)
for dev in devices: for dev in devices:
data = json.dumps(dev["config"]) data = json.dumps(dev["config"])
domain = dev["domain"] domain = dev["domain"]
@ -3109,7 +3109,7 @@ async def test_debug_info_multiple_devices(
for dev in devices: for dev in devices:
domain = dev["domain"] domain = dev["domain"]
id = dev["config"]["device"]["identifiers"][0] id = dev["config"]["device"]["identifiers"][0]
device = registry.async_get_device(identifiers={("mqtt", id)}) device = device_registry.async_get_device(identifiers={("mqtt", id)})
assert device is not None assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id) debug_info_data = debug_info.info_for_device(hass, device.id)
@ -3132,7 +3132,9 @@ async def test_debug_info_multiple_devices(
async def test_debug_info_multiple_entities_triggers( async def test_debug_info_multiple_entities_triggers(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test we get correct debug_info for a device with multiple entities and triggers.""" """Test we get correct debug_info for a device with multiple entities and triggers."""
await mqtt_mock_entry() await mqtt_mock_entry()
@ -3179,8 +3181,6 @@ async def test_debug_info_multiple_entities_triggers(
}, },
] ]
registry = dr.async_get(hass)
for c in config: for c in config:
data = json.dumps(c["config"]) data = json.dumps(c["config"])
domain = c["domain"] domain = c["domain"]
@ -3190,7 +3190,7 @@ async def test_debug_info_multiple_entities_triggers(
await hass.async_block_till_done() await hass.async_block_till_done()
device_id = config[0]["config"]["device"]["identifiers"][0] device_id = config[0]["config"]["device"]["identifiers"][0]
device = registry.async_get_device(identifiers={("mqtt", device_id)}) device = device_registry.async_get_device(identifiers={("mqtt", device_id)})
assert device is not None assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id) debug_info_data = debug_info.info_for_device(hass, device.id)
assert len(debug_info_data["entities"]) == 2 assert len(debug_info_data["entities"]) == 2
@ -3253,7 +3253,9 @@ async def test_debug_info_non_mqtt(
async def test_debug_info_wildcard( async def test_debug_info_wildcard(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test debug info.""" """Test debug info."""
await mqtt_mock_entry() await mqtt_mock_entry()
@ -3264,13 +3266,11 @@ async def test_debug_info_wildcard(
"unique_id": "veryunique", "unique_id": "veryunique",
} }
registry = dr.async_get(hass)
data = json.dumps(config) data = json.dumps(config)
async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data) async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device(identifiers={("mqtt", "helloworld")}) device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id) debug_info_data = debug_info.info_for_device(hass, device.id)
@ -3301,7 +3301,9 @@ async def test_debug_info_wildcard(
async def test_debug_info_filter_same( async def test_debug_info_filter_same(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test debug info removes messages with same timestamp.""" """Test debug info removes messages with same timestamp."""
await mqtt_mock_entry() await mqtt_mock_entry()
@ -3312,13 +3314,11 @@ async def test_debug_info_filter_same(
"unique_id": "veryunique", "unique_id": "veryunique",
} }
registry = dr.async_get(hass)
data = json.dumps(config) data = json.dumps(config)
async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data) async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device(identifiers={("mqtt", "helloworld")}) device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id) debug_info_data = debug_info.info_for_device(hass, device.id)
@ -3361,7 +3361,9 @@ async def test_debug_info_filter_same(
async def test_debug_info_same_topic( async def test_debug_info_same_topic(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test debug info.""" """Test debug info."""
await mqtt_mock_entry() await mqtt_mock_entry()
@ -3373,13 +3375,11 @@ async def test_debug_info_same_topic(
"unique_id": "veryunique", "unique_id": "veryunique",
} }
registry = dr.async_get(hass)
data = json.dumps(config) data = json.dumps(config)
async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data) async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device(identifiers={("mqtt", "helloworld")}) device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id) debug_info_data = debug_info.info_for_device(hass, device.id)
@ -3415,7 +3415,9 @@ async def test_debug_info_same_topic(
async def test_debug_info_qos_retain( async def test_debug_info_qos_retain(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test debug info.""" """Test debug info."""
await mqtt_mock_entry() await mqtt_mock_entry()
@ -3426,13 +3428,11 @@ async def test_debug_info_qos_retain(
"unique_id": "veryunique", "unique_id": "veryunique",
} }
registry = dr.async_get(hass)
data = json.dumps(config) data = json.dumps(config)
async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data) async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device(identifiers={("mqtt", "helloworld")}) device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None assert device is not None
debug_info_data = debug_info.info_for_device(hass, device.id) debug_info_data = debug_info.info_for_device(hass, device.id)

View File

@ -312,6 +312,7 @@ async def test_availability_with_shared_state_topic(
@patch("homeassistant.components.mqtt.client.DISCOVERY_COOLDOWN", 0.0) @patch("homeassistant.components.mqtt.client.DISCOVERY_COOLDOWN", 0.0)
async def test_default_entity_and_device_name( async def test_default_entity_and_device_name(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_client_mock: MqttMockPahoClient, mqtt_client_mock: MqttMockPahoClient,
mqtt_config_entry_data, mqtt_config_entry_data,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
@ -336,9 +337,7 @@ async def test_default_entity_and_device_name(
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED) hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
await hass.async_block_till_done() await hass.async_block_till_done()
registry = dr.async_get(hass) device = device_registry.async_get_device({("mqtt", "helloworld")})
device = registry.async_get_device({("mqtt", "helloworld")})
assert device is not None assert device is not None
assert device.name == device_name assert device.name == device_name

View File

@ -1134,14 +1134,15 @@ async def test_entity_id_update_discovery_update(
async def test_entity_device_info_with_hub( async def test_entity_device_info_with_hub(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test MQTT sensor device registry integration.""" """Test MQTT sensor device registry integration."""
await mqtt_mock_entry() await mqtt_mock_entry()
other_config_entry = MockConfigEntry() other_config_entry = MockConfigEntry()
other_config_entry.add_to_hass(hass) other_config_entry.add_to_hass(hass)
registry = dr.async_get(hass) hub = device_registry.async_get_or_create(
hub = registry.async_get_or_create(
config_entry_id=other_config_entry.entry_id, config_entry_id=other_config_entry.entry_id,
connections=set(), connections=set(),
identifiers={("mqtt", "hub-id")}, identifiers={("mqtt", "hub-id")},
@ -1160,7 +1161,7 @@ async def test_entity_device_info_with_hub(
async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data) async_fire_mqtt_message(hass, "homeassistant/sensor/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device(identifiers={("mqtt", "helloworld")}) device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None assert device is not None
assert device.via_device_id == hub.id assert device.via_device_id == hub.id

View File

@ -444,11 +444,12 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
async def test_entity_device_info_with_connection( async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test MQTT device registry integration.""" """Test MQTT device registry integration."""
await mqtt_mock_entry() await mqtt_mock_entry()
registry = dr.async_get(hass)
data = json.dumps( data = json.dumps(
{ {
@ -466,7 +467,7 @@ async def test_entity_device_info_with_connection(
async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", data) async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device( device = device_registry.async_get_device(
connections={(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")} connections={(dr.CONNECTION_NETWORK_MAC, "02:5b:26:a8:dc:12")}
) )
assert device is not None assert device is not None
@ -479,11 +480,12 @@ async def test_entity_device_info_with_connection(
async def test_entity_device_info_with_identifier( async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test MQTT device registry integration.""" """Test MQTT device registry integration."""
await mqtt_mock_entry() await mqtt_mock_entry()
registry = dr.async_get(hass)
data = json.dumps( data = json.dumps(
{ {
@ -501,7 +503,7 @@ async def test_entity_device_info_with_identifier(
async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", data) async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device(identifiers={("mqtt", "helloworld")}) device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None assert device is not None
assert device.identifiers == {("mqtt", "helloworld")} assert device.identifiers == {("mqtt", "helloworld")}
assert device.manufacturer == "Whatever" assert device.manufacturer == "Whatever"
@ -512,11 +514,12 @@ async def test_entity_device_info_with_identifier(
async def test_entity_device_info_update( async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test device registry update.""" """Test device registry update."""
await mqtt_mock_entry() await mqtt_mock_entry()
registry = dr.async_get(hass)
config = { config = {
"topic": "test-topic", "topic": "test-topic",
@ -534,7 +537,7 @@ async def test_entity_device_info_update(
async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", data) async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device(identifiers={("mqtt", "helloworld")}) device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None assert device is not None
assert device.name == "Beer" assert device.name == "Beer"
@ -543,7 +546,7 @@ async def test_entity_device_info_update(
async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", data) async_fire_mqtt_message(hass, "homeassistant/tag/bla/config", data)
await hass.async_block_till_done() await hass.async_block_till_done()
device = registry.async_get_device(identifiers={("mqtt", "helloworld")}) device = device_registry.async_get_device(identifiers={("mqtt", "helloworld")})
assert device is not None assert device is not None
assert device.name == "Milk" assert device.name == "Milk"

View File

@ -118,7 +118,7 @@ async def test_room_update(hass: HomeAssistant, mqtt_mock: MqttMockHAClient) ->
async def test_unique_id_is_set( async def test_unique_id_is_set(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient hass: HomeAssistant, entity_registry: er.EntityRegistry, mqtt_mock: MqttMockHAClient
) -> None: ) -> None:
"""Test the updating between rooms.""" """Test the updating between rooms."""
unique_name = "my_unique_name_0123456789" unique_name = "my_unique_name_0123456789"
@ -141,6 +141,5 @@ async def test_unique_id_is_set(
state = hass.states.get(SENSOR_STATE) state = hass.states.get(SENSOR_STATE)
assert state.state is not None assert state.state is not None
entity_registry = er.async_get(hass)
entry = entity_registry.async_get(SENSOR_STATE) entry = entity_registry.async_get(SENSOR_STATE)
assert entry.unique_id == unique_name assert entry.unique_id == unique_name

View File

@ -15,6 +15,8 @@ from tests.typing import WebSocketGenerator
async def test_remove_config_entry_device( async def test_remove_config_entry_device(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
gps_sensor: Sensor, gps_sensor: Sensor,
integration: MockConfigEntry, integration: MockConfigEntry,
gateway: BaseSyncGateway, gateway: BaseSyncGateway,
@ -27,11 +29,9 @@ async def test_remove_config_entry_device(
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
await hass.async_block_till_done() await hass.async_block_till_done()
device_registry = dr.async_get(hass)
device_entry = device_registry.async_get_device( device_entry = device_registry.async_get_device(
identifiers={(DOMAIN, f"{config_entry.entry_id}-{node_id}")} identifiers={(DOMAIN, f"{config_entry.entry_id}-{node_id}")}
) )
entity_registry = er.async_get(hass)
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert gateway.sensors assert gateway.sensors

View File

@ -10,10 +10,8 @@ from homeassistant.util import dt as dt_util
from . import init_integration from . import init_integration
async def test_button(hass: HomeAssistant) -> None: async def test_button(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None:
"""Test states of the button.""" """Test states of the button."""
registry = er.async_get(hass)
await init_integration(hass) await init_integration(hass)
state = hass.states.get("button.nettigo_air_monitor_restart") state = hass.states.get("button.nettigo_air_monitor_restart")
@ -21,7 +19,7 @@ async def test_button(hass: HomeAssistant) -> None:
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
assert state.attributes.get(ATTR_DEVICE_CLASS) == ButtonDeviceClass.RESTART assert state.attributes.get(ATTR_DEVICE_CLASS) == ButtonDeviceClass.RESTART
entry = registry.async_get("button.nettigo_air_monitor_restart") entry = entity_registry.async_get("button.nettigo_air_monitor_restart")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-restart" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-restart"

View File

@ -93,11 +93,11 @@ async def test_unload_entry(hass: HomeAssistant) -> None:
assert not hass.data.get(DOMAIN) assert not hass.data.get(DOMAIN)
async def test_remove_air_quality_entities(hass: HomeAssistant) -> None: async def test_remove_air_quality_entities(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test remove air_quality entities from registry.""" """Test remove air_quality entities from registry."""
registry = er.async_get(hass) entity_registry.async_get_or_create(
registry.async_get_or_create(
AIR_QUALITY_PLATFORM, AIR_QUALITY_PLATFORM,
DOMAIN, DOMAIN,
"aa:bb:cc:dd:ee:ff-sds011", "aa:bb:cc:dd:ee:ff-sds011",
@ -105,7 +105,7 @@ async def test_remove_air_quality_entities(hass: HomeAssistant) -> None:
disabled_by=None, disabled_by=None,
) )
registry.async_get_or_create( entity_registry.async_get_or_create(
AIR_QUALITY_PLATFORM, AIR_QUALITY_PLATFORM,
DOMAIN, DOMAIN,
"aa:bb:cc:dd:ee:ff-sps30", "aa:bb:cc:dd:ee:ff-sps30",
@ -115,8 +115,8 @@ async def test_remove_air_quality_entities(hass: HomeAssistant) -> None:
await init_integration(hass) await init_integration(hass)
entry = registry.async_get("air_quality.nettigo_air_monitor_sds011") entry = entity_registry.async_get("air_quality.nettigo_air_monitor_sds011")
assert entry is None assert entry is None
entry = registry.async_get("air_quality.nettigo_air_monitor_sps30") entry = entity_registry.async_get("air_quality.nettigo_air_monitor_sps30")
assert entry is None assert entry is None

View File

@ -35,11 +35,9 @@ from . import INCOMPLETE_NAM_DATA, init_integration, nam_data
from tests.common import async_fire_time_changed from tests.common import async_fire_time_changed
async def test_sensor(hass: HomeAssistant) -> None: async def test_sensor(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None:
"""Test states of the air_quality.""" """Test states of the air_quality."""
registry = er.async_get(hass) entity_registry.async_get_or_create(
registry.async_get_or_create(
SENSOR_DOMAIN, SENSOR_DOMAIN,
DOMAIN, DOMAIN,
"aa:bb:cc:dd:ee:ff-signal", "aa:bb:cc:dd:ee:ff-signal",
@ -47,7 +45,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
disabled_by=None, disabled_by=None,
) )
registry.async_get_or_create( entity_registry.async_get_or_create(
SENSOR_DOMAIN, SENSOR_DOMAIN,
DOMAIN, DOMAIN,
"aa:bb:cc:dd:ee:ff-uptime", "aa:bb:cc:dd:ee:ff-uptime",
@ -67,7 +65,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
entry = registry.async_get("sensor.nettigo_air_monitor_bme280_humidity") entry = entity_registry.async_get("sensor.nettigo_air_monitor_bme280_humidity")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-bme280_humidity" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-bme280_humidity"
@ -78,7 +76,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS
entry = registry.async_get("sensor.nettigo_air_monitor_bme280_temperature") entry = entity_registry.async_get("sensor.nettigo_air_monitor_bme280_temperature")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-bme280_temperature" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-bme280_temperature"
@ -89,7 +87,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPressure.HPA assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPressure.HPA
entry = registry.async_get("sensor.nettigo_air_monitor_bme280_pressure") entry = entity_registry.async_get("sensor.nettigo_air_monitor_bme280_pressure")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-bme280_pressure" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-bme280_pressure"
@ -100,7 +98,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS
entry = registry.async_get("sensor.nettigo_air_monitor_bmp180_temperature") entry = entity_registry.async_get("sensor.nettigo_air_monitor_bmp180_temperature")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-bmp180_temperature" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-bmp180_temperature"
@ -111,7 +109,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPressure.HPA assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPressure.HPA
entry = registry.async_get("sensor.nettigo_air_monitor_bmp180_pressure") entry = entity_registry.async_get("sensor.nettigo_air_monitor_bmp180_pressure")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-bmp180_pressure" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-bmp180_pressure"
@ -122,7 +120,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS
entry = registry.async_get("sensor.nettigo_air_monitor_bmp280_temperature") entry = entity_registry.async_get("sensor.nettigo_air_monitor_bmp280_temperature")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-bmp280_temperature" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-bmp280_temperature"
@ -133,7 +131,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPressure.HPA assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPressure.HPA
entry = registry.async_get("sensor.nettigo_air_monitor_bmp280_pressure") entry = entity_registry.async_get("sensor.nettigo_air_monitor_bmp280_pressure")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-bmp280_pressure" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-bmp280_pressure"
@ -144,7 +142,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
entry = registry.async_get("sensor.nettigo_air_monitor_sht3x_humidity") entry = entity_registry.async_get("sensor.nettigo_air_monitor_sht3x_humidity")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sht3x_humidity" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sht3x_humidity"
@ -155,7 +153,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS
entry = registry.async_get("sensor.nettigo_air_monitor_sht3x_temperature") entry = entity_registry.async_get("sensor.nettigo_air_monitor_sht3x_temperature")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sht3x_temperature" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sht3x_temperature"
@ -166,7 +164,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
entry = registry.async_get("sensor.nettigo_air_monitor_dht22_humidity") entry = entity_registry.async_get("sensor.nettigo_air_monitor_dht22_humidity")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-dht22_humidity" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-dht22_humidity"
@ -177,7 +175,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS
entry = registry.async_get("sensor.nettigo_air_monitor_dht22_temperature") entry = entity_registry.async_get("sensor.nettigo_air_monitor_dht22_temperature")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-dht22_temperature" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-dht22_temperature"
@ -188,7 +186,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
entry = registry.async_get("sensor.nettigo_air_monitor_heca_humidity") entry = entity_registry.async_get("sensor.nettigo_air_monitor_heca_humidity")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-heca_humidity" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-heca_humidity"
@ -199,7 +197,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS
entry = registry.async_get("sensor.nettigo_air_monitor_heca_temperature") entry = entity_registry.async_get("sensor.nettigo_air_monitor_heca_temperature")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-heca_temperature" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-heca_temperature"
@ -213,7 +211,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
== SIGNAL_STRENGTH_DECIBELS_MILLIWATT == SIGNAL_STRENGTH_DECIBELS_MILLIWATT
) )
entry = registry.async_get("sensor.nettigo_air_monitor_signal_strength") entry = entity_registry.async_get("sensor.nettigo_air_monitor_signal_strength")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-signal" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-signal"
@ -226,7 +224,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TIMESTAMP assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TIMESTAMP
assert state.attributes.get(ATTR_STATE_CLASS) is None assert state.attributes.get(ATTR_STATE_CLASS) is None
entry = registry.async_get("sensor.nettigo_air_monitor_uptime") entry = entity_registry.async_get("sensor.nettigo_air_monitor_uptime")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-uptime" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-uptime"
@ -245,7 +243,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
] ]
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter" assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get( entry = entity_registry.async_get(
"sensor.nettigo_air_monitor_pmsx003_common_air_quality_index_level" "sensor.nettigo_air_monitor_pmsx003_common_air_quality_index_level"
) )
assert entry assert entry
@ -259,7 +257,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.state == "19" assert state.state == "19"
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter" assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get( entry = entity_registry.async_get(
"sensor.nettigo_air_monitor_pmsx003_common_air_quality_index" "sensor.nettigo_air_monitor_pmsx003_common_air_quality_index"
) )
assert entry assert entry
@ -275,7 +273,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
) )
entry = registry.async_get("sensor.nettigo_air_monitor_pmsx003_pm10") entry = entity_registry.async_get("sensor.nettigo_air_monitor_pmsx003_pm10")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-pms_p1" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-pms_p1"
@ -289,7 +287,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
) )
entry = registry.async_get("sensor.nettigo_air_monitor_pmsx003_pm2_5") entry = entity_registry.async_get("sensor.nettigo_air_monitor_pmsx003_pm2_5")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-pms_p2" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-pms_p2"
@ -303,7 +301,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
) )
entry = registry.async_get("sensor.nettigo_air_monitor_pmsx003_pm1") entry = entity_registry.async_get("sensor.nettigo_air_monitor_pmsx003_pm1")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-pms_p0" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-pms_p0"
@ -317,7 +315,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
) )
entry = registry.async_get("sensor.nettigo_air_monitor_sds011_pm10") entry = entity_registry.async_get("sensor.nettigo_air_monitor_sds011_pm10")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sds011_p1" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sds011_p1"
@ -328,7 +326,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.state == "19" assert state.state == "19"
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter" assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get( entry = entity_registry.async_get(
"sensor.nettigo_air_monitor_sds011_common_air_quality_index" "sensor.nettigo_air_monitor_sds011_common_air_quality_index"
) )
assert entry assert entry
@ -349,7 +347,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
] ]
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter" assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get( entry = entity_registry.async_get(
"sensor.nettigo_air_monitor_sds011_common_air_quality_index_level" "sensor.nettigo_air_monitor_sds011_common_air_quality_index_level"
) )
assert entry assert entry
@ -366,7 +364,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
) )
entry = registry.async_get("sensor.nettigo_air_monitor_sds011_pm2_5") entry = entity_registry.async_get("sensor.nettigo_air_monitor_sds011_pm2_5")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sds011_p2" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sds011_p2"
@ -375,7 +373,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.state == "54" assert state.state == "54"
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter" assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get( entry = entity_registry.async_get(
"sensor.nettigo_air_monitor_sps30_common_air_quality_index" "sensor.nettigo_air_monitor_sps30_common_air_quality_index"
) )
assert entry assert entry
@ -396,7 +394,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
] ]
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter" assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get( entry = entity_registry.async_get(
"sensor.nettigo_air_monitor_sps30_common_air_quality_index_level" "sensor.nettigo_air_monitor_sps30_common_air_quality_index_level"
) )
assert entry assert entry
@ -413,7 +411,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
) )
entry = registry.async_get("sensor.nettigo_air_monitor_sps30_pm1") entry = entity_registry.async_get("sensor.nettigo_air_monitor_sps30_pm1")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sps30_p0" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sps30_p0"
@ -427,7 +425,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
) )
entry = registry.async_get("sensor.nettigo_air_monitor_sps30_pm10") entry = entity_registry.async_get("sensor.nettigo_air_monitor_sps30_pm10")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sps30_p1" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sps30_p1"
@ -441,7 +439,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
) )
entry = registry.async_get("sensor.nettigo_air_monitor_sps30_pm2_5") entry = entity_registry.async_get("sensor.nettigo_air_monitor_sps30_pm2_5")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sps30_p2" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sps30_p2"
@ -455,7 +453,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
) )
assert state.attributes.get(ATTR_ICON) == "mdi:molecule" assert state.attributes.get(ATTR_ICON) == "mdi:molecule"
entry = registry.async_get("sensor.nettigo_air_monitor_sps30_pm4") entry = entity_registry.async_get("sensor.nettigo_air_monitor_sps30_pm4")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sps30_p4" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sps30_p4"
@ -468,24 +466,27 @@ async def test_sensor(hass: HomeAssistant) -> None:
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== CONCENTRATION_PARTS_PER_MILLION == CONCENTRATION_PARTS_PER_MILLION
) )
entry = registry.async_get("sensor.nettigo_air_monitor_mh_z14a_carbon_dioxide") entry = entity_registry.async_get(
"sensor.nettigo_air_monitor_mh_z14a_carbon_dioxide"
)
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-mhz14a_carbon_dioxide" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-mhz14a_carbon_dioxide"
async def test_sensor_disabled(hass: HomeAssistant) -> None: async def test_sensor_disabled(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test sensor disabled by default.""" """Test sensor disabled by default."""
await init_integration(hass) await init_integration(hass)
registry = er.async_get(hass)
entry = registry.async_get("sensor.nettigo_air_monitor_signal_strength") entry = entity_registry.async_get("sensor.nettigo_air_monitor_signal_strength")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-signal" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-signal"
assert entry.disabled assert entry.disabled
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
# Test enabling entity # Test enabling entity
updated_entry = registry.async_update_entity( updated_entry = entity_registry.async_update_entity(
entry.entity_id, **{"disabled_by": None} entry.entity_id, **{"disabled_by": None}
) )
@ -574,11 +575,11 @@ async def test_manual_update_entity(hass: HomeAssistant) -> None:
assert mock_get_data.call_count == 1 assert mock_get_data.call_count == 1
async def test_unique_id_migration(hass: HomeAssistant) -> None: async def test_unique_id_migration(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test states of the unique_id migration.""" """Test states of the unique_id migration."""
registry = er.async_get(hass) entity_registry.async_get_or_create(
registry.async_get_or_create(
SENSOR_DOMAIN, SENSOR_DOMAIN,
DOMAIN, DOMAIN,
"aa:bb:cc:dd:ee:ff-temperature", "aa:bb:cc:dd:ee:ff-temperature",
@ -586,7 +587,7 @@ async def test_unique_id_migration(hass: HomeAssistant) -> None:
disabled_by=None, disabled_by=None,
) )
registry.async_get_or_create( entity_registry.async_get_or_create(
SENSOR_DOMAIN, SENSOR_DOMAIN,
DOMAIN, DOMAIN,
"aa:bb:cc:dd:ee:ff-humidity", "aa:bb:cc:dd:ee:ff-humidity",
@ -596,10 +597,10 @@ async def test_unique_id_migration(hass: HomeAssistant) -> None:
await init_integration(hass) await init_integration(hass)
entry = registry.async_get("sensor.nettigo_air_monitor_dht22_temperature") entry = entity_registry.async_get("sensor.nettigo_air_monitor_dht22_temperature")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-dht22_temperature" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-dht22_temperature"
entry = registry.async_get("sensor.nettigo_air_monitor_dht22_humidity") entry = entity_registry.async_get("sensor.nettigo_air_monitor_dht22_humidity")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-dht22_humidity" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-dht22_humidity"