def get_item_by_id(self, item_id):
"""
Returns a handler object that can be used to send messages to an item.
:param item_id: globally unique id of the item
:return: a proxy object for the item
"""
if not self._reactor.running:
raise Exception("You must call parlay.utils.setup() at the beginning of a script!")
def find():
g = self._find_item_info(self.discovery, item_id, "ID")
item_disc = next(g)
return self._proxy_item(item_disc)
try:
defer.returnValue(find())
except StopIteration:
# discover and try again
try:
yield self.discover(force=False)
defer.returnValue(find())
except StopIteration:
raise KeyError("Couldn't find item with id " + str(item_id))
评论列表
文章目录