def setup(hass, config):
    """Set up the Insteon Hub component.

    This will automatically import associated lights.
    """
    from insteonlocal.Hub import Hub

    conf = config[DOMAIN]
    username = conf.get(CONF_USERNAME)
    password = conf.get(CONF_PASSWORD)
    host = conf.get(CONF_HOST)
    port = conf.get(CONF_PORT)
    timeout = conf.get(CONF_TIMEOUT)

    try:
        if not os.path.exists(hass.config.path('.insteon_cache')):
            os.makedirs(hass.config.path('.insteon_cache'))

        insteonhub = Hub(host, username, password, port, timeout, _LOGGER,
                         hass.config.path('.insteon_cache'))

        # Check for successful connection
        insteonhub.get_buffer_status()
    except requests.exceptions.ConnectTimeout:
        _LOGGER.error(
            "Error on insteon_local."
            "Could not connect. Check config",
            exc_info=True)
        return False
    except requests.exceptions.ConnectionError:
        _LOGGER.error(
            "Error on insteon_local. Could not connect."
            "Check config",
            exc_info=True)
        return False
    except requests.exceptions.RequestException:
        if insteonhub.http_code == 401:
            _LOGGER.error("Bad user/pass for insteon_local hub")
            return False
        else:
            _LOGGER.error("Error on insteon_local hub check", exc_info=True)
            return False

    hass.data['insteon_local'] = insteonhub

    return True
Пример #2
0
def setup(hass, config):
    """Set up the local Insteon hub."""
    from insteonlocal.Hub import Hub

    conf = config[DOMAIN]
    username = conf.get(CONF_USERNAME)
    password = conf.get(CONF_PASSWORD)
    host = conf.get(CONF_HOST)
    port = conf.get(CONF_PORT)
    timeout = conf.get(CONF_TIMEOUT)

    try:
        if not os.path.exists(hass.config.path(INSTEON_CACHE)):
            os.makedirs(hass.config.path(INSTEON_CACHE))

        insteonhub = Hub(host, username, password, port, timeout, _LOGGER,
                         hass.config.path(INSTEON_CACHE))

        # Check for successful connection
        insteonhub.get_buffer_status()
    except requests.exceptions.ConnectTimeout:
        _LOGGER.error("Could not connect", exc_info=True)
        return False
    except requests.exceptions.ConnectionError:
        _LOGGER.error("Could not connect", exc_info=True)
        return False
    except requests.exceptions.RequestException:
        if insteonhub.http_code == 401:
            _LOGGER.error("Bad username or password for Insteon_local hub")
        else:
            _LOGGER.error("Error on Insteon_local hub check", exc_info=True)
        return False

    linked = insteonhub.get_linked()

    hass.data['insteon_local'] = insteonhub

    for insteon_platform in INSTEON_PLATFORMS:
        load_platform(hass, insteon_platform, DOMAIN, {'linked': linked},
                      config)

    return True
def setup(hass, config):
    """Set up the Insteon Hub component.

    This will automatically import associated lights.
    """
    from insteonlocal.Hub import Hub

    conf = config[DOMAIN]
    username = conf.get(CONF_USERNAME)
    password = conf.get(CONF_PASSWORD)
    host = conf.get(CONF_HOST)
    port = conf.get(CONF_PORT)
    timeout = conf.get(CONF_TIMEOUT)

    try:
        if not os.path.exists(hass.config.path('.insteon_cache')):
            os.makedirs(hass.config.path('.insteon_cache'))

        insteonhub = Hub(host, username, password, port, timeout, _LOGGER,
                         hass.config.path('.insteon_cache'))

        # Check for successful connection
        insteonhub.get_buffer_status()
    except requests.exceptions.ConnectTimeout:
        _LOGGER.error("Error on insteon_local."
                      "Could not connect. Check config", exc_info=True)
        return False
    except requests.exceptions.ConnectionError:
        _LOGGER.error("Error on insteon_local. Could not connect."
                      "Check config", exc_info=True)
        return False
    except requests.exceptions.RequestException:
        if insteonhub.http_code == 401:
            _LOGGER.error("Bad user/pass for insteon_local hub")
            return False
        else:
            _LOGGER.error("Error on insteon_local hub check", exc_info=True)
            return False

    hass.data['insteon_local'] = insteonhub

    return True
Пример #4
0
def setup(hass, config):
    """Set up the local Insteon hub."""
    from insteonlocal.Hub import Hub

    conf = config[DOMAIN]
    username = conf.get(CONF_USERNAME)
    password = conf.get(CONF_PASSWORD)
    host = conf.get(CONF_HOST)
    port = conf.get(CONF_PORT)
    timeout = conf.get(CONF_TIMEOUT)

    try:
        if not os.path.exists(hass.config.path(INSTEON_CACHE)):
            os.makedirs(hass.config.path(INSTEON_CACHE))

        insteonhub = Hub(host, username, password, port, timeout, _LOGGER,
                         hass.config.path(INSTEON_CACHE))

        # Check for successful connection
        insteonhub.get_buffer_status()
    except requests.exceptions.ConnectTimeout:
        _LOGGER.error("Could not connect", exc_info=True)
        return False
    except requests.exceptions.ConnectionError:
        _LOGGER.error("Could not connect", exc_info=True)
        return False
    except requests.exceptions.RequestException:
        if insteonhub.http_code == 401:
            _LOGGER.error("Bad username or password for Insteon_local hub")
        else:
            _LOGGER.error("Error on Insteon_local hub check", exc_info=True)
        return False

    linked = insteonhub.get_linked()

    hass.data['insteon_local'] = insteonhub

    for insteon_platform in INSTEON_PLATFORMS:
        load_platform(hass, insteon_platform, DOMAIN, {'linked': linked},
                      config)

    return True
#device = device's Insteon ID
# or comment out the import config and manually specify below

try:
    FORMAT = '[%(asctime)s] (%(filename)s:%(lineno)s) %(message)s'
    logging.basicConfig(format=FORMAT,
                        level=logging.DEBUG,
                        filename='insteon.log')
    #logging.basicConfig(format=FORMAT, level=logging.DEBUG)
    logger = logging.getLogger('')

    # create hub object
    hub = Hub(
        config.host,
        config.username,
        config.password,
        '25105',  #port 
        10,  #timeout
        logger)
    buffer = hub.get_buffer_status()
except requests.exceptions.RequestException as e:
    if hub.http_code == 401:
        print("Unauthorized...check user/pass for hub\n")
        sys.exit(1)
    else:
        print(e)
        sys.exit(1)

# set up dimmer
dimmer1 = hub.dimmer(config.device)
Пример #6
0
#host = "hub's ip"
#username = "******"
#password = "******"
# or comment out the import config and manually specify below

try:
    FORMAT = '[%(asctime)s] (%(filename)s:%(lineno)s) %(message)s'
    #logging.basicConfig(format=FORMAT, level=logging.DEBUG, filename='/tmp/insteonlocal.log')
    logging.basicConfig(format=FORMAT, level=logging.DEBUG)
    logger = logging.getLogger('')

    # create hub object
    hub = Hub(
        config.host,
        config.username,
        config.password,
        '25105',  #port 
        10,  #timeout
        logger)
    buffer = hub.get_buffer_status()
except requests.exceptions.RequestException as e:
    if hub.http_code == 401:
        print("Unauthorized...check user/pass for hub\n")
        sys.exit(1)
    else:
        print(e)
        sys.exit(1)

#hub.get_linked()

#insteonLocal.id_request('42902e')
Пример #7
0
 def __init__(self, hostname, username=None, password=None, port='25105'):
     self.hub = hub = Hub(hostname, username, password, port)
     self.devices = self.hub.get_linked()