예제 #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
        device.initiate_metadatastream()
    AXIS_DEVICES[device.serial_number] = device
    return True
예제 #2
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
예제 #3
0
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
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