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)
Esempio n. 2
0
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:
        print('ERROR: validation failed.')
Esempio n. 3
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()