UniFi simplify update (#24304)
This commit is contained in:
parent
aa8ddeca34
commit
e9b0f54a43
7 changed files with 90 additions and 134 deletions
|
@ -4,8 +4,7 @@ from unittest.mock import Mock, patch
|
|||
import pytest
|
||||
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.components.unifi.const import (
|
||||
CONF_POE_CONTROL, CONF_CONTROLLER, CONF_SITE_ID)
|
||||
from homeassistant.components.unifi.const import CONF_CONTROLLER, CONF_SITE_ID
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME, CONF_VERIFY_SSL)
|
||||
from homeassistant.components.unifi import controller, errors
|
||||
|
@ -22,8 +21,7 @@ CONTROLLER_DATA = {
|
|||
}
|
||||
|
||||
ENTRY_CONFIG = {
|
||||
CONF_CONTROLLER: CONTROLLER_DATA,
|
||||
CONF_POE_CONTROL: True
|
||||
CONF_CONTROLLER: CONTROLLER_DATA
|
||||
}
|
||||
|
||||
|
||||
|
@ -171,30 +169,6 @@ async def test_reset_unloads_entry_if_setup():
|
|||
assert len(hass.config_entries.async_forward_entry_unload.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_reset_unloads_entry_without_poe_control():
|
||||
"""Calling reset while the entry has been setup."""
|
||||
hass = Mock()
|
||||
entry = Mock()
|
||||
entry.data = dict(ENTRY_CONFIG)
|
||||
entry.data[CONF_POE_CONTROL] = False
|
||||
api = Mock()
|
||||
api.initialize.return_value = mock_coro(True)
|
||||
|
||||
unifi_controller = controller.UniFiController(hass, entry)
|
||||
|
||||
with patch.object(controller, 'get_controller',
|
||||
return_value=mock_coro(api)):
|
||||
assert await unifi_controller.async_setup() is True
|
||||
|
||||
assert not hass.config_entries.async_forward_entry_setup.mock_calls
|
||||
|
||||
hass.config_entries.async_forward_entry_unload.return_value = \
|
||||
mock_coro(True)
|
||||
assert await unifi_controller.async_reset()
|
||||
|
||||
assert not hass.config_entries.async_forward_entry_unload.mock_calls
|
||||
|
||||
|
||||
async def test_get_controller(hass):
|
||||
"""Successful call."""
|
||||
with patch('aiounifi.Controller.login', return_value=mock_coro()):
|
||||
|
|
|
@ -4,8 +4,7 @@ from unittest.mock import Mock, patch
|
|||
from homeassistant.components import unifi
|
||||
from homeassistant.components.unifi import config_flow
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components.unifi.const import (
|
||||
CONF_POE_CONTROL, CONF_CONTROLLER, CONF_SITE_ID)
|
||||
from homeassistant.components.unifi.const import CONF_CONTROLLER, CONF_SITE_ID
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME, CONF_VERIFY_SSL)
|
||||
|
||||
|
@ -186,8 +185,7 @@ async def test_flow_works(hass, aioclient_mock):
|
|||
CONF_PORT: 1234,
|
||||
CONF_SITE_ID: 'default',
|
||||
CONF_VERIFY_SSL: True
|
||||
},
|
||||
CONF_POE_CONTROL: True
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,22 +4,21 @@ from unittest.mock import Mock
|
|||
|
||||
import pytest
|
||||
|
||||
from tests.common import mock_coro
|
||||
|
||||
import aiounifi
|
||||
from aiounifi.clients import Clients
|
||||
from aiounifi.devices import Devices
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import unifi
|
||||
from homeassistant.components.unifi.const import (
|
||||
CONF_POE_CONTROL, CONF_CONTROLLER, CONF_SITE_ID)
|
||||
from homeassistant.components.unifi.const import CONF_CONTROLLER, CONF_SITE_ID
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME, CONF_VERIFY_SSL)
|
||||
|
||||
import homeassistant.components.switch as switch
|
||||
|
||||
from tests.common import mock_coro
|
||||
|
||||
CLIENT_1 = {
|
||||
'hostname': 'client_1',
|
||||
'ip': '10.0.0.1',
|
||||
|
@ -180,8 +179,7 @@ CONTROLLER_DATA = {
|
|||
}
|
||||
|
||||
ENTRY_CONFIG = {
|
||||
CONF_CONTROLLER: CONTROLLER_DATA,
|
||||
CONF_POE_CONTROL: True
|
||||
CONF_CONTROLLER: CONTROLLER_DATA
|
||||
}
|
||||
|
||||
CONTROLLER_ID = unifi.CONTROLLER_ID.format(host='mock-host', site='mock-site')
|
||||
|
@ -190,12 +188,9 @@ CONTROLLER_ID = unifi.CONTROLLER_ID.format(host='mock-host', site='mock-site')
|
|||
@pytest.fixture
|
||||
def mock_controller(hass):
|
||||
"""Mock a UniFi Controller."""
|
||||
controller = Mock(
|
||||
available=True,
|
||||
api=Mock(),
|
||||
spec=unifi.UniFiController
|
||||
)
|
||||
controller.mac = '10:00:00:00:00:01'
|
||||
controller = unifi.UniFiController(hass, None)
|
||||
|
||||
controller.api = Mock()
|
||||
controller.mock_requests = []
|
||||
|
||||
controller.mock_client_responses = deque()
|
||||
|
@ -224,6 +219,9 @@ async def setup_controller(hass, mock_controller):
|
|||
config_entry = config_entries.ConfigEntry(
|
||||
1, unifi.DOMAIN, 'Mock Title', ENTRY_CONFIG, 'test',
|
||||
config_entries.CONN_CLASS_LOCAL_POLL)
|
||||
mock_controller.config_entry = config_entry
|
||||
|
||||
await mock_controller.async_update()
|
||||
await hass.config_entries.async_forward_entry_setup(config_entry, 'switch')
|
||||
# To flush out the service call to update the group
|
||||
await hass.async_block_till_done()
|
||||
|
@ -242,6 +240,7 @@ async def test_platform_manually_configured(hass):
|
|||
async def test_no_clients(hass, mock_controller):
|
||||
"""Test the update_clients function when no clients are found."""
|
||||
mock_controller.mock_client_responses.append({})
|
||||
mock_controller.mock_device_responses.append({})
|
||||
await setup_controller(hass, mock_controller)
|
||||
assert len(mock_controller.mock_requests) == 2
|
||||
assert not hass.states.async_all()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue