Пример #1
0
 def get(self, device_id):
     auth_api_request = AuthApiRequest(self._api)
     auth_api_request.url('device/{deviceId}', deviceId=device_id)
     auth_api_request.action('device/get')
     auth_api_request.response_key('device')
     device = auth_api_request.execute('Device get failure.')
     self._init(device)
Пример #2
0
 def get(self, user_id):
     auth_api_request = AuthApiRequest(self._api)
     auth_api_request.url('user/{userId}', userId=user_id)
     auth_api_request.action('user/get')
     auth_api_request.response_key('user')
     user = auth_api_request.execute('User get failure.')
     self._init(user)
Пример #3
0
 def get_current(self):
     auth_api_request = AuthApiRequest(self._api)
     auth_api_request.url('user/current')
     auth_api_request.action('user/getCurrent')
     auth_api_request.response_key('current')
     user = auth_api_request.execute('Current user get failure.')
     self._init(user)
Пример #4
0
 def get(self, network_id):
     auth_api_request = AuthApiRequest(self._api)
     auth_api_request.url('network/{id}', id=network_id)
     auth_api_request.action('network/get')
     auth_api_request.response_key('network')
     network = auth_api_request.execute('Network get failure.')
     self._init(network)
Пример #5
0
 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)
Пример #6
0
 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']
     }
Пример #7
0
 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)
Пример #8
0
 def disallow_all_device_types(self):
     self._ensure_exists()
     self._ensure_all_device_types_available()
     auth_api_request = AuthApiRequest(self._api)
     auth_api_request.method('DELETE')
     auth_api_request.url('user/{userId}/devicetype/all', userId=self._id)
     auth_api_request.action('user/disallowAllDeviceTypes')
     auth_api_request.execute('Unassign device type failure.')
     self._all_device_types_available = False
Пример #9
0
 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']}
Пример #10
0
 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.')
Пример #11
0
 def allow_all_device_types(self):
     self._ensure_exists()
     self._ensure_not_all_device_types_available()
     auth_api_request = AuthApiRequest(self._api)
     auth_api_request.method('PUT')
     auth_api_request.url('user/{userId}/devicetype/all', userId=self._id)
     auth_api_request.action('user/allowAllDeviceTypes')
     auth_api_request.execute('Assign all device types failure.')
     self._all_device_types_available = True
Пример #12
0
 def unassign_network(self, network_id):
     self._ensure_exists()
     auth_api_request = AuthApiRequest(self._api)
     auth_api_request.method('DELETE')
     auth_api_request.url('user/{userId}/network/{networkId}',
                          userId=self._id,
                          networkId=network_id)
     auth_api_request.action('user/unassignNetwork')
     auth_api_request.execute('Unassign network failure.')
Пример #13
0
 def remove(self):
     self._ensure_exists()
     auth_api_request = AuthApiRequest(self._api)
     auth_api_request.method('DELETE')
     auth_api_request.url('network/{id}', id=self._id)
     auth_api_request.action('network/delete')
     auth_api_request.execute('Network remove failure.')
     self._id = None
     self.name = None
     self.description = None
Пример #14
0
 def unassign_device_type(self, device_type_id):
     self._ensure_exists()
     self._ensure_not_all_device_types_available()
     auth_api_request = AuthApiRequest(self._api)
     auth_api_request.method('DELETE')
     auth_api_request.url('user/{userId}/devicetype/{deviceTypeId}',
                          userId=self._id,
                          deviceTypeId=device_type_id)
     auth_api_request.action('user/unassignDeviceType')
     auth_api_request.execute('Unassign device type failure.')
Пример #15
0
 def remove(self):
     self._ensure_exists()
     auth_api_request = AuthApiRequest(self._api)
     auth_api_request.method('DELETE')
     auth_api_request.url('devicetype/{deviceTypeId}', deviceTypeId=self._id)
     auth_api_request.action('devicetype/delete')
     auth_api_request.execute('DeviceType remove failure.')
     self._id = None
     self.name = None
     self.description = None
Пример #16
0
 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.')
Пример #17
0
 def list_networks(self):
     self._ensure_exists()
     auth_api_request = AuthApiRequest(self._api)
     auth_api_request.url('user/{userId}', userId=self._id)
     auth_api_request.action('user/get')
     auth_api_request.response_key('user')
     user = auth_api_request.execute('List networks failure.')
     return [
         Network(self._api, network) for network in user[User.NETWORKS_KEY]
     ]
Пример #18
0
 def list_device_types(self):
     self._ensure_exists()
     auth_api_request = AuthApiRequest(self._api)
     auth_api_request.url('user/{userId}/devicetype', userId=self._id)
     auth_api_request.action('user/getDeviceTypes')
     auth_api_request.response_key('deviceTypes')
     device_types = auth_api_request.execute('List device types failure.')
     return [
         DeviceType(self._api, device_type) for device_type in device_types
     ]
Пример #19
0
 def get_property(self, name):
     auth_api_request = AuthApiRequest(self)
     auth_api_request.url('configuration/{name}', name=name)
     auth_api_request.action('configuration/get')
     auth_api_request.response_key('configuration')
     configuration = auth_api_request.execute('Get property failure.')
     return {
         'entity_version': configuration['entityVersion'],
         'name': configuration['name'],
         'value': configuration['value']
     }
Пример #20
0
 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.')
Пример #21
0
 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.')
Пример #22
0
 def remove(self):
     self._ensure_exists()
     auth_api_request = AuthApiRequest(self._api)
     auth_api_request.method('DELETE')
     auth_api_request.url('device/{deviceId}', deviceId=self._id)
     auth_api_request.action('device/delete')
     auth_api_request.execute('Device remove failure.')
     self._id = None
     self.name = None
     self.data = None
     self.network_id = None
     self.device_type_id = None
     self.is_blocked = None
Пример #23
0
 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.')
Пример #24
0
 def remove(self):
     self._ensure_exists()
     auth_api_request = AuthApiRequest(self._api)
     auth_api_request.method('DELETE')
     auth_api_request.url('user/{userId}', userId=self._id)
     auth_api_request.action('user/delete')
     auth_api_request.execute('User remove failure.')
     self._id = None
     self._login = None
     self._last_login = None
     self._intro_reviewed = None
     self.role = None
     self.status = None
     self.data = None
Пример #25
0
 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.')
Пример #26
0
 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)
Пример #27
0
 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)
Пример #28
0
 def list_device_types(self,
                       name=None,
                       name_pattern=None,
                       sort_field=None,
                       sort_order=None,
                       take=None,
                       skip=None):
     auth_api_request = AuthApiRequest(self)
     auth_api_request.url('devicetype')
     auth_api_request.action('devicetype/list')
     auth_api_request.param('name', name)
     auth_api_request.param('namePattern', name_pattern)
     auth_api_request.param('sortField', sort_field)
     auth_api_request.param('sortOrder', sort_order)
     auth_api_request.param('take', take)
     auth_api_request.param('skip', skip)
     auth_api_request.response_key('deviceTypes')
     device_types = auth_api_request.execute('List device types failure.')
     return [DeviceType(self, device_type) for device_type in device_types]
Пример #29
0
 def list_networks(self,
                   name=None,
                   name_pattern=None,
                   sort_field=None,
                   sort_order=None,
                   take=None,
                   skip=None):
     auth_api_request = AuthApiRequest(self)
     auth_api_request.url('network')
     auth_api_request.action('network/list')
     auth_api_request.param('name', name)
     auth_api_request.param('namePattern', name_pattern)
     auth_api_request.param('sortField', sort_field)
     auth_api_request.param('sortOrder', sort_order)
     auth_api_request.param('take', take)
     auth_api_request.param('skip', skip)
     auth_api_request.response_key('networks')
     networks = auth_api_request.execute('List networks failure.')
     return [Network(self, network) for network in networks]
Пример #30
0
 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)