Ejemplo n.º 1
0
async def async_setup_platform(hass,
                               config,
                               async_add_entities,
                               discovery_info=None):
    """Set up a Synology IP Camera."""
    verify_ssl = config.get(CONF_VERIFY_SSL)
    timeout = config.get(CONF_TIMEOUT)

    try:
        from synology.surveillance_station import SurveillanceStation
        surveillance = SurveillanceStation(config.get(CONF_URL),
                                           config.get(CONF_USERNAME),
                                           config.get(CONF_PASSWORD),
                                           verify_ssl=verify_ssl,
                                           timeout=timeout)
    except (requests.exceptions.RequestException, ValueError):
        _LOGGER.exception("Error when initializing SurveillanceStation")
        return False

    cameras = surveillance.get_all_cameras()

    # add cameras
    devices = []
    for camera in cameras:
        if not config.get(CONF_WHITELIST):
            device = SynologyCamera(surveillance, camera.camera_id, verify_ssl)
            devices.append(device)

    async_add_entities(devices)
Ejemplo n.º 2
0
async def async_setup_platform(hass, config, async_add_entities,
                               discovery_info=None):
    """Set up a Synology IP Camera."""
    verify_ssl = config.get(CONF_VERIFY_SSL)
    timeout = config.get(CONF_TIMEOUT)

    try:
        from synology.surveillance_station import SurveillanceStation
        surveillance = SurveillanceStation(
            config.get(CONF_URL),
            config.get(CONF_USERNAME),
            config.get(CONF_PASSWORD),
            verify_ssl=verify_ssl,
            timeout=timeout
        )
    except (requests.exceptions.RequestException, ValueError):
        _LOGGER.exception("Error when initializing SurveillanceStation")
        return False

    cameras = surveillance.get_all_cameras()

    # add cameras
    devices = []
    for camera in cameras:
        if not config.get(CONF_WHITELIST):
            device = SynologyCamera(surveillance, camera.camera_id, verify_ssl)
            devices.append(device)

    async_add_entities(devices)
Ejemplo n.º 3
0
def setup(hass, config):
    """Set up the Synology Surveillance Station component."""

    # Get values from config
    conf = config[DOMAIN]
    verify_ssl = conf.get(CONF_VERIFY_SSL)
    timeout = conf.get(CONF_TIMEOUT)

    try:
        from synology.surveillance_station import SurveillanceStation

        surveillance = SurveillanceStation(
            conf.get(CONF_URL),
            conf.get(CONF_USERNAME),
            conf.get(CONF_PASSWORD),
            verify_ssl=verify_ssl,
            timeout=timeout,
        )
    except (RequestException, ValueError):
        _LOGGER.exception("Error when initializing SurveillanceStation")
        return False

    hass.states.set(
        'surveillance_station.home_mode',
        "home" if surveillance.get_home_mode_status() is True else "away")

    def handle_set_home_mode(call):
        """Handle the service call."""

        mode = call.data.get('home_mode', 'away').lower()

        # Set the Home Mode
        if surveillance.set_home_mode(True if mode == 'home' else False):
            _LOGGER.info('Successfully set mode to: %s', mode)
        else:
            _LOGGER.error('Failed set mode to: %s', mode)

        hass.states.set('surveillance_station.home_mode', mode)

    hass.services.register(DOMAIN, 'set_home_mode', handle_set_home_mode)

    # Return boolean to indicate that initialization was successful.
    return True