Example #1
0
async def get_device(hass, host, port, username, password):
    """Create a Axis device."""
    session = get_async_client(hass, verify_ssl=False)

    device = axis.AxisDevice(
        Configuration(session,
                      host,
                      port=port,
                      username=username,
                      password=password))

    try:
        async with async_timeout.timeout(30):
            await device.vapix.initialize()

        return device

    except axis.Unauthorized as err:
        LOGGER.warning("Connected to device at %s but not registered", host)
        raise AuthenticationRequired from err

    except (asyncio.TimeoutError, axis.RequestError) as err:
        LOGGER.error("Error connecting to the Axis device at %s", host)
        raise CannotConnect from err

    except axis.AxisException as err:
        LOGGER.exception("Unknown Axis communication error occurred")
        raise AuthenticationRequired from err
Example #2
0
async def get_axis_device(
    hass: HomeAssistant,
    config: MappingProxyType[str, Any],
) -> axis.AxisDevice:
    """Create a Axis device."""
    session = get_async_client(hass, verify_ssl=False)

    device = axis.AxisDevice(
        Configuration(
            session,
            config[CONF_HOST],
            port=config[CONF_PORT],
            username=config[CONF_USERNAME],
            password=config[CONF_PASSWORD],
        ))

    try:
        async with async_timeout.timeout(30):
            await device.vapix.initialize()

        return device

    except axis.Unauthorized as err:
        LOGGER.warning("Connected to device at %s but not registered",
                       config[CONF_HOST])
        raise AuthenticationRequired from err

    except (asyncio.TimeoutError, axis.RequestError) as err:
        LOGGER.error("Error connecting to the Axis device at %s",
                     config[CONF_HOST])
        raise CannotConnect from err

    except axis.AxisException as err:
        LOGGER.exception("Unknown Axis communication error occurred")
        raise AuthenticationRequired from err
Example #3
0
async def axis_device(loop) -> AxisDevice:
    """Returns the axis device.

    Clean up sessions automatically at the end of each test.
    """
    session = AsyncClient(verify=False)
    axis_device = AxisDevice(
        Configuration(session, HOST, username=USER, password=PASS))
    yield axis_device
    await session.aclose()
Example #4
0
def test_device():
    """"""
    axis_device = AxisDevice(
        Configuration("host", port=80, username="******", password="******")
    )

    assert axis_device.config
    assert axis_device.vapix
    assert axis_device.stream
    assert axis_device.event is None

    mock_callback = Mock()
    axis_device.enable_events(mock_callback)
    assert axis_device.event
    assert axis_device.event.signal == mock_callback
Example #5
0
def test_minimal_configuration():
    """Test Configuration works."""
    session = AsyncClient(verify=False)
    config = Configuration(
        session,
        "192.168.1.1",
        username="******",
        password="******",
    )

    assert config.host == "192.168.1.1"
    assert config.username == "bill"
    assert config.password == "cipher"
    assert config.port == 80
    assert config.web_proto == "http"
    assert config.verify_ssl is False
    assert config.url == "http://192.168.1.1:80"
Example #6
0
def test_configuration():
    """Test Configuration works."""
    config = Configuration(
        "192.168.0.1",
        username="******",
        password="******",
        port=443,
        web_proto="https",
        verify_ssl=True,
    )

    assert config.host == "192.168.0.1"
    assert config.username == "root"
    assert config.password == "pass"
    assert config.port == 443
    assert config.web_proto == "https"
    assert config.verify_ssl is True
    assert config.url == "https://192.168.0.1:443"
Example #7
0
async def get_device(hass, host, port, username, password):
    """Create a Axis device."""

    device = axis.AxisDevice(
        Configuration(host, port=port, username=username, password=password))

    try:
        with async_timeout.timeout(15):
            await hass.async_add_executor_job(device.vapix.initialize)

        return device

    except axis.Unauthorized as err:
        LOGGER.warning("Connected to device at %s but not registered.", host)
        raise AuthenticationRequired from err

    except (asyncio.TimeoutError, axis.RequestError) as err:
        LOGGER.error("Error connecting to the Axis device at %s", host)
        raise CannotConnect from err

    except axis.AxisException as err:
        LOGGER.exception("Unknown Axis communication error occurred")
        raise AuthenticationRequired from err