code: def _disconnect_from_device(self, uuid, key, client, unsolicited=False):
          
  
          conn_id = self._validate_connection('disconnect', uuid, key)
          if conn_id is None:
              return
  
          conn_data = self._connections[uuid]
  
          slug = self._build_device_slug(uuid)
  
          message = {'client': client, 'type': 'response', 'operation': 'disconnect'}
  
          self.client.reset_sequence(self.topics.gateway_topic(slug, 'control/connect'))
          self.client.reset_sequence(self.topics.gateway_topic(slug, 'control/action'))
  
          try:
              resp = yield self._manager.disconnect(conn_id)
          except Exception as exc:
              self._logger.exception("Error in manager disconnect")
              resp = {'success': False, 'reason': "Internal error: %s" % str(exc)}
  
          # Remove any monitors that we registered for this device
          self._manager.remove_monitor(conn_data['report_monitor'])
          self._manager.remove_monitor(conn_data['trace_monitor'])
  
          if resp['success']:
              del self._connections[uuid]
              message['success'] = True
          else:
              message['success'] = False
              message['failure_reason'] = resp['reason']
  
          self._logger.info("Client %s disconnected from device 0x%X", client, uuid)
  
          # Send a response for all requested disconnects and if we tried to disconnect the client
          # on our own and succeeded, send an unsolicited notification to that effect
          if unsolicited and resp['success']:
              self._publish_response(slug, {'client': client, 'type': 'notification', 'operation': 'disconnect'})
          elif not unsolicited:
              self._publish_response(slug, message)
docs: Disconnect from a device that we have previously connected to.
  
          Args:
              uuid (int): The unique id of the device
              key (string): A 64 byte string used to secure this connection
              client (string): The client id for who is trying to connect
                  to the device.
              unsolicited (bool): Whether the client asked us to disconnect or we
                  are forcibly doing it.  Forcible disconnections are sent as notifications
                  instead of responses.