memory (disco): added findServiceEntity helper method to get first service of a kind

This commit is contained in:
Goffi 2017-11-15 08:54:32 +01:00
commit 30768ce305

View file

@ -230,6 +230,16 @@ class Discovery(object):
log.warning(_(u"Error while requesting [%(jid)s]: %(error)s") % {'jid': entity_jid.full(),
'error': failure_.getErrorMessage()})
def findServiceEntity(self, client, category, type_, jid_=None):
"""Helper method to find first available entity from findServiceEntities
args are the same as for [findServiceEntities]
@return (jid.JID, None): found entity
"""
d = self.host.findServiceEntities(client, "pubsub", "service")
d.addCallback(lambda entities: entities.pop() if entities else None)
return d
def findServiceEntities(self, client, category, type_, jid_=None):
"""Return all available items of an entity which correspond to (category, type_)