Simplify UniFi entry configuration data (#45759)
* Simplify configuration structure by removing the controller key * Fix flake8 * Fix review comments * Don't use migrate_entry mechanism to flatten configuration Keep legacy configuration when creating new entries as well
This commit is contained in:
parent
cefde8721d
commit
618fcda821
6 changed files with 87 additions and 46 deletions
|
@ -2,10 +2,11 @@
|
|||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
from homeassistant.components import unifi
|
||||
from homeassistant.components.unifi.const import DOMAIN as UNIFI_DOMAIN
|
||||
from homeassistant.components.unifi import async_flatten_entry_data
|
||||
from homeassistant.components.unifi.const import CONF_CONTROLLER, DOMAIN as UNIFI_DOMAIN
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .test_controller import setup_unifi_integration
|
||||
from .test_controller import CONTROLLER_DATA, ENTRY_CONFIG, setup_unifi_integration
|
||||
|
||||
from tests.common import MockConfigEntry, mock_coro
|
||||
|
||||
|
@ -35,17 +36,9 @@ async def test_controller_no_mac(hass):
|
|||
"""Test that configured options for a host are loaded via config entry."""
|
||||
entry = MockConfigEntry(
|
||||
domain=UNIFI_DOMAIN,
|
||||
data={
|
||||
"controller": {
|
||||
"host": "0.0.0.0",
|
||||
"username": "user",
|
||||
"password": "pass",
|
||||
"port": 80,
|
||||
"site": "default",
|
||||
"verify_ssl": True,
|
||||
},
|
||||
},
|
||||
data=ENTRY_CONFIG,
|
||||
unique_id="1",
|
||||
version=1,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
mock_registry = Mock()
|
||||
|
@ -64,6 +57,17 @@ async def test_controller_no_mac(hass):
|
|||
assert len(mock_registry.mock_calls) == 0
|
||||
|
||||
|
||||
async def test_flatten_entry_data(hass):
|
||||
"""Verify entry data can be flattened."""
|
||||
entry = MockConfigEntry(
|
||||
domain=UNIFI_DOMAIN,
|
||||
data={CONF_CONTROLLER: CONTROLLER_DATA},
|
||||
)
|
||||
await async_flatten_entry_data(hass, entry)
|
||||
|
||||
assert entry.data == ENTRY_CONFIG
|
||||
|
||||
|
||||
async def test_unload_entry(hass, aioclient_mock):
|
||||
"""Test being able to unload an entry."""
|
||||
config_entry = await setup_unifi_integration(hass, aioclient_mock)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue