def create_user(self, login, password, role, data, all_device_types_available=True): status = User.ACTIVE_STATUS user = { User.LOGIN_KEY: login, User.ROLE_KEY: role, User.STATUS_KEY: status, User.DATA_KEY: data, User.PASSWORD_KEY: password, User.ALL_DEVICE_TYPES_KEY: all_device_types_available } auth_api_request = AuthApiRequest(self) auth_api_request.method('POST') auth_api_request.url('user') auth_api_request.action('user/insert') auth_api_request.set('user', user, True) auth_api_request.response_key('user') user = auth_api_request.execute('User create failure.') user[User.LOGIN_KEY] = login user[User.ROLE_KEY] = role user[User.STATUS_KEY] = status user[User.DATA_KEY] = data return User(self, user)
def send_command(self, device_id, command_name, parameters=None, lifetime=None, timestamp=None, status=None, result=None): command = {Command.COMMAND_KEY: command_name} if parameters: command[Command.PARAMETERS_KEY] = parameters if lifetime: command[Command.LIFETIME_KEY] = lifetime if timestamp: command[Command.TIMESTAMP_KEY] = timestamp if status: command[Command.STATUS_KEY] = status if result: command[Command.RESULT_KEY] = result auth_api_request = AuthApiRequest(self) auth_api_request.method('POST') auth_api_request.url('device/{deviceId}/command', deviceId=device_id) auth_api_request.action('command/insert') auth_api_request.set('command', command, True) auth_api_request.response_key('command') command = auth_api_request.execute('Command send failure.') command[Command.DEVICE_ID_KEY] = device_id command[Command.COMMAND_KEY] = command_name command[Command.PARAMETERS_KEY] = parameters command[Command.LIFETIME_KEY] = lifetime command[Command.STATUS_KEY] = status command[Command.RESULT_KEY] = result return Command(self, command)
def create_token(self, user_id, expiration=None, actions=None, network_ids=None, device_type_ids=None, device_ids=None): payload = {'userId': user_id} if expiration: payload['expiration'] = expiration if actions: payload['actions'] = actions if network_ids: payload['networkIds'] = network_ids if device_type_ids: payload['deviceTypeIds'] = device_type_ids if device_ids: payload['deviceIds'] = device_ids auth_api_request = AuthApiRequest(self) auth_api_request.method('POST') auth_api_request.url('token/create') auth_api_request.action('token/create') auth_api_request.set('payload', payload, True) tokens = auth_api_request.execute('Token refresh failure.') return { 'refresh_token': tokens['refreshToken'], 'access_token': tokens['accessToken'] }
def set_property(self, name, value): auth_api_request = AuthApiRequest(self) auth_api_request.method('PUT') auth_api_request.url('configuration/{name}', name=name) auth_api_request.action('configuration/put') auth_api_request.set('value', value) auth_api_request.response_key('configuration') configuration = auth_api_request.execute('Set property failure.') return {'entity_version': configuration['entityVersion']}
def update_password(self, password): self._ensure_exists() user = {self.PASSWORD_KEY: password} auth_api_request = AuthApiRequest(self._api) auth_api_request.method('PUT') auth_api_request.url('user/{userId}', userId=self._id) auth_api_request.action('user/update') auth_api_request.set('user', user, True) auth_api_request.execute('User password update failure.')
def save(self): command = {self.STATUS_KEY: self.status, self.RESULT_KEY: self.result} auth_api_request = AuthApiRequest(self._api) auth_api_request.method('PUT') auth_api_request.url('device/{deviceId}/command/{commandId}', deviceId=self._device_id, commandId=self._id) auth_api_request.action('command/update') auth_api_request.set('command', command, True) auth_api_request.execute('Command save failure.')
def save(self): self._ensure_exists() network = {self.ID_KEY: self._id, self.NAME_KEY: self.name, self.DESCRIPTION_KEY: self.description} auth_api_request = AuthApiRequest(self._api) auth_api_request.method('PUT') auth_api_request.url('network/{networkId}', networkId=self._id) auth_api_request.action('network/update') auth_api_request.set('network', network, True) auth_api_request.execute('Network save failure.')
def save(self): self._ensure_exists() device_type = {self.ID_KEY: self._id, self.NAME_KEY: self.name, self.DESCRIPTION_KEY: self.description} auth_api_request = AuthApiRequest(self._api) auth_api_request.method('PUT') auth_api_request.url('devicetype/{deviceTypeId}', deviceTypeId=self._id) auth_api_request.action('devicetype/update') auth_api_request.set('deviceType', device_type, True) auth_api_request.execute('DeviceType save failure.')
def save(self): self._ensure_exists() user = { self.ROLE_KEY: self.role, self.STATUS_KEY: self.status, self.DATA_KEY: self.data } auth_api_request = AuthApiRequest(self._api) auth_api_request.method('PUT') auth_api_request.url('user/{userId}', userId=self._id) auth_api_request.action('user/update') auth_api_request.set('user', user, True) auth_api_request.execute('User save failure.')
def save(self): self._ensure_exists() device = { self.NAME_KEY: self.name, self.DATA_KEY: self.data, self.NETWORK_ID_KEY: self.network_id, self.DEVICE_TYPE_ID_KEY: self.device_type_id, self.IS_BLOCKED_KEY: self.is_blocked } auth_api_request = AuthApiRequest(self._api) auth_api_request.method('PUT') auth_api_request.url('device/{deviceId}', deviceId=self._id) auth_api_request.action('device/save') auth_api_request.set('device', device, True) auth_api_request.execute('Device save failure.')
def create_device_type(self, name, description): device_type = { DeviceType.NAME_KEY: name, DeviceType.DESCRIPTION_KEY: description } auth_api_request = AuthApiRequest(self) auth_api_request.method('POST') auth_api_request.url('devicetype') auth_api_request.action('devicetype/insert') auth_api_request.set('deviceType', device_type, True) auth_api_request.response_key('deviceType') device_type = auth_api_request.execute('Device type create failure.') device_type[DeviceType.NAME_KEY] = name device_type[DeviceType.DESCRIPTION_KEY] = description return DeviceType(self, device_type)
def create_network(self, name, description): network = { Network.NAME_KEY: name, Network.DESCRIPTION_KEY: description } auth_api_request = AuthApiRequest(self) auth_api_request.method('POST') auth_api_request.url('network') auth_api_request.action('network/insert') auth_api_request.set('network', network, True) auth_api_request.response_key('network') network = auth_api_request.execute('Network create failure.') network[Network.NAME_KEY] = name network[Network.DESCRIPTION_KEY] = description return Network(self, network)
def send_notification(self, device_id, notification_name, parameters=None, timestamp=None): notification = {'notification': notification_name} if parameters: notification['parameters'] = parameters if timestamp: notification['timestamp'] = timestamp auth_api_request = AuthApiRequest(self) auth_api_request.method('POST') auth_api_request.url('device/{deviceId}/notification', deviceId=device_id) auth_api_request.action('notification/insert') auth_api_request.set('notification', notification, True) auth_api_request.response_key('notification') notification = auth_api_request.execute('Notification send failure.') notification[Notification.DEVICE_ID_KEY] = device_id notification[Notification.NOTIFICATION_KEY] = notification_name notification[Notification.PARAMETERS_KEY] = parameters return Notification(notification)