def test_get_locks(self, mock): mock.register_uri("get", API_GET_LOCKS_URL, text=load_fixture("get_locks.json")) api = Api() locks = api.get_locks(ACCESS_TOKEN) self.assertEqual(1, len(locks)) first = locks[0] self.assertEqual("A6697750D607098BAE8D6BAA11EF8063", first.device_id) self.assertEqual("Front Door Lock", first.device_name) self.assertEqual("000000000000", first.house_id)
def test_get_locks(self, mock): mock.register_uri("get", API_GET_LOCKS_URL, text=load_fixture("get_locks.json")) api = Api() locks = sorted(api.get_locks(ACCESS_TOKEN), key=lambda d: d.device_id) self.assertEqual(2, len(locks)) first = locks[0] self.assertEqual("A6697750D607098BAE8D6BAA11EF8063", first.device_id) self.assertEqual("Front Door Lock", first.device_name) self.assertEqual("000000000000", first.house_id) self.assertEqual(True, first.is_operable) second = locks[1] self.assertEqual("A6697750D607098BAE8D6BAA11EF9999", second.device_id) self.assertEqual("Back Door Lock", second.device_name) self.assertEqual("000000000011", second.house_id) self.assertEqual(False, second.is_operable)
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() # Once you have authenticated and validated you can use the access token to make API calls locks = api.get_locks(authentication.access_token) #print (locks[0].device_id) #api.unlock(authentication.access_token, locks[0].device_id) api.get_lock_detail(authentication.access_token, locks[0].device_id)