Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion homeassistant/components/switch/unifi.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def update_switch_state():
# Network device with active POE
if not client.is_wired or client.sw_mac not in devices or \
not devices[client.sw_mac].ports[client.sw_port].port_poe or \
not devices[client.sw_mac].ports[client.sw_port].poe_enable:
not devices[client.sw_mac].ports[client.sw_port].poe_enable or \
controller.mac == client.mac:
continue

# Multiple POE-devices on same port means non UniFi POE driven switch
Expand Down
24 changes: 24 additions & 0 deletions tests/components/switch/test_unifi.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
'wired-rx_bytes': 1234000000,
'wired-tx_bytes': 5678000000
}
CLOUDKEY = {
'hostname': 'client_1',
'ip': 'mock-host',
'is_wired': True,
'mac': '10:00:00:00:00:01',
'name': 'Cloud key',
'oui': 'Producer',
'sw_mac': '00:00:00:00:01:01',
'sw_port': 1,
'wired-rx_bytes': 1234000000,
'wired-tx_bytes': 5678000000
}
POE_SWITCH_CLIENTS = [
{
'hostname': 'client_1',
Expand Down Expand Up @@ -179,6 +191,7 @@ def mock_controller(hass):
api=Mock(),
spec=unifi.UniFiController
)
controller.mac = '10:00:00:00:00:01'
controller.mock_requests = []

controller.mock_client_responses = deque()
Expand Down Expand Up @@ -230,6 +243,17 @@ async def test_no_clients(hass, mock_controller):
assert not hass.states.async_all()


async def test_controller_not_client(hass, mock_controller):
"""Test that the controller doesn't become a switch."""
mock_controller.mock_client_responses.append([CLOUDKEY])
mock_controller.mock_device_responses.append([DEVICE_1])
await setup_controller(hass, mock_controller)
assert len(mock_controller.mock_requests) == 2
assert not hass.states.async_all()
cloudkey = hass.states.get('switch.cloud_key')
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])
Expand Down