Example #1
0
def setup_device(hass, config):
    """Set up device."""
    from axis import AxisDevice

    config['hass'] = hass
    device = AxisDevice(config)  # Initialize device
    enable_metadatastream = False

    if device.serial_number is None:
        # If there is no serial number a connection could not be made
        _LOGGER.error("Couldn\'t connect to %s", config[CONF_HOST])
        return False

    for component in config[CONF_INCLUDE]:
        if component in EVENT_TYPES:
            # Sensors are created by device calling event_initialized
            # when receiving initialize messages on metadatastream
            device.add_event_topic(convert(component, 'type', 'subscribe'))
            if not enable_metadatastream:
                enable_metadatastream = True
        else:
            discovery.load_platform(hass, component, DOMAIN, config)

    if enable_metadatastream:
        device.initialize_new_event = event_initialized
        if not device.initiate_metadatastream():
            hass.components.persistent_notification.create(
                'Dependency missing for sensors, '
                'please check documentation',
                title=DOMAIN,
                notification_id='axis_notification')

    AXIS_DEVICES[device.serial_number] = device

    return True
Example #2
0
def setup_device(hass, config, device_config):
    """Set up device."""
    from axis import AxisDevice

    def signal_callback(action, event):
        """Callback to configure events when initialized on event stream."""
        if action == 'add':
            event_config = {
                CONF_EVENT: event,
                CONF_NAME: device_config[CONF_NAME],
                ATTR_LOCATION: device_config[ATTR_LOCATION],
                CONF_TRIGGER_TIME: device_config[CONF_TRIGGER_TIME]
            }
            component = event.event_platform
            discovery.load_platform(hass,
                                    component,
                                    DOMAIN,
                                    event_config,
                                    config)

    event_types = list(filter(lambda x: x in device_config[CONF_INCLUDE],
                              EVENT_TYPES))
    device_config['events'] = event_types
    device_config['signal'] = signal_callback
    device = AxisDevice(hass.loop, **device_config)
    device.name = device_config[CONF_NAME]

    if device.serial_number is None:
        # If there is no serial number a connection could not be made
        _LOGGER.error("Couldn\'t connect to %s", device_config[CONF_HOST])
        return False

    for component in device_config[CONF_INCLUDE]:
        if component == 'camera':
            camera_config = {
                CONF_NAME: device_config[CONF_NAME],
                CONF_HOST: device_config[CONF_HOST],
                CONF_PORT: device_config[CONF_PORT],
                CONF_USERNAME: device_config[CONF_USERNAME],
                CONF_PASSWORD: device_config[CONF_PASSWORD]
            }
            discovery.load_platform(hass,
                                    component,
                                    DOMAIN,
                                    camera_config,
                                    config)

    AXIS_DEVICES[device.serial_number] = device
    if event_types:
        hass.add_job(device.start)
    return True
Example #3
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
Example #4
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
Example #5
0
def setup_device(hass, config, device_config):
    """Set up device."""
    from axis import AxisDevice

    def signal_callback(action, event):
        """Callback to configure events when initialized on event stream."""
        if action == 'add':
            event_config = {
                CONF_EVENT: event,
                CONF_NAME: device_config[CONF_NAME],
                ATTR_LOCATION: device_config[ATTR_LOCATION],
                CONF_TRIGGER_TIME: device_config[CONF_TRIGGER_TIME]
            }
            component = event.event_platform
            discovery.load_platform(hass, component, DOMAIN, event_config,
                                    config)

    event_types = list(
        filter(lambda x: x in device_config[CONF_INCLUDE], EVENT_TYPES))
    device_config['events'] = event_types
    device_config['signal'] = signal_callback
    device = AxisDevice(hass.loop, **device_config)
    device.name = device_config[CONF_NAME]

    if device.serial_number is None:
        # If there is no serial number a connection could not be made
        _LOGGER.error("Couldn\'t connect to %s", device_config[CONF_HOST])
        return False

    for component in device_config[CONF_INCLUDE]:
        if component == 'camera':
            camera_config = {
                CONF_NAME: device_config[CONF_NAME],
                CONF_HOST: device_config[CONF_HOST],
                CONF_PORT: device_config[CONF_PORT],
                CONF_USERNAME: device_config[CONF_USERNAME],
                CONF_PASSWORD: device_config[CONF_PASSWORD]
            }
            discovery.load_platform(hass, component, DOMAIN, camera_config,
                                    config)

    AXIS_DEVICES[device.serial_number] = device
    if event_types:
        hass.add_job(device.start)
    return True
Example #6
0
def setup_device(hass, config):
    """Set up device."""
    from axis import AxisDevice

    config['hass'] = hass
    device = AxisDevice(config)  # Initialize device
    enable_metadatastream = False

    if device.serial_number is None:
        # If there is no serial number a connection could not be made
        _LOGGER.error("Couldn\'t connect to %s", config[CONF_HOST])
        return False

    for component in config[CONF_INCLUDE]:
        if component in EVENT_TYPES:
            # Sensors are created by device calling event_initialized
            # when receiving initialize messages on metadatastream
            device.add_event_topic(convert(component, 'type', 'subscribe'))
            if not enable_metadatastream:
                enable_metadatastream = True
        else:
            discovery.load_platform(hass, component, DOMAIN, config)

    if enable_metadatastream:
        device.initialize_new_event = event_initialized
        device.initiate_metadatastream()
    AXIS_DEVICES[device.serial_number] = device
    return True
def setup_device(hass, config, device_config):
    """Set up device."""
    from axis import AxisDevice

    device_config['hass'] = hass
    device = AxisDevice(device_config)  # Initialize device
    enable_metadatastream = False

    if device.serial_number is None:
        # If there is no serial number a connection could not be made
        _LOGGER.error("Couldn\'t connect to %s", device_config[CONF_HOST])
        return False

    for component in device_config[CONF_INCLUDE]:
        if component in EVENT_TYPES:
            # Sensors are created by device calling event_initialized
            # when receiving initialize messages on metadatastream
            device.add_event_topic(convert(component, 'type', 'subscribe'))
            if not enable_metadatastream:
                enable_metadatastream = True
        else:
            camera_config = {
                CONF_HOST: device_config[CONF_HOST],
                CONF_NAME: device_config[CONF_NAME],
                CONF_PORT: device_config[CONF_PORT],
                CONF_USERNAME: device_config[CONF_USERNAME],
                CONF_PASSWORD: device_config[CONF_PASSWORD]
            }
            discovery.load_platform(hass, component, DOMAIN, camera_config,
                                    config)

    if enable_metadatastream:
        device.initialize_new_event = event_initialized
        if not device.initiate_metadatastream():
            hass.components.persistent_notification.create(
                'Dependency missing for sensors, '
                'please check documentation',
                title=DOMAIN,
                notification_id='axis_notification')

    AXIS_DEVICES[device.serial_number] = device

    return True