예제 #1
0
async def test_duplicate_mac_dev_id(mock_warning, hass):
    """Test adding duplicate MACs or device IDs to DeviceTracker."""
    devices = [
        legacy.Device(hass, True, True, 'my_device', 'AB:01', 'My device',
                      None, None, False),
        legacy.Device(hass, True, True, 'your_device', 'AB:01', 'Your device',
                      None, None, False)
    ]
    legacy.DeviceTracker(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 = [
        legacy.Device(hass, True, True, 'my_device', 'AB:01', 'My device',
                      None, None, False),
        legacy.Device(hass, True, True, 'my_device', None, 'Your device', None,
                      None, False)
    ]
    legacy.DeviceTracker(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
파일: test_init.py 프로젝트: Twtcer/core-1
async def test_duplicate_mac_dev_id(mock_warning, hass):
    """Test adding duplicate MACs or device IDs to DeviceTracker."""
    devices = [
        legacy.Device(hass, True, True, "my_device", "AB:01", "My device",
                      None, None, False),
        legacy.Device(hass, True, True, "your_device", "AB:01", "Your device",
                      None, None, False),
    ]
    legacy.DeviceTracker(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 = [
        legacy.Device(hass, True, True, "my_device", "AB:01", "My device",
                      None, None, False),
        legacy.Device(hass, True, True, "my_device", None, "Your device", None,
                      None, False),
    ]
    legacy.DeviceTracker(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"
예제 #3
0
async def test_reading_yaml_config(hass, yaml_devices):
    """Test the rendering of the YAML configuration."""
    dev_id = 'test'
    device = legacy.Device(hass,
                           timedelta(seconds=180),
                           True,
                           dev_id,
                           'AB:CD:EF:GH:IJ',
                           'Test name',
                           picture='http://test.picture',
                           hide_if_away=True,
                           icon='mdi:kettle')
    await hass.async_add_executor_job(legacy.update_config, yaml_devices,
                                      dev_id, device)
    assert await async_setup_component(hass, device_tracker.DOMAIN,
                                       TEST_PLATFORM)
    config = (await legacy.async_load_config(yaml_devices, hass,
                                             device.consider_home))[0]
    assert device.dev_id == config.dev_id
    assert device.track == config.track
    assert device.mac == config.mac
    assert device.config_picture == config.config_picture
    assert device.away_hide == config.away_hide
    assert device.consider_home == config.consider_home
    assert device.icon == config.icon
예제 #4
0
async def test_entity_attributes(hass, mock_device_tracker_conf):
    """Test the entity attributes."""
    devices = mock_device_tracker_conf
    dev_id = 'test_entity'
    entity_id = const.ENTITY_ID_FORMAT.format(dev_id)
    friendly_name = 'Paulus'
    picture = 'http://placehold.it/200x200'
    icon = 'mdi:kettle'

    device = legacy.Device(hass,
                           timedelta(seconds=180),
                           True,
                           dev_id,
                           None,
                           friendly_name,
                           picture,
                           hide_if_away=True,
                           icon=icon)
    devices.append(device)

    with assert_setup_component(1, device_tracker.DOMAIN):
        assert await async_setup_component(hass, device_tracker.DOMAIN,
                                           TEST_PLATFORM)

    attrs = hass.states.get(entity_id).attributes

    assert friendly_name == attrs.get(ATTR_FRIENDLY_NAME)
    assert icon == attrs.get(ATTR_ICON)
    assert picture == attrs.get(ATTR_ENTITY_PICTURE)
예제 #5
0
파일: test_init.py 프로젝트: Twtcer/core-1
async def test_entity_attributes(hass, mock_device_tracker_conf):
    """Test the entity attributes."""
    devices = mock_device_tracker_conf
    dev_id = "test_entity"
    entity_id = f"{const.DOMAIN}.{dev_id}"
    friendly_name = "Paulus"
    picture = "http://placehold.it/200x200"
    icon = "mdi:kettle"

    device = legacy.Device(
        hass,
        timedelta(seconds=180),
        True,
        dev_id,
        None,
        friendly_name,
        picture,
        icon=icon,
    )
    devices.append(device)

    with assert_setup_component(1, device_tracker.DOMAIN):
        assert await async_setup_component(hass, device_tracker.DOMAIN,
                                           TEST_PLATFORM)

    attrs = hass.states.get(entity_id).attributes

    assert friendly_name == attrs.get(ATTR_FRIENDLY_NAME)
    assert icon == attrs.get(ATTR_ICON)
    assert picture == attrs.get(ATTR_ENTITY_PICTURE)
예제 #6
0
async def test_reading_yaml_config(hass, yaml_devices):
    """Test the rendering of the YAML configuration."""
    dev_id = "test"
    device = legacy.Device(
        hass,
        timedelta(seconds=180),
        True,
        dev_id,
        "AB:CD:EF:GH:IJ",
        "Test name",
        picture="http://test.picture",
        icon="mdi:kettle",
    )
    await hass.async_add_executor_job(
        legacy.update_config, yaml_devices, dev_id, device
    )
    assert await async_setup_component(hass, device_tracker.DOMAIN, TEST_PLATFORM)
    config = (await legacy.async_load_config(yaml_devices, hass, device.consider_home))[
        0
    ]
    assert device.dev_id == config.dev_id
    assert device.track == config.track
    assert device.mac == config.mac
    assert device.config_picture == config.config_picture
    assert device.consider_home == config.consider_home
    assert device.icon == config.icon
    assert f"{device_tracker.DOMAIN}.test" in hass.config.components
예제 #7
0
async def test_gravatar(hass):
    """Test the Gravatar generation."""
    dev_id = 'test'
    device = legacy.Device(
        hass, timedelta(seconds=180), True, dev_id,
        'AB:CD:EF:GH:IJ', 'Test name', gravatar='*****@*****.**')
    gravatar_url = ("https://www.gravatar.com/avatar/"
                    "55502f40dc8b7c769880b10874abc9d0.jpg?s=80&d=wavatar")
    assert device.config_picture == gravatar_url
예제 #8
0
파일: test_init.py 프로젝트: Twtcer/core-1
async def test_gravatar_and_picture(hass):
    """Test that Gravatar overrides picture."""
    dev_id = "test"
    device = legacy.Device(
        hass,
        timedelta(seconds=180),
        True,
        dev_id,
        "AB:CD:EF:GH:IJ",
        "Test name",
        picture="http://test.picture",
        gravatar="*****@*****.**",
    )
    gravatar_url = ("https://www.gravatar.com/avatar/"
                    "55502f40dc8b7c769880b10874abc9d0.jpg?s=80&d=wavatar")
    assert device.config_picture == gravatar_url
예제 #9
0
async def test_device_hidden(hass, mock_device_tracker_conf):
    """Test hidden devices."""
    devices = mock_device_tracker_conf
    dev_id = 'test_entity'
    entity_id = const.ENTITY_ID_FORMAT.format(dev_id)
    device = legacy.Device(
        hass, timedelta(seconds=180), True, dev_id, None,
        hide_if_away=True)
    devices.append(device)

    scanner = getattr(hass.components, 'test.device_tracker').SCANNER
    scanner.reset()

    with assert_setup_component(1, device_tracker.DOMAIN):
        assert await async_setup_component(hass, device_tracker.DOMAIN,
                                           TEST_PLATFORM)

    assert hass.states.get(entity_id).attributes.get(ATTR_HIDDEN)
예제 #10
0
async def test_group_all_devices(hass, mock_device_tracker_conf):
    """Test grouping of devices."""
    devices = mock_device_tracker_conf
    dev_id = 'test_entity'
    entity_id = const.ENTITY_ID_FORMAT.format(dev_id)
    device = legacy.Device(
        hass, timedelta(seconds=180), True, dev_id, None,
        hide_if_away=True)
    devices.append(device)
    scanner = getattr(hass.components, 'test.device_tracker').SCANNER
    scanner.reset()

    with assert_setup_component(1, device_tracker.DOMAIN):
        assert await async_setup_component(hass, device_tracker.DOMAIN,
                                           TEST_PLATFORM)
        await hass.async_block_till_done()

    state = hass.states.get(device_tracker.ENTITY_ID_ALL_DEVICES)
    assert state is not None
    assert STATE_NOT_HOME == state.state
    assert (entity_id,) == state.attributes.get(ATTR_ENTITY_ID)