Esempio n. 1
0
def setup(hass, config):
    """Setup the Netatmo devices."""
    if not validate_config(config,
                           {DOMAIN: [CONF_API_KEY,
                                     CONF_USERNAME,
                                     CONF_PASSWORD,
                                     CONF_SECRET_KEY]},
                           _LOGGER):
        return None

    import lnetatmo

    global NETATMO_AUTH
    try:
        NETATMO_AUTH = lnetatmo.ClientAuth(config[DOMAIN][CONF_API_KEY],
                                           config[DOMAIN][CONF_SECRET_KEY],
                                           config[DOMAIN][CONF_USERNAME],
                                           config[DOMAIN][CONF_PASSWORD],
                                           "read_station read_camera "
                                           "access_camera")
    except HTTPError:
        _LOGGER.error(
            "Connection error "
            "Please check your settings for NatAtmo API.")
        return False

    for component, discovery_service in (
            ('camera', DISCOVER_CAMERAS), ('sensor', DISCOVER_SENSORS)):
        discovery.discover(hass, discovery_service, component=component,
                           hass_config=config)

    return True
Esempio n. 2
0
def setup(hass, config):
    """Set up OctoPrint API."""
    if not validate_config(config, {DOMAIN: [CONF_API_KEY],
                                    DOMAIN: [CONF_HOST]},
                           _LOGGER):
        return False

    base_url = config[DOMAIN][CONF_HOST] + "/api/"
    api_key = config[DOMAIN][CONF_API_KEY]

    global OCTOPRINT
    try:
        OCTOPRINT = OctoPrintAPI(base_url, api_key)
        OCTOPRINT.get("printer")
        OCTOPRINT.get("job")
    except requests.exceptions.RequestException as conn_err:
        _LOGGER.error("Error setting up OctoPrint API: %r", conn_err)
        return False

    for component, discovery_service in (
            ('sensor', DISCOVER_SENSORS),
            ('binary_sensor', DISCOVER_BINARY_SENSORS)):
        discovery.discover(hass, discovery_service, component=component,
                           hass_config=config)

    return True
Esempio n. 3
0
def setup(hass, config):
    """Set up OctoPrint API."""
    if not validate_config(config, {
            DOMAIN: [CONF_API_KEY],
            DOMAIN: [CONF_HOST]
    }, _LOGGER):
        return False

    base_url = config[DOMAIN][CONF_HOST] + "/api/"
    api_key = config[DOMAIN][CONF_API_KEY]

    global OCTOPRINT
    try:
        OCTOPRINT = OctoPrintAPI(base_url, api_key)
        OCTOPRINT.get("printer")
        OCTOPRINT.get("job")
    except requests.exceptions.RequestException as conn_err:
        _LOGGER.error("Error setting up OctoPrint API: %r", conn_err)
        return False

    for component, discovery_service in (('sensor', DISCOVER_SENSORS),
                                         ('binary_sensor',
                                          DISCOVER_BINARY_SENSORS)):
        discovery.discover(hass,
                           discovery_service,
                           component=component,
                           hass_config=config)

    return True
Esempio n. 4
0
def setup(hass, config):
    """Setup the Netatmo devices."""
    if not validate_config(config, {
            DOMAIN:
        [CONF_API_KEY, CONF_USERNAME, CONF_PASSWORD, CONF_SECRET_KEY]
    }, _LOGGER):
        return None

    import lnetatmo

    global NETATMO_AUTH
    try:
        NETATMO_AUTH = lnetatmo.ClientAuth(
            config[DOMAIN][CONF_API_KEY], config[DOMAIN][CONF_SECRET_KEY],
            config[DOMAIN][CONF_USERNAME], config[DOMAIN][CONF_PASSWORD],
            "read_station read_camera "
            "access_camera")
    except HTTPError:
        _LOGGER.error("Connection error "
                      "Please check your settings for NatAtmo API.")
        return False

    for component, discovery_service in (('camera', DISCOVER_CAMERAS),
                                         ('sensor', DISCOVER_SENSORS)):
        discovery.discover(hass,
                           discovery_service,
                           component=component,
                           hass_config=config)

    return True
Esempio n. 5
0
def setup(hass, config):
    """Common setup for WeMo devices."""
    import pywemo

    global SUBSCRIPTION_REGISTRY
    SUBSCRIPTION_REGISTRY = pywemo.SubscriptionRegistry()
    SUBSCRIPTION_REGISTRY.start()

    def stop_wemo(event):
        """Shutdown Wemo subscriptions and subscription thread on exit."""
        _LOGGER.info("Shutting down subscriptions.")
        SUBSCRIPTION_REGISTRY.stop()

    hass.bus.listen_once(EVENT_BLUMATE_STOP, stop_wemo)

    def discovery_dispatch(service, discovery_info):
        """Dispatcher for WeMo discovery events."""
        # name, model, location, mac
        _, model_name, _, _, serial = discovery_info

        # Only register a device once
        if serial in KNOWN_DEVICES:
            return
        _LOGGER.debug('Discovered unique device %s', serial)
        KNOWN_DEVICES.append(serial)

        service = WEMO_MODEL_DISPATCH.get(model_name) or DISCOVER_SWITCHES
        component = WEMO_SERVICE_DISPATCH.get(service)

        discovery.discover(hass, service, discovery_info,
                           component, config)

    discovery.listen(hass, discovery.SERVICE_WEMO, discovery_dispatch)

    _LOGGER.info("Scanning for WeMo devices.")
    devices = [(device.host, device) for device in pywemo.discover_devices()]

    # Add static devices from the config file.
    devices.extend((address, None)
                   for address in config.get(DOMAIN, {}).get('static', []))

    for address, device in devices:
        port = pywemo.ouimeaux_device.probe_wemo(address)
        if not port:
            _LOGGER.warning('Unable to probe wemo at %s', address)
            continue
        _LOGGER.info('Adding wemo at %s:%i', address, port)

        url = 'http://%s:%i/setup.xml' % (address, port)
        if device is None:
            device = pywemo.discovery.device_from_description(url, None)

        discovery_info = (device.name, device.model_name, url, device.mac,
                          device.serialnumber)
        discovery.discover(hass, discovery.SERVICE_WEMO, discovery_info)
    return True
Esempio n. 6
0
def setup(hass, config):
    """Common setup for WeMo devices."""
    import pywemo

    global SUBSCRIPTION_REGISTRY
    SUBSCRIPTION_REGISTRY = pywemo.SubscriptionRegistry()
    SUBSCRIPTION_REGISTRY.start()

    def stop_wemo(event):
        """Shutdown Wemo subscriptions and subscription thread on exit."""
        _LOGGER.info("Shutting down subscriptions.")
        SUBSCRIPTION_REGISTRY.stop()

    hass.bus.listen_once(EVENT_BLUMATE_STOP, stop_wemo)

    def discovery_dispatch(service, discovery_info):
        """Dispatcher for WeMo discovery events."""
        # name, model, location, mac
        _, model_name, _, _, serial = discovery_info

        # Only register a device once
        if serial in KNOWN_DEVICES:
            return
        _LOGGER.debug('Discovered unique device %s', serial)
        KNOWN_DEVICES.append(serial)

        service = WEMO_MODEL_DISPATCH.get(model_name) or DISCOVER_SWITCHES
        component = WEMO_SERVICE_DISPATCH.get(service)

        discovery.discover(hass, service, discovery_info, component, config)

    discovery.listen(hass, discovery.SERVICE_WEMO, discovery_dispatch)

    _LOGGER.info("Scanning for WeMo devices.")
    devices = [(device.host, device) for device in pywemo.discover_devices()]

    # Add static devices from the config file.
    devices.extend((address, None)
                   for address in config.get(DOMAIN, {}).get('static', []))

    for address, device in devices:
        port = pywemo.ouimeaux_device.probe_wemo(address)
        if not port:
            _LOGGER.warning('Unable to probe wemo at %s', address)
            continue
        _LOGGER.info('Adding wemo at %s:%i', address, port)

        url = 'http://%s:%i/setup.xml' % (address, port)
        if device is None:
            device = pywemo.discovery.device_from_description(url, None)

        discovery_info = (device.name, device.model_name, url, device.mac,
                          device.serialnumber)
        discovery.discover(hass, discovery.SERVICE_WEMO, discovery_info)
    return True
Esempio n. 7
0
    def discovery_dispatch(service, discovery_info):
        """Dispatcher for WeMo discovery events."""
        # name, model, location, mac
        _, model_name, _, _, serial = discovery_info

        # Only register a device once
        if serial in KNOWN_DEVICES:
            return
        _LOGGER.debug('Discovered unique device %s', serial)
        KNOWN_DEVICES.append(serial)

        service = WEMO_MODEL_DISPATCH.get(model_name) or DISCOVER_SWITCHES
        component = WEMO_SERVICE_DISPATCH.get(service)

        discovery.discover(hass, service, discovery_info, component, config)
Esempio n. 8
0
    def discovery_dispatch(service, discovery_info):
        """Dispatcher for WeMo discovery events."""
        # name, model, location, mac
        _, model_name, _, _, serial = discovery_info

        # Only register a device once
        if serial in KNOWN_DEVICES:
            return
        _LOGGER.debug('Discovered unique device %s', serial)
        KNOWN_DEVICES.append(serial)

        service = WEMO_MODEL_DISPATCH.get(model_name) or DISCOVER_SWITCHES
        component = WEMO_SERVICE_DISPATCH.get(service)

        discovery.discover(hass, service, discovery_info,
                           component, config)
Esempio n. 9
0
def setup(hass, config):
    """Setup BloomSky component."""
    if not validate_config(config, {DOMAIN: [CONF_API_KEY]}, _LOGGER):
        return False

    api_key = config[DOMAIN][CONF_API_KEY]

    global BLOOMSKY
    try:
        BLOOMSKY = BloomSky(api_key)
    except RuntimeError:
        return False

    for component, discovery_service in (('camera', DISCOVER_CAMERAS),
                                         ('sensor', DISCOVER_SENSORS),
                                         ('binary_sensor',
                                          DISCOVER_BINARY_SENSORS)):
        discovery.discover(hass,
                           discovery_service,
                           component=component,
                           hass_config=config)

    return True
Esempio n. 10
0
def setup(hass, config):
    """Setup BloomSky component."""
    if not validate_config(
            config,
            {DOMAIN: [CONF_API_KEY]},
            _LOGGER):
        return False

    api_key = config[DOMAIN][CONF_API_KEY]

    global BLOOMSKY
    try:
        BLOOMSKY = BloomSky(api_key)
    except RuntimeError:
        return False

    for component, discovery_service in (
            ('camera', DISCOVER_CAMERAS), ('sensor', DISCOVER_SENSORS),
            ('binary_sensor', DISCOVER_BINARY_SENSORS)):
        discovery.discover(hass, discovery_service, component=component,
                           hass_config=config)

    return True