def add_devices(api_client, account_id, device_names): # Step 1 # Get a DevicesApi instance from the swagger_client #<YOUR CODE HERE> api_instance = swagger_client.DevicesApi(api_client) try: for device_name in device_names: # Step 2 # Create a DeviceCreator request from the swagger_client to contain device information # Set client_id to the device_name # Set display_name to the device_name # Set other optional properties #<YOUR CODE HERE> DeviceCreator = { 'clientId': device_name, 'displayName': device_name, 'createBy': 'Liang Faan' } # Step 3 # Pass the DeviceCreator request to the DevicesApi instance’s device_create method # Use account_id as the scope_id # <YOUR CODE HERE> api_response = api_instance.device_create(account_id, DeviceCreator) print(f'Created device: {api_response.display_name}') except ApiException as e: print(f'Exception when calling API: {e}')
def list_devices(api_client, account_id): api_instance = swagger_client.DevicesApi(api_client) try: api_response = api_instance.device_simple_query(account_id) pprint(api_response) except ApiException as e: print(f'Exception when calling API: {e}')
def delete_devices(api_client, account_id, device_names): api_instance = swagger_client.DevicesApi(api_client) try: for device_name in device_names: api_response = api_instance.device_simple_query(account_id, client_id=device_name) if len(api_response.items) > 0: api_instance.device_delete(account_id, api_response.items[0].id) print(f'Deleted device: {device_name}') else: print(f'Device {device_name} not found, skipping') except ApiException as e: print(f'Exception when calling API: {e}')
def add_devices(api_client, account_id, device_names): api_instance = swagger_client.DevicesApi(api_client) try: for device_name in device_names: # Create dummy devices with some fake properties body = swagger_client.DeviceCreator( client_id='fake_device_' + device_name, display_name=device_name, model_name=device_name, serial_number=random.randint(1, 1000), status='ENABLED') api_response = api_instance.device_create(account_id, body) print(f'Created device: {api_response.display_name}') except ApiException as e: print(f'Exception when calling API: {e}')