Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve deCONZ init tests #47825

Merged
merged 1 commit into from
Mar 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 22 additions & 30 deletions tests/components/deconz/test_init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test deCONZ component setup process."""

import asyncio
from copy import deepcopy
from unittest.mock import patch

from homeassistant.components.deconz import (
Expand All @@ -16,7 +15,7 @@
)
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT
from homeassistant.helpers import entity_registry
from homeassistant.helpers import entity_registry as er

from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration

Expand Down Expand Up @@ -71,15 +70,14 @@ async def test_setup_entry_multiple_gateways(hass, aioclient_mock):
config_entry = await setup_deconz_integration(hass, aioclient_mock)
aioclient_mock.clear_requests()

data = deepcopy(DECONZ_WEB_REQUEST)
data["config"]["bridgeid"] = "01234E56789B"
config_entry2 = await setup_deconz_integration(
hass,
aioclient_mock,
get_state_response=data,
entry_id="2",
unique_id="01234E56789B",
)
data = {"config": {"bridgeid": "01234E56789B"}}
with patch.dict(DECONZ_WEB_REQUEST, data):
config_entry2 = await setup_deconz_integration(
hass,
aioclient_mock,
entry_id="2",
unique_id="01234E56789B",
)

assert len(hass.data[DECONZ_DOMAIN]) == 2
assert hass.data[DECONZ_DOMAIN][config_entry.unique_id].master
Expand All @@ -100,15 +98,14 @@ async def test_unload_entry_multiple_gateways(hass, aioclient_mock):
config_entry = await setup_deconz_integration(hass, aioclient_mock)
aioclient_mock.clear_requests()

data = deepcopy(DECONZ_WEB_REQUEST)
data["config"]["bridgeid"] = "01234E56789B"
config_entry2 = await setup_deconz_integration(
hass,
aioclient_mock,
get_state_response=data,
entry_id="2",
unique_id="01234E56789B",
)
data = {"config": {"bridgeid": "01234E56789B"}}
with patch.dict(DECONZ_WEB_REQUEST, data):
config_entry2 = await setup_deconz_integration(
hass,
aioclient_mock,
entry_id="2",
unique_id="01234E56789B",
)

assert len(hass.data[DECONZ_DOMAIN]) == 2

Expand All @@ -133,7 +130,7 @@ async def test_update_group_unique_id(hass):
},
)

registry = await entity_registry.async_get_registry(hass)
registry = er.async_get(hass)
# Create entity entry to migrate to new unique ID
registry.async_get_or_create(
LIGHT_DOMAIN,
Expand All @@ -154,12 +151,8 @@ async def test_update_group_unique_id(hass):
await async_update_group_unique_id(hass, entry)

assert entry.data == {CONF_API_KEY: "1", CONF_HOST: "2", CONF_PORT: "3"}

old_entity = registry.async_get(f"{LIGHT_DOMAIN}.old")
assert old_entity.unique_id == f"{new_unique_id}-OLD"

new_entity = registry.async_get(f"{LIGHT_DOMAIN}.new")
assert new_entity.unique_id == f"{new_unique_id}-NEW"
assert registry.async_get(f"{LIGHT_DOMAIN}.old").unique_id == f"{new_unique_id}-OLD"
assert registry.async_get(f"{LIGHT_DOMAIN}.new").unique_id == f"{new_unique_id}-NEW"


async def test_update_group_unique_id_no_legacy_group_id(hass):
Expand All @@ -172,7 +165,7 @@ async def test_update_group_unique_id_no_legacy_group_id(hass):
data={},
)

registry = await entity_registry.async_get_registry(hass)
registry = er.async_get(hass)
# Create entity entry to migrate to new unique ID
registry.async_get_or_create(
LIGHT_DOMAIN,
Expand All @@ -184,5 +177,4 @@ async def test_update_group_unique_id_no_legacy_group_id(hass):

await async_update_group_unique_id(hass, entry)

old_entity = registry.async_get(f"{LIGHT_DOMAIN}.old")
assert old_entity.unique_id == f"{old_unique_id}-OLD"
assert registry.async_get(f"{LIGHT_DOMAIN}.old").unique_id == f"{old_unique_id}-OLD"