UniFi - Store controller in config_entry.entry_id (#34553)
* Store controller in config_entry.entry_id * Clean up imports
This commit is contained in:
1 parent
a0fbf9ba47
commit
c3689d7416
13 files changed
+190
-182
No files matched your search
@@ -2,6 +2,7 @@
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from homeassistant.components import unifi
|
||||
from homeassistant.components.unifi.const import DOMAIN as UNIFI_DOMAIN
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .test_controller import setup_unifi_integration
|
||||
@@ -11,29 +12,29 @@ from tests.common import MockConfigEntry, mock_coro
|
||||
|
||||
async def test_setup_with_no_config(hass):
|
||||
"""Test that we do not discover anything or try to set up a bridge."""
|
||||
assert await async_setup_component(hass, unifi.DOMAIN, {}) is True
|
||||
assert unifi.DOMAIN not in hass.data
|
||||
assert await async_setup_component(hass, UNIFI_DOMAIN, {}) is True
|
||||
assert UNIFI_DOMAIN not in hass.data
|
||||
|
||||
|
||||
async def test_successful_config_entry(hass):
|
||||
"""Test that configured options for a host are loaded via config entry."""
|
||||
await setup_unifi_integration(hass)
|
||||
assert hass.data[unifi.DOMAIN]
|
||||
assert hass.data[UNIFI_DOMAIN]
|
||||
|
||||
|
||||
async def test_controller_fail_setup(hass):
|
||||
"""Test that a failed setup still stores controller."""
|
||||
with patch.object(unifi, "UniFiController") as mock_cntrlr:
|
||||
mock_cntrlr.return_value.async_setup.return_value = mock_coro(False)
|
||||
with patch("homeassistant.components.unifi.UniFiController") as mock_controller:
|
||||
mock_controller.return_value.async_setup.return_value = mock_coro(False)
|
||||
await setup_unifi_integration(hass)
|
||||
|
||||
assert hass.data[unifi.DOMAIN] == {}
|
||||
assert hass.data[UNIFI_DOMAIN] == {}
|
||||
|
||||
|
||||
async def test_controller_no_mac(hass):
|
||||
"""Test that configured options for a host are loaded via config entry."""
|
||||
entry = MockConfigEntry(
|
||||
domain=unifi.DOMAIN,
|
||||
domain=UNIFI_DOMAIN,
|
||||
data={
|
||||
"controller": {
|
||||
"host": "0.0.0.0",
|
||||
@@ -48,7 +49,9 @@ async def test_controller_no_mac(hass):
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
mock_registry = Mock()
|
||||
with patch.object(unifi, "UniFiController") as mock_controller, patch(
|
||||
with patch(
|
||||
"homeassistant.components.unifi.UniFiController"
|
||||
) as mock_controller, patch(
|
||||
"homeassistant.helpers.device_registry.async_get_registry",
|
||||
return_value=mock_coro(mock_registry),
|
||||
):
|
||||
@@ -64,7 +67,7 @@ async def test_controller_no_mac(hass):
|
||||
async def test_unload_entry(hass):
|
||||
"""Test being able to unload an entry."""
|
||||
controller = await setup_unifi_integration(hass)
|
||||
assert hass.data[unifi.DOMAIN]
|
||||
assert hass.data[UNIFI_DOMAIN]
|
||||
|
||||
assert await unifi.async_unload_entry(hass, controller.config_entry)
|
||||
assert not hass.data[unifi.DOMAIN]
|
||||
assert not hass.data[UNIFI_DOMAIN]
|
||||
Reference in new issue
Block a user