コード例 #1
0
ファイル: __init__.py プロジェクト: Martwall/home-assistant
def setup(hass, config):
    """Set up the ZoneMinder component."""
    from zoneminder.zm import ZoneMinder

    hass.data[DOMAIN] = {}

    success = True

    for conf in config[DOMAIN]:
        if conf[CONF_SSL]:
            schema = 'https'
        else:
            schema = 'http'

        host_name = conf[CONF_HOST]
        server_origin = '{}://{}'.format(schema, host_name)
        zm_client = ZoneMinder(
            server_origin,
            conf.get(CONF_USERNAME),
            conf.get(CONF_PASSWORD),
            conf.get(CONF_PATH),
            conf.get(CONF_PATH_ZMS),
            conf.get(CONF_VERIFY_SSL)
        )
        hass.data[DOMAIN][host_name] = zm_client

        success = zm_client.login() and success

    def set_active_state(call):
        """Set the ZoneMinder run state to the given state name."""
        zm_id = call.data[ATTR_ID]
        state_name = call.data[ATTR_NAME]
        if zm_id not in hass.data[DOMAIN]:
            _LOGGER.error('Invalid ZoneMinder host provided: %s', zm_id)
        if not hass.data[DOMAIN][zm_id].set_active_state(state_name):
            _LOGGER.error(
                'Unable to change ZoneMinder state. Host: %s, state: %s',
                zm_id,
                state_name
            )

    hass.services.register(
        DOMAIN, SERVICE_SET_RUN_STATE, set_active_state,
        schema=SET_RUN_STATE_SCHEMA
    )

    hass.async_create_task(
        async_load_platform(hass, 'binary_sensor', DOMAIN, {}, config)
    )

    return success
コード例 #2
0
def setup(hass, config):
    """Set up the ZoneMinder component."""
    from zoneminder.zm import ZoneMinder

    hass.data[DOMAIN] = {}

    success = True

    for conf in config[DOMAIN]:
        if conf[CONF_SSL]:
            schema = 'https'
        else:
            schema = 'http'

        host_name = conf[CONF_HOST]
        server_origin = '{}://{}'.format(schema, host_name)
        zm_client = ZoneMinder(
            server_origin,
            conf.get(CONF_USERNAME),
            conf.get(CONF_PASSWORD),
            conf.get(CONF_PATH),
            conf.get(CONF_PATH_ZMS),
            conf.get(CONF_VERIFY_SSL)
        )
        hass.data[DOMAIN][host_name] = zm_client

        success = zm_client.login() and success

    def set_active_state(call):
        """Set the ZoneMinder run state to the given state name."""
        zm_id = call.data[ATTR_ID]
        state_name = call.data[ATTR_NAME]
        if zm_id not in hass.data[DOMAIN]:
            _LOGGER.error('Invalid ZoneMinder host provided: %s', zm_id)
        if not hass.data[DOMAIN][zm_id].set_active_state(state_name):
            _LOGGER.error(
                'Unable to change ZoneMinder state. Host: %s, state: %s',
                zm_id,
                state_name
            )

    hass.services.register(
        DOMAIN, SERVICE_SET_RUN_STATE, set_active_state,
        schema=SET_RUN_STATE_SCHEMA
    )

    hass.async_create_task(
        async_load_platform(hass, 'binary_sensor', DOMAIN, {}, config)
    )

    return success
コード例 #3
0
ファイル: __init__.py プロジェクト: MoshonkaKita/Golovastik
def setup(hass, config):
    """Set up the ZoneMinder component."""
    from zoneminder.zm import ZoneMinder

    conf = config[DOMAIN]
    if conf[CONF_SSL]:
        schema = 'https'
    else:
        schema = 'http'

    server_origin = '{}://{}'.format(schema, conf[CONF_HOST])
    hass.data[DOMAIN] = ZoneMinder(server_origin,
                                   conf.get(CONF_USERNAME),
                                   conf.get(CONF_PASSWORD),
                                   conf.get(CONF_PATH),
                                   conf.get(CONF_PATH_ZMS),
                                   conf.get(CONF_VERIFY_SSL))

    def set_active_state(call):
        """Set the ZoneMinder run state to the given state name."""
        return hass.data[DOMAIN].set_active_state(call.data[ATTR_NAME])

    hass.services.register(
        DOMAIN, SERVICE_SET_RUN_STATE, set_active_state,
        schema=SET_RUN_STATE_SCHEMA
    )

    return hass.data[DOMAIN].login()
コード例 #4
0
def setup(hass, config):
    """Set up the ZoneMinder component."""

    hass.data[DOMAIN] = {}

    success = True

    for conf in config[DOMAIN]:
        protocol = "https" if conf[CONF_SSL] else "http"

        host_name = conf[CONF_HOST]
        server_origin = f"{protocol}://{host_name}"
        zm_client = ZoneMinder(
            server_origin,
            conf.get(CONF_USERNAME),
            conf.get(CONF_PASSWORD),
            conf.get(CONF_PATH),
            conf.get(CONF_PATH_ZMS),
            conf.get(CONF_VERIFY_SSL),
        )
        hass.data[DOMAIN][host_name] = zm_client

        success = zm_client.login() and success

    def set_active_state(call):
        """Set the ZoneMinder run state to the given state name."""
        zm_id = call.data[ATTR_ID]
        state_name = call.data[ATTR_NAME]
        if zm_id not in hass.data[DOMAIN]:
            _LOGGER.error("Invalid ZoneMinder host provided: %s", zm_id)
        if not hass.data[DOMAIN][zm_id].set_active_state(state_name):
            _LOGGER.error(
                "Unable to change ZoneMinder state. Host: %s, state: %s",
                zm_id,
                state_name,
            )

    hass.services.register(DOMAIN,
                           SERVICE_SET_RUN_STATE,
                           set_active_state,
                           schema=SET_RUN_STATE_SCHEMA)

    hass.async_create_task(
        async_load_platform(hass, "binary_sensor", DOMAIN, {}, config))

    return success
def setup(hass, config):
    """Set up the ZoneMinder component."""
    from zoneminder.zm import ZoneMinder

    conf = config[DOMAIN]
    if conf[CONF_SSL]:
        schema = 'https'
    else:
        schema = 'http'

    server_origin = '{}://{}'.format(schema, conf[CONF_HOST])
    hass.data[DOMAIN] = ZoneMinder(server_origin, conf.get(CONF_USERNAME),
                                   conf.get(CONF_PASSWORD),
                                   conf.get(CONF_PATH),
                                   conf.get(CONF_PATH_ZMS),
                                   conf.get(CONF_VERIFY_SSL))

    return hass.data[DOMAIN].login()