def test_get_device_name(): """Test the getting of device names.""" ctrl = mock.MagicMock() fake_clients = [ { 'mac': '123', 'hostname': 'foobar', 'essid': 'barnet', 'last_seen': dt_util.as_timestamp(dt_util.utcnow()) }, { 'mac': '234', 'name': 'Nice Name', 'essid': 'barnet', 'last_seen': dt_util.as_timestamp(dt_util.utcnow()) }, { 'mac': '456', 'essid': 'barnet', 'last_seen': '1504786810' }, ] ctrl.get_clients.return_value = fake_clients scanner = unifi.UnifiScanner(ctrl, DEFAULT_DETECTION_TIME, None, None) assert scanner.get_device_name('123') == 'foobar' assert scanner.get_device_name('234') == 'Nice Name' assert scanner.get_device_name('456') is None assert scanner.get_device_name('unknown') is None
def test_scan_devices_filtered(): """Test the scanning for devices based on SSID.""" ctrl = mock.MagicMock() fake_clients = [ { 'mac': '123', 'essid': 'foonet', 'last_seen': dt_util.as_timestamp(dt_util.utcnow()) }, { 'mac': '234', 'essid': 'foonet', 'last_seen': dt_util.as_timestamp(dt_util.utcnow()) }, { 'mac': '567', 'essid': 'notnet', 'last_seen': dt_util.as_timestamp(dt_util.utcnow()) }, { 'mac': '890', 'essid': 'barnet', 'last_seen': dt_util.as_timestamp(dt_util.utcnow()) }, ] ssid_filter = ['foonet', 'barnet'] ctrl.get_clients.return_value = fake_clients scanner = unifi.UnifiScanner(ctrl, DEFAULT_DETECTION_TIME, ssid_filter, None) assert set(scanner.scan_devices()) == set(['123', '234', '890'])
def test_scan_devices(): """Test the scanning for devices.""" ctrl = mock.MagicMock() fake_clients = [ { 'mac': '123', 'essid': 'barnet', 'last_seen': dt_util.as_timestamp(dt_util.utcnow()) }, { 'mac': '234', 'essid': 'barnet', 'last_seen': dt_util.as_timestamp(dt_util.utcnow()) }, ] ctrl.get_clients.return_value = fake_clients scanner = unifi.UnifiScanner(ctrl, DEFAULT_DETECTION_TIME, None, None) assert set(scanner.scan_devices()) == set(['123', '234'])
def test_scanner_update(): """Test the scanner update.""" ctrl = mock.MagicMock() fake_clients = [ { 'mac': '123', 'essid': 'barnet', 'last_seen': dt_util.as_timestamp(dt_util.utcnow()) }, { 'mac': '234', 'essid': 'barnet', 'last_seen': dt_util.as_timestamp(dt_util.utcnow()) }, ] ctrl.get_clients.return_value = fake_clients unifi.UnifiScanner(ctrl, DEFAULT_DETECTION_TIME, None, None) assert ctrl.get_clients.call_count == 1 assert ctrl.get_clients.call_args == mock.call()
async def test_scan_devices(): """Test the scanning for devices.""" ctrl = mock.MagicMock() fake_clients = [ { 'mac': '123', 'essid': 'barnet', 'last_seen': dt_util.as_timestamp(dt_util.utcnow()) }, { 'mac': '234', 'essid': 'barnet', 'last_seen': dt_util.as_timestamp(dt_util.utcnow()) }, ] ctrl.clients = Clients([], CoroutineMock(return_value=fake_clients)) scnr = unifi.UnifiScanner(ctrl, DEFAULT_DETECTION_TIME, None, None) await scnr.async_update() assert set(await scnr.async_scan_devices()) == set(['123', '234'])
async def test_monitored_conditions(): """Test the filtering of attributes.""" ctrl = mock.MagicMock() fake_clients = [ { 'mac': '123', 'hostname': 'foobar', 'essid': 'barnet', 'signal': -60, 'last_seen': dt_util.as_timestamp(dt_util.utcnow()), 'latest_assoc_time': 946684800.0 }, { 'mac': '234', 'name': 'Nice Name', 'essid': 'barnet', 'signal': -42, 'last_seen': dt_util.as_timestamp(dt_util.utcnow()) }, { 'mac': '456', 'hostname': 'wired', 'essid': 'barnet', 'last_seen': dt_util.as_timestamp(dt_util.utcnow()) }, ] ctrl.clients = Clients([], CoroutineMock(return_value=fake_clients)) scnr = unifi.UnifiScanner(ctrl, DEFAULT_DETECTION_TIME, None, ['essid', 'signal', 'latest_assoc_time']) await scnr.async_update() assert scnr.get_extra_attributes('123') == { 'essid': 'barnet', 'signal': -60, 'latest_assoc_time': datetime(2000, 1, 1, 0, 0, tzinfo=dt_util.UTC) } assert scnr.get_extra_attributes('234') == { 'essid': 'barnet', 'signal': -42 } assert scnr.get_extra_attributes('456') == {'essid': 'barnet'}
def test_scanner_update_error(): """Test the scanner update for error.""" ctrl = mock.MagicMock() ctrl.get_clients.side_effect = APIError('/', 500, 'foo', {}, None) unifi.UnifiScanner(ctrl, DEFAULT_DETECTION_TIME, None, None)
def test_scanner_update_error(): """Test the scanner update for error.""" ctrl = mock.MagicMock() ctrl.get_clients.side_effect = unifi.aiounifi.AiounifiException unifi.UnifiScanner(ctrl, DEFAULT_DETECTION_TIME, None, None)