Merge UniFi device tracker to config entry (#24367)
* Move device tracker to use config entry * Remove monitored conditions attributes based on ADR0003 * Add support for import of device tracker config to be backwards compatible * Remove unnecessary configuration options from device tracker * Add component configuration support
This commit is contained in:
1 parent
3480e6229a
commit
01b890f426
11 files changed
+493
-449
No files matched your search
@@ -12,7 +12,8 @@ from aiounifi.devices import Devices
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import unifi
|
||||
from homeassistant.components.unifi.const import CONF_CONTROLLER, CONF_SITE_ID
|
||||
from homeassistant.components.unifi.const import (
|
||||
CONF_CONTROLLER, CONF_SITE_ID, UNIFI_CONFIG)
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME, CONF_VERIFY_SSL)
|
||||
@@ -188,8 +189,11 @@ CONTROLLER_ID = unifi.CONTROLLER_ID.format(host='mock-host', site='mock-site')
|
||||
@pytest.fixture
|
||||
def mock_controller(hass):
|
||||
"""Mock a UniFi Controller."""
|
||||
hass.data[UNIFI_CONFIG] = {}
|
||||
controller = unifi.UniFiController(hass, None)
|
||||
|
||||
controller._site_role = 'admin'
|
||||
|
||||
controller.api = Mock()
|
||||
controller.mock_requests = []
|
||||
|
||||
@@ -257,13 +261,25 @@ async def test_controller_not_client(hass, mock_controller):
|
||||
assert cloudkey is None
|
||||
|
||||
|
||||
async def test_switches(hass, mock_controller):
|
||||
"""Test the update_items function with some lights."""
|
||||
mock_controller.mock_client_responses.append([CLIENT_1, CLIENT_4])
|
||||
mock_controller.mock_device_responses.append([DEVICE_1])
|
||||
async def test_not_admin(hass, mock_controller):
|
||||
"""Test that switch platform only work on an admin account."""
|
||||
mock_controller.mock_client_responses.append([CLIENT_1])
|
||||
mock_controller.mock_device_responses.append([])
|
||||
|
||||
mock_controller._site_role = 'viewer'
|
||||
|
||||
await setup_controller(hass, mock_controller)
|
||||
assert len(mock_controller.mock_requests) == 2
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
||||
|
||||
async def test_switches(hass, mock_controller):
|
||||
"""Test the update_items function with some clients."""
|
||||
mock_controller.mock_client_responses.append([CLIENT_1, CLIENT_4])
|
||||
mock_controller.mock_device_responses.append([DEVICE_1])
|
||||
|
||||
await setup_controller(hass, mock_controller)
|
||||
assert len(mock_controller.mock_requests) == 2
|
||||
# 1 All Lights group, 2 lights
|
||||
assert len(hass.states.async_all()) == 2
|
||||
|
||||
switch_1 = hass.states.get('switch.client_1')
|
||||
@@ -276,8 +292,8 @@ async def test_switches(hass, mock_controller):
|
||||
assert switch_1.attributes['port'] == 1
|
||||
assert switch_1.attributes['poe_mode'] == 'auto'
|
||||
|
||||
switch = hass.states.get('switch.client_4')
|
||||
assert switch is None
|
||||
switch_4 = hass.states.get('switch.client_4')
|
||||
assert switch_4 is None
|
||||
|
||||
|
||||
async def test_new_client_discovered(hass, mock_controller):
|
||||
@@ -296,13 +312,37 @@ async def test_new_client_discovered(hass, mock_controller):
|
||||
await hass.services.async_call('switch', 'turn_off', {
|
||||
'entity_id': 'switch.client_1'
|
||||
}, blocking=True)
|
||||
# 2x light update, 1 turn on request
|
||||
assert len(mock_controller.mock_requests) == 5
|
||||
assert len(hass.states.async_all()) == 3
|
||||
assert mock_controller.mock_requests[2] == {
|
||||
'json': {
|
||||
'port_overrides': [{
|
||||
'port_idx': 1,
|
||||
'portconf_id': '1a1',
|
||||
'poe_mode': 'off'}]
|
||||
},
|
||||
'method': 'put',
|
||||
'path': 's/{site}/rest/device/mock-id'
|
||||
}
|
||||
|
||||
switch = hass.states.get('switch.client_2')
|
||||
assert switch is not None
|
||||
assert switch.state == 'on'
|
||||
await hass.services.async_call('switch', 'turn_on', {
|
||||
'entity_id': 'switch.client_1'
|
||||
}, blocking=True)
|
||||
assert len(mock_controller.mock_requests) == 7
|
||||
assert mock_controller.mock_requests[5] == {
|
||||
'json': {
|
||||
'port_overrides': [{
|
||||
'port_idx': 1,
|
||||
'portconf_id': '1a1',
|
||||
'poe_mode': 'auto'}]
|
||||
},
|
||||
'method': 'put',
|
||||
'path': 's/{site}/rest/device/mock-id'
|
||||
}
|
||||
|
||||
switch_2 = hass.states.get('switch.client_2')
|
||||
assert switch_2 is not None
|
||||
assert switch_2.state == 'on'
|
||||
|
||||
|
||||
async def test_failed_update_successful_login(hass, mock_controller):
|
||||
@@ -346,7 +386,7 @@ async def test_failed_update_unreachable_controller(hass, mock_controller):
|
||||
await hass.services.async_call('switch', 'turn_off', {
|
||||
'entity_id': 'switch.client_1'
|
||||
}, blocking=True)
|
||||
# 2x light update, 1 turn on request
|
||||
|
||||
assert len(mock_controller.mock_requests) == 3
|
||||
assert len(hass.states.async_all()) == 3
|
||||
|
||||
|
||||
Reference in new issue
Block a user