Пример #1
0
async def setup_device(hass):
    """Load the Axis binary sensor platform."""
    from axis import AxisDevice

    loop = Mock()

    config_entry = config_entries.ConfigEntry(
        1,
        axis.DOMAIN,
        "Mock Title",
        ENTRY_CONFIG,
        "test",
        config_entries.CONN_CLASS_LOCAL_PUSH,
        system_options={},
        options=ENTRY_OPTIONS,
    )
    device = axis.AxisNetworkDevice(hass, config_entry)
    device.api = AxisDevice(loop=loop, **config_entry.data[axis.CONF_DEVICE])
    hass.data[axis.DOMAIN] = {device.serial: device}
    device.api.enable_events(event_callback=device.async_event_callback)

    await hass.config_entries.async_forward_entry_setup(config_entry, "camera")
    # To flush out the service call to update the group
    await hass.async_block_till_done()

    return device
Пример #2
0
async def setup_device(hass):
    """Load the Axis binary sensor platform."""
    from axis import AxisDevice
    loop = Mock()

    config_entry = config_entries.ConfigEntry(
        1,
        axis.DOMAIN,
        'Mock Title',
        ENTRY_CONFIG,
        'test',
        config_entries.CONN_CLASS_LOCAL_PUSH,
        options=ENTRY_OPTIONS)
    device = axis.AxisNetworkDevice(hass, config_entry)
    device.api = AxisDevice(loop=loop,
                            **config_entry.data[axis.CONF_DEVICE],
                            signal=device.async_signal_callback)
    hass.data[axis.DOMAIN] = {device.serial: device}

    await hass.config_entries.async_forward_entry_setup(
        config_entry, 'binary_sensor')
    # To flush out the service call to update the group
    await hass.async_block_till_done()

    return device
Пример #3
0
async def test_unload_entry(hass):
    """Test successful unload of entry."""
    entry = MockConfigEntry(domain=axis.DOMAIN, data={axis.device.CONF_MAC: "0123"})

    mock_device = axis.AxisNetworkDevice(hass, entry)
    mock_device.async_setup = Mock(return_value=mock_coro(True))
    mock_device.async_update_device_registry = Mock(return_value=mock_coro(True))
    mock_device.async_reset = Mock(return_value=mock_coro(True))

    with patch.object(axis, "AxisNetworkDevice") as mock_device_class, patch.object(
        axis, "async_populate_options", return_value=mock_coro(True)
    ):
        mock_device_class.return_value = mock_device

        assert await axis.async_setup_entry(hass, entry)

    assert await axis.async_unload_entry(hass, entry)
    assert not hass.data[axis.DOMAIN]
Пример #4
0
async def test_setup_entry(hass):
    """Test successful setup of entry."""
    entry = MockConfigEntry(domain=axis.DOMAIN,
                            data={axis.device.CONF_MAC: '0123'})

    mock_device = axis.AxisNetworkDevice(hass, entry)
    mock_device.async_setup = Mock(return_value=mock_coro(True))
    mock_device.async_update_device_registry = \
        Mock(return_value=mock_coro(True))
    mock_device.async_reset = Mock(return_value=mock_coro(True))

    with patch.object(axis, 'AxisNetworkDevice') as mock_device_class, \
            patch.object(
                axis, 'async_populate_options', return_value=mock_coro(True)):
        mock_device_class.return_value = mock_device

        assert await axis.async_setup_entry(hass, entry)

    assert len(hass.data[axis.DOMAIN]) == 1
    assert '0123' in hass.data[axis.DOMAIN]