Beispiel #1
0
async def test_duplicate_mac_dev_id(mock_warning, opp):
    """Test adding duplicate MACs or device IDs to DeviceTracker."""
    devices = [
        legacy.Device(opp, True, True, "my_device", "AB:01", "My device", None,
                      None, False),
        legacy.Device(opp, True, True, "your_device", "AB:01", "Your device",
                      None, None, False),
    ]
    legacy.DeviceTracker(opp, 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 = [
        legacy.Device(opp, True, True, "my_device", "AB:01", "My device", None,
                      None, False),
        legacy.Device(opp, True, True, "my_device", None, "Your device", None,
                      None, False),
    ]
    legacy.DeviceTracker(opp, 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"
Beispiel #2
0
async def test_old_style_track_new_is_skipped(mock_device_tracker_conf, opp):
    """Test old style config is skipped."""
    tracker = legacy.DeviceTracker(opp, timedelta(seconds=60), None,
                                   {device_tracker.CONF_TRACK_NEW: False}, [])
    await tracker.async_see(dev_id=14)
    await opp.async_block_till_done()
    assert len(mock_device_tracker_conf) == 1
    assert mock_device_tracker_conf[0].track is False
Beispiel #3
0
async def test_default_hide_if_away_is_used(mock_device_tracker_conf, opp):
    """Test that default track_new is used."""
    tracker = legacy.DeviceTracker(opp, timedelta(seconds=60), False,
                                   {device_tracker.CONF_AWAY_HIDE: True}, [])
    await tracker.async_see(dev_id=12)
    await opp.async_block_till_done()
    assert len(mock_device_tracker_conf) == 1
    assert mock_device_tracker_conf[0].away_hide
Beispiel #4
0
async def test_backward_compatibility_for_track_new(mock_device_tracker_conf,
                                                    opp):
    """Test backward compatibility for track new."""
    tracker = legacy.DeviceTracker(opp, timedelta(seconds=60), False,
                                   {device_tracker.CONF_TRACK_NEW: True}, [])
    await tracker.async_see(dev_id=13)
    await opp.async_block_till_done()
    assert len(mock_device_tracker_conf) == 1
    assert mock_device_tracker_conf[0].track is False
Beispiel #5
0
async def test_picture_and_icon_on_see_discovery(mock_device_tracker_conf,
                                                 opp):
    """Test that picture and icon are set in initial see."""
    tracker = legacy.DeviceTracker(opp, timedelta(seconds=60), False, {}, [])
    await tracker.async_see(dev_id=11, picture="pic_url", icon="mdi:icon")
    await opp.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"
Beispiel #6
0
async def test_see_failures(mock_warning, opp, mock_device_tracker_conf):
    """Test that the device tracker see failures."""
    devices = mock_device_tracker_conf
    tracker = legacy.DeviceTracker(opp, 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(OpenPeerPowerError):
        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 opp.async_block_till_done()

    assert mock_warning.call_count == 3
    assert len(devices) == 4