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
10 changes: 5 additions & 5 deletions homeassistant/components/device_tracker/unifi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
https://home-assistant.io/components/device_tracker.unifi/
"""
import logging
import urllib
import voluptuous as vol

import homeassistant.helpers.config_validation as cv
Expand All @@ -15,7 +14,7 @@
from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD
from homeassistant.const import CONF_VERIFY_SSL

REQUIREMENTS = ['pyunifi==2.12']
REQUIREMENTS = ['pyunifi==2.13']

_LOGGER = logging.getLogger(__name__)
CONF_PORT = 'port'
Expand All @@ -40,7 +39,7 @@

def get_scanner(hass, config):
"""Set up the Unifi device_tracker."""
from pyunifi.controller import Controller
from pyunifi.controller import Controller, APIError

host = config[DOMAIN].get(CONF_HOST)
username = config[DOMAIN].get(CONF_USERNAME)
Expand All @@ -53,7 +52,7 @@ def get_scanner(hass, config):
try:
ctrl = Controller(host, username, password, port, version='v4',
site_id=site_id, ssl_verify=verify_ssl)
except urllib.error.HTTPError as ex:
except APIError as ex:
_LOGGER.error("Failed to connect to Unifi: %s", ex)
persistent_notification.create(
hass, 'Failed to connect to Unifi. '
Expand All @@ -77,9 +76,10 @@ def __init__(self, controller):

def _update(self):
"""Get the clients from the device."""
from pyunifi.controller import APIError
try:
clients = self._controller.get_clients()
except urllib.error.HTTPError as ex:
except APIError as ex:
_LOGGER.error("Failed to scan clients: %s", ex)
clients = []

Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ pytrackr==0.0.5
pytradfri==1.1

# homeassistant.components.device_tracker.unifi
pyunifi==2.12
pyunifi==2.13

# homeassistant.components.keyboard
# pyuserinput==0.1.11
Expand Down
3 changes: 3 additions & 0 deletions requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ pynx584==0.4
# homeassistant.components.sensor.darksky
python-forecastio==1.3.5

# homeassistant.components.device_tracker.unifi
pyunifi==2.13

# homeassistant.components.notify.html5
pywebpush==1.0.4

Expand Down
1 change: 1 addition & 0 deletions script/gen_requirements_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
'pywebpush',
'PyJWT',
'restrictedpython',
'pyunifi',
)

IGNORE_PACKAGES = (
Expand Down
13 changes: 5 additions & 8 deletions tests/components/device_tracker/test_unifi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""The tests for the Unifi WAP device tracker platform."""
from unittest import mock
import urllib
from pyunifi.controller import APIError

import pytest
import voluptuous as vol
Expand All @@ -13,11 +13,8 @@
@pytest.fixture
def mock_ctrl():
"""Mock pyunifi."""
module = mock.MagicMock()
with mock.patch.dict('sys.modules', {
'pyunifi.controller': module.controller,
}):
yield module.controller.Controller
with mock.patch('pyunifi.controller.Controller') as mock_control:
yield mock_control


@pytest.fixture
Expand Down Expand Up @@ -100,7 +97,7 @@ def test_config_controller_failed(hass, mock_ctrl, mock_scanner):
CONF_PASSWORD: 'password',
}
}
mock_ctrl.side_effect = urllib.error.HTTPError(
mock_ctrl.side_effect = APIError(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'APIError'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to import APIError first.

'/', 500, 'foo', {}, None)
result = unifi.get_scanner(hass, config)
assert result is False
Expand All @@ -122,7 +119,7 @@ def test_scanner_update():
def test_scanner_update_error():
"""Test the scanner update for error."""
ctrl = mock.MagicMock()
ctrl.get_clients.side_effect = urllib.error.HTTPError(
ctrl.get_clients.side_effect = APIError(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'APIError'

'/', 500, 'foo', {}, None)
unifi.UnifiScanner(ctrl)

Expand Down