Use entity & device registry fixtures in unifi tests (#110889)

This commit is contained in:
Jan-Philipp Benecke 2024-02-18 23:47:10 +01:00 committed by GitHub
parent 72ccc40c43
commit 22e62f42e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 85 additions and 61 deletions

View file

@ -816,7 +816,9 @@ async def test_not_admin(
async def test_switches(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test the update_items function with some clients."""
config_entry = await setup_unifi_integration(
@ -852,9 +854,10 @@ async def test_switches(
assert dpi_switch.state == "on"
assert dpi_switch.attributes["icon"] == "mdi:network"
ent_reg = er.async_get(hass)
for entry_id in ("switch.block_client_1", "switch.block_media_streaming"):
assert ent_reg.async_get(entry_id).entity_category is EntityCategory.CONFIG
assert (
entity_registry.async_get(entry_id).entity_category is EntityCategory.CONFIG
)
# Block and unblock client
aioclient_mock.clear_requests()
@ -1326,6 +1329,7 @@ async def test_option_remove_switches(
async def test_poe_port_switches(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
mock_unifi_websocket,
websocket_mock,
@ -1338,16 +1342,15 @@ async def test_poe_port_switches(
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 0
ent_reg = er.async_get(hass)
ent_reg_entry = ent_reg.async_get("switch.mock_name_port_1_poe")
ent_reg_entry = entity_registry.async_get("switch.mock_name_port_1_poe")
assert ent_reg_entry.disabled_by == RegistryEntryDisabler.INTEGRATION
assert ent_reg_entry.entity_category is EntityCategory.CONFIG
# Enable entity
ent_reg.async_update_entity(
entity_registry.async_update_entity(
entity_id="switch.mock_name_port_1_poe", disabled_by=None
)
ent_reg.async_update_entity(
entity_registry.async_update_entity(
entity_id="switch.mock_name_port_2_poe", disabled_by=None
)
await hass.async_block_till_done()
@ -1438,6 +1441,7 @@ async def test_poe_port_switches(
async def test_wlan_switches(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
mock_unifi_websocket,
websocket_mock,
@ -1450,8 +1454,7 @@ async def test_wlan_switches(
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 1
ent_reg = er.async_get(hass)
ent_reg_entry = ent_reg.async_get("switch.ssid_1")
ent_reg_entry = entity_registry.async_get("switch.ssid_1")
assert ent_reg_entry.unique_id == "wlan-012345678910111213141516"
assert ent_reg_entry.entity_category is EntityCategory.CONFIG
@ -1507,6 +1510,7 @@ async def test_wlan_switches(
async def test_port_forwarding_switches(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
mock_unifi_websocket,
websocket_mock,
@ -1531,8 +1535,7 @@ async def test_port_forwarding_switches(
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 1
ent_reg = er.async_get(hass)
ent_reg_entry = ent_reg.async_get("switch.unifi_network_plex")
ent_reg_entry = entity_registry.async_get("switch.unifi_network_plex")
assert ent_reg_entry.unique_id == "port_forward-5a32aa4ee4b0412345678911"
assert ent_reg_entry.entity_category is EntityCategory.CONFIG
@ -1594,7 +1597,9 @@ async def test_port_forwarding_switches(
async def test_updating_unique_id(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Verify outlet control and poe control unique ID update works."""
poe_device = {
@ -1637,15 +1642,14 @@ async def test_updating_unique_id(
entry_id="1",
)
registry = er.async_get(hass)
registry.async_get_or_create(
entity_registry.async_get_or_create(
SWITCH_DOMAIN,
UNIFI_DOMAIN,
f'{poe_device["mac"]}-poe-1',
suggested_object_id="switch_port_1_poe",
config_entry=config_entry,
)
registry.async_get_or_create(
entity_registry.async_get_or_create(
SWITCH_DOMAIN,
UNIFI_DOMAIN,
f'{OUTLET_UP1["mac"]}-outlet-1',