예제 #1
0
 def handle_event(self, event):
     api_event = ApiEvent(event)
     action = api_event.action
     event = api_event.event
     if action == self.EVENT_COMMAND_INSERT_ACTION:
         command = Command(self._api, event[self.EVENT_COMMAND_KEY])
         return self._handler.handle_command_insert(command)
     if action == self.EVENT_COMMAND_UPDATE_ACTION:
         command = Command(self._api, event[self.EVENT_COMMAND_KEY])
         return self._handler.handle_command_update(command)
     if action == self.EVENT_NOTIFICATION_ACTION:
         notification = Notification(event[self.EVENT_NOTIFICATION_KEY])
         return self._handler.handle_notification(notification)
예제 #2
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)
예제 #3
0
 def handle_event(self, event):
     api_event = ApiEvent(event)
     action = api_event.action
     subscription_id = api_event.subscription_id
     if self._api.removed_subscription_id_exists(action, subscription_id):
         return
     event = api_event.event
     if action == self.EVENT_COMMAND_INSERT_ACTION:
         command = Command(self._api, event[self.EVENT_COMMAND_KEY])
         return self._handler.handle_command_insert(command)
     if action == self.EVENT_COMMAND_UPDATE_ACTION:
         command = Command(self._api, event[self.EVENT_COMMAND_KEY])
         return self._handler.handle_command_update(command)
     if action == self.EVENT_NOTIFICATION_ACTION:
         notification = Notification(event[self.EVENT_NOTIFICATION_KEY])
         return self._handler.handle_notification(notification)
예제 #4
0
 def list_commands(self,
                   device_id,
                   start=None,
                   end=None,
                   command=None,
                   status=None,
                   sort_field=None,
                   sort_order=None,
                   take=None,
                   skip=None):
     auth_api_request = AuthApiRequest(self)
     auth_api_request.url('device/{deviceId}/command', deviceId=device_id)
     auth_api_request.action('command/list')
     auth_api_request.param('start', start)
     auth_api_request.param('end', end)
     auth_api_request.param('command', command)
     auth_api_request.param('status', status)
     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('commands')
     commands = auth_api_request.execute('List commands failure.')
     return [Command(self, command) for command in commands]