示例#1
0
    def test_track_with_duplicate_mac_dev_id(self, mock_warning):
        """Test adding duplicate MACs or device IDs to DeviceTracker."""
        devices = [
            device_tracker.Device(self.hass, True, True, 'my_device', 'AB:01',
                                  'My device', None, None, False),
            device_tracker.Device(self.hass, True, True, 'your_device',
                                  'AB:01', 'Your device', None, None, False)]
        device_tracker.DeviceTracker(self.hass, False, True, {}, devices)
        _LOGGER.debug(mock_warning.call_args_list)
        assert mock_warning.call_count == 1, \
            "The only warning call should be duplicates (check DEBUG)"
        args, _ = mock_warning.call_args
        assert 'Duplicate device MAC' in args[0], \
            'Duplicate MAC warning expected'

        mock_warning.reset_mock()
        devices = [
            device_tracker.Device(self.hass, True, True, 'my_device',
                                  'AB:01', 'My device', None, None, False),
            device_tracker.Device(self.hass, True, True, 'my_device',
                                  None, 'Your device', None, None, False)]
        device_tracker.DeviceTracker(self.hass, False, True, {}, devices)

        _LOGGER.debug(mock_warning.call_args_list)
        assert mock_warning.call_count == 1, \
            "The only warning call should be duplicates (check DEBUG)"
        args, _ = mock_warning.call_args
        assert 'Duplicate device IDs' in args[0], \
            'Duplicate device IDs warning expected'
示例#2
0
    def test_see_failures(self, mock_warning):
        """Test that the device tracker see failures."""
        tracker = device_tracker.DeviceTracker(self.hass,
                                               timedelta(seconds=60), 0, {},
                                               [])

        # MAC is not a string (but added)
        tracker.see(mac=567, host_name="Number MAC")

        # No device id or MAC(not added)
        with self.assertRaises(HomeAssistantError):
            run_coroutine_threadsafe(tracker.async_see(),
                                     self.hass.loop).result()
        assert mock_warning.call_count == 0

        # Ignore gps on invalid GPS (both added & warnings)
        tracker.see(mac='mac_1_bad_gps', gps=1)
        tracker.see(mac='mac_2_bad_gps', gps=[1])
        tracker.see(mac='mac_3_bad_gps', gps='gps')
        self.hass.block_till_done()
        config = device_tracker.load_config(self.yaml_devices, self.hass,
                                            timedelta(seconds=0))
        assert mock_warning.call_count == 3

        assert len(config) == 4
示例#3
0
async def test_old_style_track_new_is_skipped(mock_device_tracker_conf, hass):
    """Test old style config is skipped."""
    tracker = device_tracker.DeviceTracker(
        hass, timedelta(seconds=60), None,
        {device_tracker.CONF_TRACK_NEW: False}, [])
    await tracker.async_see(dev_id=14)
    await hass.async_block_till_done()
    assert len(mock_device_tracker_conf) == 1
    assert mock_device_tracker_conf[0].track is False
示例#4
0
async def test_default_hide_if_away_is_used(mock_device_tracker_conf, hass):
    """Test that default track_new is used."""
    tracker = device_tracker.DeviceTracker(
        hass, timedelta(seconds=60), False,
        {device_tracker.CONF_AWAY_HIDE: True}, [])
    await tracker.async_see(dev_id=12)
    await hass.async_block_till_done()
    assert len(mock_device_tracker_conf) == 1
    assert mock_device_tracker_conf[0].away_hide
示例#5
0
async def test_backward_compatibility_for_track_new(mock_device_tracker_conf,
                                                    hass):
    """Test backward compatibility for track new."""
    tracker = device_tracker.DeviceTracker(
        hass, timedelta(seconds=60), False,
        {device_tracker.CONF_TRACK_NEW: True}, [])
    await tracker.async_see(dev_id=13)
    await hass.async_block_till_done()
    assert len(mock_device_tracker_conf) == 1
    assert mock_device_tracker_conf[0].track is False
示例#6
0
async def test_picture_and_icon_on_see_discovery(mock_device_tracker_conf,
                                                 hass):
    """Test that picture and icon are set in initial see."""
    tracker = device_tracker.DeviceTracker(hass, timedelta(seconds=60), False,
                                           {}, [])
    await tracker.async_see(dev_id=11, picture='pic_url', icon='mdi:icon')
    await hass.async_block_till_done()
    assert len(mock_device_tracker_conf) == 1
    assert mock_device_tracker_conf[0].icon == 'mdi:icon'
    assert mock_device_tracker_conf[0].entity_picture == 'pic_url'
示例#7
0
 def test_old_style_track_new_is_skipped(self):
     """Test old style config is skipped."""
     tracker = device_tracker.DeviceTracker(
         self.hass, timedelta(seconds=60), None,
         {device_tracker.CONF_TRACK_NEW: False}, [])
     tracker.see(dev_id=14)
     self.hass.block_till_done()
     config = device_tracker.load_config(self.yaml_devices, self.hass,
                                         timedelta(seconds=0))
     assert len(config) == 1
     self.assertFalse(config[0].track)
示例#8
0
 def test_backward_compatibility_for_track_new(self):
     """Test backward compatibility for track new."""
     tracker = device_tracker.DeviceTracker(
         self.hass, timedelta(seconds=60), False,
         {device_tracker.CONF_TRACK_NEW: True}, [])
     tracker.see(dev_id=13)
     self.hass.block_till_done()
     config = device_tracker.load_config(self.yaml_devices, self.hass,
                                         timedelta(seconds=0))
     assert len(config) == 1
     self.assertFalse(config[0].track)
示例#9
0
 def test_default_hide_if_away_is_used(self):
     """Test that default track_new is used."""
     tracker = device_tracker.DeviceTracker(
         self.hass, timedelta(seconds=60), False,
         {device_tracker.CONF_AWAY_HIDE: True}, [])
     tracker.see(dev_id=12)
     self.hass.block_till_done()
     config = device_tracker.load_config(self.yaml_devices, self.hass,
                                         timedelta(seconds=0))
     assert len(config) == 1
     self.assertTrue(config[0].hidden)
示例#10
0
 def test_picture_and_icon_on_see_discovery(self):
     """Test that picture and icon are set in initial see."""
     tracker = device_tracker.DeviceTracker(
         self.hass, timedelta(seconds=60), False, {}, [])
     tracker.see(dev_id=11, picture='pic_url', icon='mdi:icon')
     self.hass.block_till_done()
     config = device_tracker.load_config(self.yaml_devices, self.hass,
                                         timedelta(seconds=0))
     assert len(config) == 1
     assert config[0].icon == 'mdi:icon'
     assert config[0].entity_picture == 'pic_url'
示例#11
0
    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)
示例#12
0
async def test_see_failures(mock_warning, hass, yaml_devices):
    """Test that the device tracker see failures."""
    tracker = device_tracker.DeviceTracker(hass, timedelta(seconds=60), 0, {},
                                           [])

    # MAC is not a string (but added)
    await tracker.async_see(mac=567, host_name="Number MAC")

    # No device id or MAC(not added)
    with pytest.raises(HomeAssistantError):
        await tracker.async_see()
    assert mock_warning.call_count == 0

    # Ignore gps on invalid GPS (both added & warnings)
    await tracker.async_see(mac='mac_1_bad_gps', gps=1)
    await tracker.async_see(mac='mac_2_bad_gps', gps=[1])
    await tracker.async_see(mac='mac_3_bad_gps', gps='gps')
    await hass.async_block_till_done()
    config = await device_tracker.async_load_config(yaml_devices, hass,
                                                    timedelta(seconds=0))
    assert mock_warning.call_count == 3

    assert len(config) == 4