2018-10-16 08:35:35 +00:00
|
|
|
"""UniFi POE control platform tests."""
|
2019-10-05 14:16:08 +00:00
|
|
|
from copy import deepcopy
|
2018-10-16 08:35:35 +00:00
|
|
|
|
|
|
|
from homeassistant import config_entries
|
|
|
|
from homeassistant.components import unifi
|
2019-12-09 11:19:34 +00:00
|
|
|
import homeassistant.components.switch as switch
|
2019-07-29 17:48:38 +00:00
|
|
|
from homeassistant.helpers import entity_registry
|
2018-10-16 08:35:35 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
2019-10-07 19:55:35 +00:00
|
|
|
from .test_controller import (
|
|
|
|
CONTROLLER_HOST,
|
|
|
|
ENTRY_CONFIG,
|
|
|
|
SITES,
|
|
|
|
setup_unifi_integration,
|
|
|
|
)
|
|
|
|
|
2018-10-16 08:35:35 +00:00
|
|
|
CLIENT_1 = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"hostname": "client_1",
|
|
|
|
"ip": "10.0.0.1",
|
|
|
|
"is_wired": True,
|
2019-10-05 14:16:08 +00:00
|
|
|
"last_seen": 1562600145,
|
2019-07-31 19:25:30 +00:00
|
|
|
"mac": "00:00:00:00:00:01",
|
|
|
|
"name": "POE Client 1",
|
|
|
|
"oui": "Producer",
|
|
|
|
"sw_mac": "00:00:00:00:01:01",
|
|
|
|
"sw_port": 1,
|
|
|
|
"wired-rx_bytes": 1234000000,
|
|
|
|
"wired-tx_bytes": 5678000000,
|
2018-10-16 08:35:35 +00:00
|
|
|
}
|
|
|
|
CLIENT_2 = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"hostname": "client_2",
|
|
|
|
"ip": "10.0.0.2",
|
|
|
|
"is_wired": True,
|
2019-10-05 14:16:08 +00:00
|
|
|
"last_seen": 1562600145,
|
2019-07-31 19:25:30 +00:00
|
|
|
"mac": "00:00:00:00:00:02",
|
|
|
|
"name": "POE Client 2",
|
|
|
|
"oui": "Producer",
|
|
|
|
"sw_mac": "00:00:00:00:01:01",
|
|
|
|
"sw_port": 2,
|
|
|
|
"wired-rx_bytes": 1234000000,
|
|
|
|
"wired-tx_bytes": 5678000000,
|
2018-10-16 08:35:35 +00:00
|
|
|
}
|
|
|
|
CLIENT_3 = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"hostname": "client_3",
|
|
|
|
"ip": "10.0.0.3",
|
|
|
|
"is_wired": True,
|
2019-10-05 14:16:08 +00:00
|
|
|
"last_seen": 1562600145,
|
2019-07-31 19:25:30 +00:00
|
|
|
"mac": "00:00:00:00:00:03",
|
|
|
|
"name": "Non-POE Client 3",
|
|
|
|
"oui": "Producer",
|
|
|
|
"sw_mac": "00:00:00:00:01:01",
|
|
|
|
"sw_port": 3,
|
|
|
|
"wired-rx_bytes": 1234000000,
|
|
|
|
"wired-tx_bytes": 5678000000,
|
2018-10-16 08:35:35 +00:00
|
|
|
}
|
|
|
|
CLIENT_4 = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"hostname": "client_4",
|
|
|
|
"ip": "10.0.0.4",
|
|
|
|
"is_wired": True,
|
2019-10-05 14:16:08 +00:00
|
|
|
"last_seen": 1562600145,
|
2019-07-31 19:25:30 +00:00
|
|
|
"mac": "00:00:00:00:00:04",
|
|
|
|
"name": "Non-POE Client 4",
|
|
|
|
"oui": "Producer",
|
|
|
|
"sw_mac": "00:00:00:00:01:01",
|
|
|
|
"sw_port": 4,
|
|
|
|
"wired-rx_bytes": 1234000000,
|
|
|
|
"wired-tx_bytes": 5678000000,
|
2018-10-16 08:35:35 +00:00
|
|
|
}
|
|
|
|
POE_SWITCH_CLIENTS = [
|
|
|
|
{
|
2019-07-31 19:25:30 +00:00
|
|
|
"hostname": "client_1",
|
|
|
|
"ip": "10.0.0.1",
|
|
|
|
"is_wired": True,
|
2019-10-05 14:16:08 +00:00
|
|
|
"last_seen": 1562600145,
|
2019-07-31 19:25:30 +00:00
|
|
|
"mac": "00:00:00:00:00:01",
|
|
|
|
"name": "POE Client 1",
|
|
|
|
"oui": "Producer",
|
|
|
|
"sw_mac": "00:00:00:00:01:01",
|
|
|
|
"sw_port": 1,
|
|
|
|
"wired-rx_bytes": 1234000000,
|
|
|
|
"wired-tx_bytes": 5678000000,
|
2018-10-16 08:35:35 +00:00
|
|
|
},
|
|
|
|
{
|
2019-07-31 19:25:30 +00:00
|
|
|
"hostname": "client_2",
|
|
|
|
"ip": "10.0.0.2",
|
|
|
|
"is_wired": True,
|
2019-10-05 14:16:08 +00:00
|
|
|
"last_seen": 1562600145,
|
2019-07-31 19:25:30 +00:00
|
|
|
"mac": "00:00:00:00:00:02",
|
|
|
|
"name": "POE Client 2",
|
|
|
|
"oui": "Producer",
|
|
|
|
"sw_mac": "00:00:00:00:01:01",
|
|
|
|
"sw_port": 1,
|
|
|
|
"wired-rx_bytes": 1234000000,
|
|
|
|
"wired-tx_bytes": 5678000000,
|
|
|
|
},
|
2018-10-16 08:35:35 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
DEVICE_1 = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"device_id": "mock-id",
|
|
|
|
"ip": "10.0.1.1",
|
|
|
|
"mac": "00:00:00:00:01:01",
|
2019-10-05 14:16:08 +00:00
|
|
|
"last_seen": 1562600145,
|
|
|
|
"model": "US16P150",
|
2019-07-31 19:25:30 +00:00
|
|
|
"name": "mock-name",
|
|
|
|
"port_overrides": [],
|
|
|
|
"port_table": [
|
2018-10-16 08:35:35 +00:00
|
|
|
{
|
2019-07-31 19:25:30 +00:00
|
|
|
"media": "GE",
|
|
|
|
"name": "Port 1",
|
|
|
|
"port_idx": 1,
|
|
|
|
"poe_class": "Class 4",
|
|
|
|
"poe_enable": True,
|
|
|
|
"poe_mode": "auto",
|
|
|
|
"poe_power": "2.56",
|
|
|
|
"poe_voltage": "53.40",
|
|
|
|
"portconf_id": "1a1",
|
|
|
|
"port_poe": True,
|
|
|
|
"up": True,
|
2018-10-16 08:35:35 +00:00
|
|
|
},
|
|
|
|
{
|
2019-07-31 19:25:30 +00:00
|
|
|
"media": "GE",
|
|
|
|
"name": "Port 2",
|
|
|
|
"port_idx": 2,
|
|
|
|
"poe_class": "Class 4",
|
|
|
|
"poe_enable": True,
|
|
|
|
"poe_mode": "auto",
|
|
|
|
"poe_power": "2.56",
|
|
|
|
"poe_voltage": "53.40",
|
|
|
|
"portconf_id": "1a2",
|
|
|
|
"port_poe": True,
|
|
|
|
"up": True,
|
2018-10-16 08:35:35 +00:00
|
|
|
},
|
|
|
|
{
|
2019-07-31 19:25:30 +00:00
|
|
|
"media": "GE",
|
|
|
|
"name": "Port 3",
|
|
|
|
"port_idx": 3,
|
|
|
|
"poe_class": "Unknown",
|
|
|
|
"poe_enable": False,
|
|
|
|
"poe_mode": "off",
|
|
|
|
"poe_power": "0.00",
|
|
|
|
"poe_voltage": "0.00",
|
|
|
|
"portconf_id": "1a3",
|
|
|
|
"port_poe": False,
|
|
|
|
"up": True,
|
2018-10-16 08:35:35 +00:00
|
|
|
},
|
|
|
|
{
|
2019-07-31 19:25:30 +00:00
|
|
|
"media": "GE",
|
|
|
|
"name": "Port 4",
|
|
|
|
"port_idx": 4,
|
|
|
|
"poe_class": "Unknown",
|
|
|
|
"poe_enable": False,
|
|
|
|
"poe_mode": "auto",
|
|
|
|
"poe_power": "0.00",
|
|
|
|
"poe_voltage": "0.00",
|
|
|
|
"portconf_id": "1a4",
|
|
|
|
"port_poe": True,
|
|
|
|
"up": True,
|
|
|
|
},
|
|
|
|
],
|
2019-10-05 14:16:08 +00:00
|
|
|
"state": 1,
|
|
|
|
"type": "usw",
|
|
|
|
"version": "4.0.42.10433",
|
2018-10-16 08:35:35 +00:00
|
|
|
}
|
|
|
|
|
2019-07-25 14:56:56 +00:00
|
|
|
BLOCKED = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"blocked": True,
|
|
|
|
"hostname": "block_client_1",
|
|
|
|
"ip": "10.0.0.1",
|
|
|
|
"is_guest": False,
|
|
|
|
"is_wired": False,
|
|
|
|
"mac": "00:00:00:00:01:01",
|
|
|
|
"name": "Block Client 1",
|
|
|
|
"noted": True,
|
|
|
|
"oui": "Producer",
|
2019-07-25 14:56:56 +00:00
|
|
|
}
|
|
|
|
UNBLOCKED = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"blocked": False,
|
|
|
|
"hostname": "block_client_2",
|
|
|
|
"ip": "10.0.0.2",
|
|
|
|
"is_guest": False,
|
|
|
|
"is_wired": True,
|
|
|
|
"mac": "00:00:00:00:01:02",
|
|
|
|
"name": "Block Client 2",
|
|
|
|
"noted": True,
|
|
|
|
"oui": "Producer",
|
2019-07-25 14:56:56 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 08:35:35 +00:00
|
|
|
|
|
|
|
async def test_platform_manually_configured(hass):
|
2019-10-05 14:16:08 +00:00
|
|
|
"""Test that we do not discover anything or try to set up a controller."""
|
2019-07-31 19:25:30 +00:00
|
|
|
assert (
|
|
|
|
await async_setup_component(
|
2019-10-05 14:16:08 +00:00
|
|
|
hass, switch.DOMAIN, {switch.DOMAIN: {"platform": "unifi"}}
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
|
|
|
is True
|
|
|
|
)
|
2018-10-16 08:35:35 +00:00
|
|
|
assert unifi.DOMAIN not in hass.data
|
|
|
|
|
|
|
|
|
2019-10-05 14:16:08 +00:00
|
|
|
async def test_no_clients(hass):
|
2018-10-16 08:35:35 +00:00
|
|
|
"""Test the update_clients function when no clients are found."""
|
2019-10-05 14:16:08 +00:00
|
|
|
controller = await setup_unifi_integration(
|
|
|
|
hass,
|
|
|
|
ENTRY_CONFIG,
|
|
|
|
options={
|
|
|
|
unifi.const.CONF_TRACK_CLIENTS: False,
|
|
|
|
unifi.const.CONF_TRACK_DEVICES: False,
|
|
|
|
},
|
|
|
|
sites=SITES,
|
|
|
|
clients_response=[],
|
|
|
|
devices_response=[],
|
|
|
|
clients_all_response=[],
|
|
|
|
)
|
|
|
|
|
|
|
|
assert len(controller.mock_requests) == 3
|
|
|
|
assert len(hass.states.async_all()) == 2
|
2018-10-16 08:35:35 +00:00
|
|
|
|
|
|
|
|
2019-10-05 14:16:08 +00:00
|
|
|
async def test_controller_not_client(hass):
|
2018-11-02 20:09:16 +00:00
|
|
|
"""Test that the controller doesn't become a switch."""
|
2019-10-05 14:16:08 +00:00
|
|
|
controller = await setup_unifi_integration(
|
|
|
|
hass,
|
|
|
|
ENTRY_CONFIG,
|
|
|
|
options={
|
|
|
|
unifi.const.CONF_TRACK_CLIENTS: False,
|
|
|
|
unifi.const.CONF_TRACK_DEVICES: False,
|
|
|
|
},
|
|
|
|
sites=SITES,
|
2019-10-07 19:55:35 +00:00
|
|
|
clients_response=[CONTROLLER_HOST],
|
2019-10-05 14:16:08 +00:00
|
|
|
devices_response=[DEVICE_1],
|
|
|
|
clients_all_response=[],
|
|
|
|
)
|
|
|
|
|
|
|
|
assert len(controller.mock_requests) == 3
|
|
|
|
assert len(hass.states.async_all()) == 2
|
2019-07-31 19:25:30 +00:00
|
|
|
cloudkey = hass.states.get("switch.cloud_key")
|
2018-11-02 20:09:16 +00:00
|
|
|
assert cloudkey is None
|
|
|
|
|
|
|
|
|
2019-10-05 14:16:08 +00:00
|
|
|
async def test_not_admin(hass):
|
2019-07-14 19:57:09 +00:00
|
|
|
"""Test that switch platform only work on an admin account."""
|
2019-10-05 14:16:08 +00:00
|
|
|
sites = deepcopy(SITES)
|
|
|
|
sites["Site name"]["role"] = "not admin"
|
|
|
|
controller = await setup_unifi_integration(
|
|
|
|
hass,
|
|
|
|
ENTRY_CONFIG,
|
|
|
|
options={
|
|
|
|
unifi.const.CONF_TRACK_CLIENTS: False,
|
|
|
|
unifi.const.CONF_TRACK_DEVICES: False,
|
|
|
|
},
|
|
|
|
sites=sites,
|
|
|
|
clients_response=[CLIENT_1],
|
|
|
|
devices_response=[DEVICE_1],
|
|
|
|
clients_all_response=[],
|
|
|
|
)
|
2019-07-14 19:57:09 +00:00
|
|
|
|
2019-10-05 14:16:08 +00:00
|
|
|
assert len(controller.mock_requests) == 3
|
|
|
|
assert len(hass.states.async_all()) == 2
|
2019-07-14 19:57:09 +00:00
|
|
|
|
|
|
|
|
2019-10-05 14:16:08 +00:00
|
|
|
async def test_switches(hass):
|
2019-07-14 19:57:09 +00:00
|
|
|
"""Test the update_items function with some clients."""
|
2019-10-05 14:16:08 +00:00
|
|
|
controller = await setup_unifi_integration(
|
|
|
|
hass,
|
|
|
|
ENTRY_CONFIG,
|
|
|
|
options={
|
|
|
|
unifi.CONF_BLOCK_CLIENT: [BLOCKED["mac"], UNBLOCKED["mac"]],
|
|
|
|
unifi.const.CONF_TRACK_CLIENTS: False,
|
|
|
|
unifi.const.CONF_TRACK_DEVICES: False,
|
|
|
|
},
|
|
|
|
sites=SITES,
|
|
|
|
clients_response=[CLIENT_1, CLIENT_4],
|
|
|
|
devices_response=[DEVICE_1],
|
|
|
|
clients_all_response=[BLOCKED, UNBLOCKED, CLIENT_1],
|
|
|
|
)
|
2019-07-14 19:57:09 +00:00
|
|
|
|
2019-10-05 14:16:08 +00:00
|
|
|
assert len(controller.mock_requests) == 3
|
|
|
|
assert len(hass.states.async_all()) == 6
|
2018-10-16 08:35:35 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
switch_1 = hass.states.get("switch.poe_client_1")
|
2018-10-16 08:35:35 +00:00
|
|
|
assert switch_1 is not None
|
2019-07-31 19:25:30 +00:00
|
|
|
assert switch_1.state == "on"
|
|
|
|
assert switch_1.attributes["power"] == "2.56"
|
|
|
|
assert switch_1.attributes["switch"] == "00:00:00:00:01:01"
|
|
|
|
assert switch_1.attributes["port"] == 1
|
|
|
|
assert switch_1.attributes["poe_mode"] == "auto"
|
|
|
|
|
|
|
|
switch_4 = hass.states.get("switch.poe_client_4")
|
2019-07-14 19:57:09 +00:00
|
|
|
assert switch_4 is None
|
2018-10-16 08:35:35 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
blocked = hass.states.get("switch.block_client_1")
|
2019-07-25 14:56:56 +00:00
|
|
|
assert blocked is not None
|
2019-08-04 14:57:36 +00:00
|
|
|
assert blocked.state == "off"
|
2019-07-25 14:56:56 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
unblocked = hass.states.get("switch.block_client_2")
|
2019-07-25 14:56:56 +00:00
|
|
|
assert unblocked is not None
|
2019-08-04 14:57:36 +00:00
|
|
|
assert unblocked.state == "on"
|
2019-07-25 14:56:56 +00:00
|
|
|
|
2018-10-16 08:35:35 +00:00
|
|
|
|
2019-10-07 19:55:35 +00:00
|
|
|
async def test_new_client_discovered_on_block_control(hass):
|
|
|
|
"""Test if 2nd update has a new client."""
|
|
|
|
controller = await setup_unifi_integration(
|
|
|
|
hass,
|
|
|
|
ENTRY_CONFIG,
|
|
|
|
options={
|
|
|
|
unifi.CONF_BLOCK_CLIENT: [BLOCKED["mac"]],
|
|
|
|
unifi.const.CONF_TRACK_CLIENTS: False,
|
|
|
|
unifi.const.CONF_TRACK_DEVICES: False,
|
|
|
|
},
|
|
|
|
sites=SITES,
|
|
|
|
clients_response=[],
|
|
|
|
devices_response=[],
|
|
|
|
clients_all_response=[BLOCKED],
|
|
|
|
)
|
|
|
|
|
|
|
|
assert len(controller.mock_requests) == 3
|
|
|
|
assert len(hass.states.async_all()) == 4
|
|
|
|
|
|
|
|
controller.mock_client_all_responses.append([BLOCKED])
|
|
|
|
|
|
|
|
# Calling a service will trigger the updates to run
|
|
|
|
await hass.services.async_call(
|
|
|
|
"switch", "turn_off", {"entity_id": "switch.block_client_1"}, blocking=True
|
|
|
|
)
|
|
|
|
assert len(controller.mock_requests) == 7
|
|
|
|
assert len(hass.states.async_all()) == 4
|
|
|
|
assert controller.mock_requests[3] == {
|
|
|
|
"json": {"mac": "00:00:00:00:01:01", "cmd": "block-sta"},
|
|
|
|
"method": "post",
|
|
|
|
"path": "s/{site}/cmd/stamgr/",
|
|
|
|
}
|
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
"switch", "turn_on", {"entity_id": "switch.block_client_1"}, blocking=True
|
|
|
|
)
|
|
|
|
assert len(controller.mock_requests) == 11
|
|
|
|
assert controller.mock_requests[7] == {
|
|
|
|
"json": {"mac": "00:00:00:00:01:01", "cmd": "unblock-sta"},
|
|
|
|
"method": "post",
|
|
|
|
"path": "s/{site}/cmd/stamgr/",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async def test_new_client_discovered_on_poe_control(hass):
|
2018-10-16 08:35:35 +00:00
|
|
|
"""Test if 2nd update has a new client."""
|
2019-10-05 14:16:08 +00:00
|
|
|
controller = await setup_unifi_integration(
|
|
|
|
hass,
|
|
|
|
ENTRY_CONFIG,
|
|
|
|
options={
|
|
|
|
unifi.const.CONF_TRACK_CLIENTS: False,
|
|
|
|
unifi.const.CONF_TRACK_DEVICES: False,
|
|
|
|
},
|
|
|
|
sites=SITES,
|
|
|
|
clients_response=[CLIENT_1],
|
|
|
|
devices_response=[DEVICE_1],
|
|
|
|
clients_all_response=[],
|
|
|
|
)
|
2018-10-16 08:35:35 +00:00
|
|
|
|
2019-10-05 14:16:08 +00:00
|
|
|
assert len(controller.mock_requests) == 3
|
|
|
|
assert len(hass.states.async_all()) == 4
|
2018-10-16 08:35:35 +00:00
|
|
|
|
2019-10-05 14:16:08 +00:00
|
|
|
controller.mock_client_responses.append([CLIENT_1, CLIENT_2])
|
|
|
|
controller.mock_device_responses.append([DEVICE_1])
|
2018-10-16 08:35:35 +00:00
|
|
|
|
|
|
|
# Calling a service will trigger the updates to run
|
2019-07-31 19:25:30 +00:00
|
|
|
await hass.services.async_call(
|
|
|
|
"switch", "turn_off", {"entity_id": "switch.poe_client_1"}, blocking=True
|
|
|
|
)
|
2019-10-05 14:16:08 +00:00
|
|
|
assert len(controller.mock_requests) == 6
|
|
|
|
assert len(hass.states.async_all()) == 5
|
|
|
|
assert controller.mock_requests[3] == {
|
2019-07-31 19:25:30 +00:00
|
|
|
"json": {
|
|
|
|
"port_overrides": [{"port_idx": 1, "portconf_id": "1a1", "poe_mode": "off"}]
|
2019-07-14 19:57:09 +00:00
|
|
|
},
|
2019-07-31 19:25:30 +00:00
|
|
|
"method": "put",
|
|
|
|
"path": "s/{site}/rest/device/mock-id",
|
2019-07-14 19:57:09 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await hass.services.async_call(
|
|
|
|
"switch", "turn_on", {"entity_id": "switch.poe_client_1"}, blocking=True
|
|
|
|
)
|
2019-10-05 14:16:08 +00:00
|
|
|
assert len(controller.mock_requests) == 9
|
|
|
|
assert controller.mock_requests[3] == {
|
2019-07-31 19:25:30 +00:00
|
|
|
"json": {
|
|
|
|
"port_overrides": [
|
|
|
|
{"port_idx": 1, "portconf_id": "1a1", "poe_mode": "auto"}
|
|
|
|
]
|
2019-07-14 19:57:09 +00:00
|
|
|
},
|
2019-07-31 19:25:30 +00:00
|
|
|
"method": "put",
|
|
|
|
"path": "s/{site}/rest/device/mock-id",
|
2019-07-14 19:57:09 +00:00
|
|
|
}
|
2018-10-16 08:35:35 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
switch_2 = hass.states.get("switch.poe_client_2")
|
2019-07-14 19:57:09 +00:00
|
|
|
assert switch_2 is not None
|
2019-07-31 19:25:30 +00:00
|
|
|
assert switch_2.state == "on"
|
2018-10-16 08:35:35 +00:00
|
|
|
|
|
|
|
|
2019-10-05 14:16:08 +00:00
|
|
|
async def test_ignore_multiple_poe_clients_on_same_port(hass):
|
2018-10-16 08:35:35 +00:00
|
|
|
"""Ignore when there are multiple POE driven clients on same port.
|
|
|
|
|
|
|
|
If there is a non-UniFi switch powered by POE,
|
|
|
|
clients will be transparently marked as having POE as well.
|
|
|
|
"""
|
2019-10-05 14:16:08 +00:00
|
|
|
controller = await setup_unifi_integration(
|
|
|
|
hass,
|
|
|
|
ENTRY_CONFIG,
|
|
|
|
options={},
|
|
|
|
sites=SITES,
|
|
|
|
clients_response=POE_SWITCH_CLIENTS,
|
|
|
|
devices_response=[DEVICE_1],
|
|
|
|
clients_all_response=[],
|
|
|
|
)
|
|
|
|
|
|
|
|
assert len(controller.mock_requests) == 3
|
|
|
|
assert len(hass.states.async_all()) == 5
|
2018-10-16 08:35:35 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
switch_1 = hass.states.get("switch.poe_client_1")
|
|
|
|
switch_2 = hass.states.get("switch.poe_client_2")
|
2018-10-16 08:35:35 +00:00
|
|
|
assert switch_1 is None
|
|
|
|
assert switch_2 is None
|
2019-07-29 17:48:38 +00:00
|
|
|
|
|
|
|
|
2019-10-05 14:16:08 +00:00
|
|
|
async def test_restoring_client(hass):
|
2019-07-29 17:48:38 +00:00
|
|
|
"""Test the update_items function with some clients."""
|
2019-08-18 04:34:11 +00:00
|
|
|
config_entry = config_entries.ConfigEntry(
|
2019-10-05 14:16:08 +00:00
|
|
|
version=1,
|
|
|
|
domain=unifi.DOMAIN,
|
|
|
|
title="Mock Title",
|
|
|
|
data=ENTRY_CONFIG,
|
|
|
|
source="test",
|
|
|
|
connection_class=config_entries.CONN_CLASS_LOCAL_POLL,
|
2019-08-18 04:34:11 +00:00
|
|
|
system_options={},
|
2019-10-05 14:16:08 +00:00
|
|
|
options={},
|
|
|
|
entry_id=1,
|
2019-08-18 04:34:11 +00:00
|
|
|
)
|
|
|
|
|
2019-07-29 17:48:38 +00:00
|
|
|
registry = await entity_registry.async_get_registry(hass)
|
|
|
|
registry.async_get_or_create(
|
2019-07-31 19:25:30 +00:00
|
|
|
switch.DOMAIN,
|
|
|
|
unifi.DOMAIN,
|
|
|
|
"poe-{}".format(CLIENT_1["mac"]),
|
|
|
|
suggested_object_id=CLIENT_1["hostname"],
|
2019-08-18 04:34:11 +00:00
|
|
|
config_entry=config_entry,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-07-29 17:48:38 +00:00
|
|
|
registry.async_get_or_create(
|
2019-07-31 19:25:30 +00:00
|
|
|
switch.DOMAIN,
|
|
|
|
unifi.DOMAIN,
|
|
|
|
"poe-{}".format(CLIENT_2["mac"]),
|
|
|
|
suggested_object_id=CLIENT_2["hostname"],
|
2019-08-18 04:34:11 +00:00
|
|
|
config_entry=config_entry,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-07-29 17:48:38 +00:00
|
|
|
|
2019-10-05 14:16:08 +00:00
|
|
|
controller = await setup_unifi_integration(
|
|
|
|
hass,
|
|
|
|
ENTRY_CONFIG,
|
|
|
|
options={
|
|
|
|
unifi.CONF_BLOCK_CLIENT: ["random mac"],
|
|
|
|
unifi.const.CONF_TRACK_CLIENTS: False,
|
|
|
|
unifi.const.CONF_TRACK_DEVICES: False,
|
|
|
|
},
|
|
|
|
sites=SITES,
|
|
|
|
clients_response=[CLIENT_2],
|
|
|
|
devices_response=[DEVICE_1],
|
|
|
|
clients_all_response=[CLIENT_1],
|
|
|
|
)
|
|
|
|
|
|
|
|
assert len(controller.mock_requests) == 3
|
|
|
|
assert len(hass.states.async_all()) == 5
|
2019-07-29 17:48:38 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
device_1 = hass.states.get("switch.client_1")
|
2019-07-29 17:48:38 +00:00
|
|
|
assert device_1 is not None
|