'Callback function called by the devices when the control command is
complete or failed.
If needed, composes a message with the result and sends it back to the
client.
Arguments:
session         -- The request session id
nodeId          -- The device id which initiated the callback
result          -- The current result status of the control command. Valid values are:
"error"  - Set fields failed.
"ok"     - All fields were set.
error_field      -- [optional] Only applies when result == "error"
The field name that failed (usually means it is missing)
error_msg        -- [optional] Only applies when result == "error".
Error details when a request failed.'

def _device_set_command_callback(self, session, nodeId, result, error_field=None, error_msg=None):

    if (not (session in self.sessions)):
        return
    if (result == 'error'):
        self.sessions[session]['commTimers'][nodeId].cancel()
        if self.sessions[session]['reply']:
            iq = self.xmpp.Iq()
            iq['from'] = self.sessions[session]['to']
            iq['to'] = self.sessions[session]['from']
            iq['type'] = 'error'
            iq['id'] = self.sessions[session]['seqnr']
            iq['setResponse']['responseCode'] = 'OtherError'
            iq['setResponse'].add_node(nodeId)
            if (error_field is not None):
                iq['setResponse'].add_data(error_field)
            iq['setResponse']['error']['var'] = error_field
            iq['setResponse']['error']['text'] = error_msg
            iq.send(block=False)
            self.sessions[session]['nodeDone'][nodeId] = True
            if self._all_nodes_done(session):
                del self.sessions[session]
    else:
        self.sessions[session]['commTimers'][nodeId].cancel()
        self.sessions[session]['nodeDone'][nodeId] = True
        if self._all_nodes_done(session):
            if self.sessions[session]['reply']:
                iq = self.xmpp.Iq()
                iq['from'] = self.sessions[session]['to']
                iq['to'] = self.sessions[session]['from']
                iq['type'] = 'result'
                iq['id'] = self.sessions[session]['seqnr']
                iq['setResponse']['responseCode'] = 'OK'
                iq.send(block=False)
            del self.sessions[session]
