def __init__(self):
     self.api = Api(timeout=20)
     self.authenticator = Authenticator(
         self.api,
         "phone|email",
         "YourPhoneNumber",
         "YourPassword",
         access_token_cache_file="access_token_cache_file.txt")
     self.id = 'EBE57CE9D7624D78A5A0BE44340E0DFE'
     self.authentication = self.authenticator.authenticate()
     self.access_token = self.authentication.access_token
예제 #2
0
def setup(hass, config):
    """Set up the August component."""
    from august.api import Api
    from august.authenticator import Authenticator

    conf = config[DOMAIN]
    api = Api(timeout=conf.get(CONF_TIMEOUT))

    authenticator = Authenticator(
        api,
        conf.get(CONF_LOGIN_METHOD),
        conf.get(CONF_USERNAME),
        conf.get(CONF_PASSWORD),
        install_id=conf.get(CONF_INSTALL_ID),
        access_token_cache_file=hass.config.path(AUGUST_CONFIG_FILE))

    return setup_august(hass, config, api, authenticator)
class SmartLock:
    def __init__(self):
        self.api = Api(timeout=20)
        self.authenticator = Authenticator(
            self.api,
            "phone|email",
            "YourPhoneNumber",
            "YourPassword",
            access_token_cache_file="access_token_cache_file.txt")
        self.id = 'EBE57CE9D7624D78A5A0BE44340E0DFE'
        self.authentication = self.authenticator.authenticate()
        self.access_token = self.authentication.access_token

    def get_smartlock_status(self):
        self.api.get_lock_status(self.access_token, self.id)

    def unlock(self):
        unlock_response = self.api.unlock(self.access_token, self.id)
        print(unlock_response)
예제 #4
0
async def async_setup(hass, config):
    """Set up the August component."""

    conf = config[DOMAIN]
    api_http_session = None
    try:
        api_http_session = Session()
    except RequestException as ex:
        _LOGGER.warning("Creating HTTP session failed with: %s", str(ex))

    api = Api(timeout=conf.get(CONF_TIMEOUT), http_session=api_http_session)

    authenticator = Authenticator(
        api,
        conf.get(CONF_LOGIN_METHOD),
        conf.get(CONF_USERNAME),
        conf.get(CONF_PASSWORD),
        install_id=conf.get(CONF_INSTALL_ID),
        access_token_cache_file=hass.config.path(AUGUST_CONFIG_FILE),
    )

    def close_http_session(event):
        """Close API sessions used to connect to August."""
        _LOGGER.debug("Closing August HTTP sessions")
        if api_http_session:
            try:
                api_http_session.close()
            except RequestException:
                pass

        _LOGGER.debug("August HTTP session closed.")

    hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, close_http_session)
    _LOGGER.debug("Registered for Home Assistant stop event")

    token_refresh_lock = asyncio.Lock()

    return await hass.async_add_executor_job(
        setup_august, hass, config, api, authenticator, token_refresh_lock
    )
예제 #5
0
def setup(hass, config):
    """Set up the August component."""
    from august.api import Api
    from august.authenticator import Authenticator
    from requests import Session

    conf = config[DOMAIN]
    api_http_session = None
    try:
        api_http_session = Session()
    except RequestException as ex:
        _LOGGER.warning("Creating HTTP session failed with: %s", str(ex))

    api = Api(timeout=conf.get(CONF_TIMEOUT), http_session=api_http_session)

    authenticator = Authenticator(
        api,
        conf.get(CONF_LOGIN_METHOD),
        conf.get(CONF_USERNAME),
        conf.get(CONF_PASSWORD),
        install_id=conf.get(CONF_INSTALL_ID),
        access_token_cache_file=hass.config.path(AUGUST_CONFIG_FILE),
    )

    def close_http_session(event):
        """Close API sessions used to connect to August."""
        _LOGGER.debug("Closing August HTTP sessions")
        if api_http_session:
            try:
                api_http_session.close()
            except RequestException:
                pass

        _LOGGER.debug("August HTTP session closed.")

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, close_http_session)
    _LOGGER.debug("Registered for HASS stop event")

    return setup_august(hass, config, api, authenticator)
예제 #6
0
from august.authenticator import Authenticator, AuthenticationState, ValidationResult


def read_last_verification_code():
    with open('/var/mail/ubuntu', 'r') as f:
        lines = f.read().splitlines()
        for i in range(1, 6):
            m = re.search(r'[0-9]{6}', lines[-1 * i])
            if m:
                return m.group(0)


api = Api(timeout=20)

password = os.environ['AUGUST_PASSWORD']
authenticator = Authenticator(api, "email", "*****@*****.**",
                              password)
auth = authenticator.authenticate()

if auth.state == AuthenticationState.BAD_PASSWORD:
    print('ERROR: wrong user name or password.')
    sys.exit(1)

if auth.state == AuthenticationState.REQUIRES_VALIDATION:
    authenticator.send_verification_code()

    time.sleep(30)

    code = read_last_verification_code()
    validation_result = authenticator.validate_verification_code(code)

    if validation_result != ValidationResult.VALIDATED:
예제 #7
0
#!/bin/python3

from august.api import Api 
from august.authenticator import Authenticator, AuthenticationState

api = Api(timeout=20)
authenticator = Authenticator(api, "phone", "+15555555555", "PASSWORD",
                                      access_token_cache_file="token.dat")

authentication = authenticator.authenticate()

# State can be either REQUIRES_VALIDATION, BAD_PASSWORD or AUTHENTICATED
# You'll need to call different methods to finish authentication process, see below
state = authentication.state

#print( state ) 

# If AuthenticationState is BAD_PASSWORD, that means your login_method, username and password do not match

# If AuthenticationState is AUTHENTICATED, that means you're authenticated already. If you specify "access_token_cache_file", the authentication is cached in a file. Everytime you try to authenticate again, it'll read from that file and if you're authenticated already, Authenticator won't call August again as you have a valid access_token

if state == AuthenticationState.REQUIRES_VALIDATION:
    # If AuthenticationState is REQUIRES_VALIDATION, then you'll need to go through verification process
    # send_verification_code() will send a code to either your phone or email depending on login_method
    authenticator.send_verification_code()
    # Wait for your code and pass it in to validate_verification_code()
    validation_result = authenticator.validate_verification_code(input())
    # If ValidationResult is INVALID_VERIFICATION_CODE, then you'll need to either enter correct one or resend by calling send_verification_code() again
    # If ValidationResult is VALIDATED, then you'll need to call authenticate() again to finish authentication process
    authentication = authenticator.authenticate()
예제 #8
0
 def _create_authenticator(self, mock_api):
     return Authenticator(mock_api,
                          "phone",
                          "user",
                          "pass",
                          install_id="install_id")