Ejemplo n.º 1
0
def setup(hass, config):
    """Setup Ecobee.

    Will automatically load thermostat and sensor components to support
    devices discovered on the network.
    """
    # pylint: disable=global-statement, import-error
    global NETWORK

    if 'ecobee' in _CONFIGURING:
        return

    from pyecobee import config_from_file

    # Create ecobee.conf if it doesn't exist
    if not os.path.isfile(hass.config.path(ECOBEE_CONFIG_FILE)):
        if config[DOMAIN].get(CONF_API_KEY) is None:
            _LOGGER.error("No ecobee api_key found in config.")
            return
        jsonconfig = {"API_KEY": config[DOMAIN].get(CONF_API_KEY)}
        config_from_file(hass.config.path(ECOBEE_CONFIG_FILE), jsonconfig)

    NETWORK = EcobeeData(hass.config.path(ECOBEE_CONFIG_FILE))

    setup_ecobee(hass, NETWORK.ecobee, config)

    return True
Ejemplo n.º 2
0
def setup(hass, config):
    """Setup Ecobee.

    Will automatically load thermostat and sensor components to support
    devices discovered on the network.
    """
    # pylint: disable=global-statement, import-error
    global NETWORK

    if 'ecobee' in _CONFIGURING:
        return

    from pyecobee import config_from_file

    # Create ecobee.conf if it doesn't exist
    if not os.path.isfile(hass.config.path(ECOBEE_CONFIG_FILE)):
        if config[DOMAIN].get(CONF_API_KEY) is None:
            _LOGGER.error("No ecobee api_key found in config.")
            return
        jsonconfig = {"API_KEY": config[DOMAIN].get(CONF_API_KEY)}
        config_from_file(hass.config.path(ECOBEE_CONFIG_FILE), jsonconfig)

    NETWORK = EcobeeData(hass.config.path(ECOBEE_CONFIG_FILE))

    setup_ecobee(hass, NETWORK.ecobee, config)

    return True
Ejemplo n.º 3
0
def connect_app_and_account(optiondict):
    # first create logging for what we are donig
    logger.info("Connecting application to account")
    logger.info("Have user get prepared by logging into the consumerportal")

    # STEP1 - check to see if the configuration file exists that the user passed in
    if optiondict['config_filename']:
        config_filename = optiondict['config_filename']
        if not os.path.isfile(config_filename):
            logger.info(
                'Config_filename specified but does not exist, creating it')
            jsonconfig = {"API_KEY": optiondict['api_key']}
            pyecobee.config_from_file(config_filename, jsonconfig)

    # STEP2 - display message to the user
    print("Connecting this application to an account")
    print(
        "Please login to the account that we will be connecting to by going to:"
    )
    print("https://www.ecobee.com/consumerportal/index.html")

    # get the input when the user is ready for us to move on
    name = input("\nPress [Enter] when this is done ==> ")

    # logging
    logger.info("Consumer has the portal ready to go")

    # STEP3 - create the ecobee object with no configuration file - we are starting new here
    logger.info("Building ecobee object")
    ecobee = pyecobee.Ecobee(api_key=optiondict['api_key'],
                             config_filename=optiondict['config_filename'])

    # STEP4 - should have failed, but if it did not - then no work to do - exit
    if ecobee.authenticated:
        # logging
        logger.info(
            "App already connected to account - no additional action required - terminating program"
        )
        print(
            "App already connected to account - no additional action required - terminating program"
        )
        sys.exit(1)

    # STEP 4 - did not fail - we need to request a pin
    logger.info('App is now requesting a pin be generated')
    print('App requesting a pin')
    ecobee.request_pin()
    logger.info('Delivered pin:' + ecobee.pin)
    if not ecobee.pin:
        logger.info('A pin was not created - failing')
        print('A pin was not generated - there is a problem - EXITTING')
        sys.exit(1)

    # logging
    logger.info(
        "Request user to enter PIN into consumer portal My Apps, Add application"
    )

    # STEP5 - we have the PIN code that the user needs to authenticate - have them go do it.
    print("Go to the consumerportal web page and click")
    print('My Apps, Add application, and when prompted enter PIN: [',
          ecobee.pin, '] and click Authorize.')
    print('Once authorized, click Add application')

    # get the input when the user is ready for us to move on
    name = input("\nPress [Enter] when this is done ==> ")

    # logging
    logger.info(
        "User entered PIN [ %s ] - application will now call request_tokens",
        ecobee.pin)

    # STEP6 - call the request_tokens
    if ecobee.request_tokens():
        print('Request_tokens delivered true and autenticated is:',
              ecobee.authenticated)

    # STEP7 - validate we got what we wanted
    if ecobee.pin is not None:
        logger.error(
            "Request_tokens call did not work - you are still not connected - please try again"
        )
        print(
            "Request_tokens call did not work - you are still not connected - please try again"
        )
        sys.exit(1)
    else:
        logger.info(
            'Request_tokens now has the thermostat connected and a configuration file generated for future runs'
        )
        print(
            'Request_tokens now has the thermostat connected and a configuration file generated for future runs'
        )

    # STEP8 - make sure this delivers a working solution - get thermostats
    logger.info('Validating we can authenticate')
    ecobee.get_thermostats()
    print('We should be authenticated:', ecobee.authenticated)
    if not ecobee.authenticated:
        logger.info('failed to authenticate')
    else:
        logger.info('All worked as expected - we are authenticated')
    sys.exit()