mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Remove vendor lookup for mac addresses (#13788)
* Remove vendor lookup for mac addresses * Fix tests
This commit is contained in:
@@ -24,9 +24,7 @@ from homeassistant.remote import JSONEncoder
|
||||
|
||||
from tests.common import (
|
||||
get_test_home_assistant, fire_time_changed,
|
||||
patch_yaml_files, assert_setup_component, mock_restore_cache, mock_coro)
|
||||
|
||||
from ...test_util.aiohttp import mock_aiohttp_client
|
||||
patch_yaml_files, assert_setup_component, mock_restore_cache)
|
||||
|
||||
TEST_PLATFORM = {device_tracker.DOMAIN: {CONF_PLATFORM: 'test'}}
|
||||
|
||||
@@ -111,7 +109,6 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||
self.assertEqual(device.config_picture, config.config_picture)
|
||||
self.assertEqual(device.away_hide, config.away_hide)
|
||||
self.assertEqual(device.consider_home, config.consider_home)
|
||||
self.assertEqual(device.vendor, config.vendor)
|
||||
self.assertEqual(device.icon, config.icon)
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
@@ -173,124 +170,6 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||
"55502f40dc8b7c769880b10874abc9d0.jpg?s=80&d=wavatar")
|
||||
self.assertEqual(device.config_picture, gravatar_url)
|
||||
|
||||
def test_mac_vendor_lookup(self):
|
||||
"""Test if vendor string is lookup on macvendors API."""
|
||||
mac = 'B8:27:EB:00:00:00'
|
||||
vendor_string = 'Raspberry Pi Foundation'
|
||||
|
||||
device = device_tracker.Device(
|
||||
self.hass, timedelta(seconds=180), True, 'test', mac, 'Test name')
|
||||
|
||||
with mock_aiohttp_client() as aioclient_mock:
|
||||
aioclient_mock.get('http://api.macvendors.com/b8:27:eb',
|
||||
text=vendor_string)
|
||||
|
||||
run_coroutine_threadsafe(device.set_vendor_for_mac(),
|
||||
self.hass.loop).result()
|
||||
assert aioclient_mock.call_count == 1
|
||||
|
||||
self.assertEqual(device.vendor, vendor_string)
|
||||
|
||||
def test_mac_vendor_mac_formats(self):
|
||||
"""Verify all variations of MAC addresses are handled correctly."""
|
||||
vendor_string = 'Raspberry Pi Foundation'
|
||||
|
||||
with mock_aiohttp_client() as aioclient_mock:
|
||||
aioclient_mock.get('http://api.macvendors.com/b8:27:eb',
|
||||
text=vendor_string)
|
||||
aioclient_mock.get('http://api.macvendors.com/00:27:eb',
|
||||
text=vendor_string)
|
||||
|
||||
mac = 'B8:27:EB:00:00:00'
|
||||
device = device_tracker.Device(
|
||||
self.hass, timedelta(seconds=180),
|
||||
True, 'test', mac, 'Test name')
|
||||
run_coroutine_threadsafe(device.set_vendor_for_mac(),
|
||||
self.hass.loop).result()
|
||||
self.assertEqual(device.vendor, vendor_string)
|
||||
|
||||
mac = '0:27:EB:00:00:00'
|
||||
device = device_tracker.Device(
|
||||
self.hass, timedelta(seconds=180),
|
||||
True, 'test', mac, 'Test name')
|
||||
run_coroutine_threadsafe(device.set_vendor_for_mac(),
|
||||
self.hass.loop).result()
|
||||
self.assertEqual(device.vendor, vendor_string)
|
||||
|
||||
mac = 'PREFIXED_B8:27:EB:00:00:00'
|
||||
device = device_tracker.Device(
|
||||
self.hass, timedelta(seconds=180),
|
||||
True, 'test', mac, 'Test name')
|
||||
run_coroutine_threadsafe(device.set_vendor_for_mac(),
|
||||
self.hass.loop).result()
|
||||
self.assertEqual(device.vendor, vendor_string)
|
||||
|
||||
def test_mac_vendor_lookup_unknown(self):
|
||||
"""Prevent another mac vendor lookup if was not found first time."""
|
||||
mac = 'B8:27:EB:00:00:00'
|
||||
|
||||
device = device_tracker.Device(
|
||||
self.hass, timedelta(seconds=180), True, 'test', mac, 'Test name')
|
||||
|
||||
with mock_aiohttp_client() as aioclient_mock:
|
||||
aioclient_mock.get('http://api.macvendors.com/b8:27:eb',
|
||||
status=404)
|
||||
|
||||
run_coroutine_threadsafe(device.set_vendor_for_mac(),
|
||||
self.hass.loop).result()
|
||||
|
||||
self.assertEqual(device.vendor, 'unknown')
|
||||
|
||||
def test_mac_vendor_lookup_error(self):
|
||||
"""Prevent another lookup if failure during API call."""
|
||||
mac = 'B8:27:EB:00:00:00'
|
||||
|
||||
device = device_tracker.Device(
|
||||
self.hass, timedelta(seconds=180), True, 'test', mac, 'Test name')
|
||||
|
||||
with mock_aiohttp_client() as aioclient_mock:
|
||||
aioclient_mock.get('http://api.macvendors.com/b8:27:eb',
|
||||
status=500)
|
||||
|
||||
run_coroutine_threadsafe(device.set_vendor_for_mac(),
|
||||
self.hass.loop).result()
|
||||
|
||||
self.assertEqual(device.vendor, 'unknown')
|
||||
|
||||
def test_mac_vendor_lookup_exception(self):
|
||||
"""Prevent another lookup if exception during API call."""
|
||||
mac = 'B8:27:EB:00:00:00'
|
||||
|
||||
device = device_tracker.Device(
|
||||
self.hass, timedelta(seconds=180), True, 'test', mac, 'Test name')
|
||||
|
||||
with mock_aiohttp_client() as aioclient_mock:
|
||||
aioclient_mock.get('http://api.macvendors.com/b8:27:eb',
|
||||
exc=asyncio.TimeoutError())
|
||||
|
||||
run_coroutine_threadsafe(device.set_vendor_for_mac(),
|
||||
self.hass.loop).result()
|
||||
|
||||
self.assertEqual(device.vendor, 'unknown')
|
||||
|
||||
def test_mac_vendor_lookup_on_see(self):
|
||||
"""Test if macvendor is looked up when device is seen."""
|
||||
mac = 'B8:27:EB:00:00:00'
|
||||
vendor_string = 'Raspberry Pi Foundation'
|
||||
|
||||
tracker = device_tracker.DeviceTracker(
|
||||
self.hass, timedelta(seconds=60), 0, {}, [])
|
||||
|
||||
with mock_aiohttp_client() as aioclient_mock:
|
||||
aioclient_mock.get('http://api.macvendors.com/b8:27:eb',
|
||||
text=vendor_string)
|
||||
|
||||
run_coroutine_threadsafe(
|
||||
tracker.async_see(mac=mac), self.hass.loop).result()
|
||||
assert aioclient_mock.call_count == 1, \
|
||||
'No http request for macvendor made!'
|
||||
self.assertEqual(tracker.devices['b827eb000000'].vendor, vendor_string)
|
||||
|
||||
@patch(
|
||||
'homeassistant.components.device_tracker.DeviceTracker.see')
|
||||
@patch(
|
||||
@@ -463,7 +342,6 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||
'entity_id': 'device_tracker.hello',
|
||||
'host_name': 'hello',
|
||||
'mac': 'MAC_1',
|
||||
'vendor': 'unknown',
|
||||
}
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
@@ -495,9 +373,7 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
||||
timedelta(seconds=0))
|
||||
assert len(config) == 0
|
||||
|
||||
@patch('homeassistant.components.device_tracker.Device'
|
||||
'.set_vendor_for_mac', return_value=mock_coro())
|
||||
def test_see_state(self, mock_set_vendor):
|
||||
def test_see_state(self):
|
||||
"""Test device tracker see records state correctly."""
|
||||
self.assertTrue(setup_component(self.hass, device_tracker.DOMAIN,
|
||||
TEST_PLATFORM))
|
||||
|
||||
Reference in New Issue
Block a user