def update_traits(username, api_key, kms_id): raise NotImplementedError # todo: work out traits # this currently works for changing the primary key server side method = "PUT" url = BASE_URL + "/v4/kmsdevice/" + kms_id parameters = { "username": username, "apikey": api_key } body = { "Id": kms_id, "Traits": [{ "Name": "PRIMARYCODE", "Value": "URURURU", "ULURURU" # paramLock.getFirmwareCounter() <<32 | paramLock.getPrimaryCodeCounter() "Counter": 0 }] } response_json = call_api(method, url, parameters, body) return isinstance(response_json, dict) \ and "ServiceResult" in response_json \ and response_json["ServiceResult"] == 1
def get_products(username, api_key): """API call to get a list of products registered with the account.""" method = "GET" url = BASE_URL + "v4/product?complex=true" parameters = {"username": username, "apikey": api_key} response_json = call_api(method, url, parameters) products = [] for product in response_json: products.append({ "name": product["Name"], "product_id": product["Id"], "device_id": product["KMSDevice"]["DeviceId"], "KMS_id": product["KMSDevice"]["Id"], "latitude": product["KMSDevice"]["Location"]["Latitude"], "longitude": product["KMSDevice"]["Location"]["Longitude"], "primary_code": product["KMSDevice"]["PrimaryCode"], "model_id": product["Model"]["Id"], "model_name": product["Model"]["Name"], "model_number": product["Model"]["ModelNumber"], "model_SKU": product["Model"]["SKU"] }) return products
def get_available_firmware_versions(username, api_key, some_id): raise NotImplementedError # doesn't work method = "GET" url = BASE_URL + "v4/kmsdevice/" + some_id + "/getavailablefirmwareversions" parameters = {"username": username, "apikey": api_key} return call_api(method, url, parameters)
def get_product(username, api_key, product_id): """API call to get information about a single product registered with the account. """ method = "GET" url = BASE_URL + "v4/product/" + product_id parameters = {"username": username, "apikey": api_key} return call_api(method, url, parameters)
def get_email_verification_details(id_): raise NotImplementedError # not working (maybe use the /v5/ version ?) # tried with all ids and only got {"Message":"100.6::Invalid ID."} and 404s method = "GET" url = BASE_URL + "v4/account/emailverification/" + id_ parameters = {"apikey": "androidble"} return call_api(method, url, parameters)
def get_api_key(username, password): """API call to get an API key to use in future requests.""" method = "POST" url = BASE_URL + "v4/account/authenticate/" parameters = {"apikey": "androidble"} body = { "username": username, "password": password } response_json = call_api(method, url, parameters, body) return response_json["Token"]
def generate_temporary_code(username, api_key, kms_id, access_time=None): """API call to generate a temporary code. If access_time is None, gets a currently active code. """ method = "GET" url = BASE_URL + "v4/kmsdevice/" + kms_id + "/servicecode/" parameters = {"username": username, "apikey": api_key} if access_time is not None: parameters["accessTime"] = access_time response_json = call_api(method, url, parameters) return response_json["ServiceCode"]
def reverse_geocode(latitude, longitude): with open("google_maps_api_key.txt") as f: google_maps_api_key = f.read().strip() method = "GET" url = "https://maps.googleapis.com/maps/api/geocode/json" parameters = { "latlng": str(latitude) + "," + str(longitude), "key": google_maps_api_key, "result_type": "street_address" } return call_api(method, url, parameters)["results"][0]["formatted_address"]
def get_master_backup_code(username, api_key, kms_id): """API call that get the "master" or "backup" code. Must be the owner. Code will always start with "U" and be of length 11. """ method = "GET" url = BASE_URL + "/v4/kmsdevice/" + kms_id + "/mastercode" parameters = { "username": username, "apikey": api_key } return call_api(method, url, parameters)["MasterCode"]
def get_kms_ids(username, api_key): """API call to get lock KMS id's associated with the account.""" method = "GET" url = BASE_URL + "v4/kmsdevicekey/" parameters = {"username": username, "apikey": api_key} response_json = call_api(method, url, parameters) locks = [] for lock in response_json: locks.append({ "device_id": lock["DeviceId"], "KMS_id": lock["KMSDeviceId"] }) return locks
def get_firmware_update(username, api_key, kms_id): raise NotImplementedError # must be owner # works, but fails with error '400': # {"Message":"100.2::No firmware available"} method = "GET" url = BASE_URL + "v4/kmsdevice/" + kms_id + "/firmwareupdate" parameters = { "username": username, "apikey": api_key, "appBuildId": 1, "appName": "androidble" } return call_api(method, url, parameters)
def get_specified_firmware_upgrade(username, api_key, kms_id, current_firmware_version: int, requested_firmware_version: int): raise NotImplementedError # can't get this working # current firmware version is 1445277336 # that's a valid UNIX timestamp for 2015-10-19T17:55:36+00:00 method = "GET" url = BASE_URL + "v4/kmsdevice/" + kms_id + "/getspecifiedfirmwareupgrade" parameters = { "username": username, "apikey": api_key, # paramLock.getFirmwareVersion() "deviceFirmwareVersion": current_firmware_version, "requestedFirmwareVersion": requested_firmware_version } return call_api(method, url, parameters)
def forgot_username(email): """API call that sends a username reminder email to the specified address. Returns True if successful and False otherwise. Call this in a loop for fun! """ method = "POST" url = BASE_URL + "v4/account/retrieveusername" parameters = { "apikey": "androidble" } body = {"email": email} try: response_json = call_api(method, url, parameters, body) return isinstance(response_json, dict) \ and "ServiceResult" in response_json \ and response_json["ServiceResult"] == 1 except MasterLockError: return False