def get_item_by_name(self, item_name):
"""
Returns a handler object that can be used to send messages to an item.
:param item_name: globally unique name 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_name, "NAME")
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 name " + str(item_name))
评论列表
文章目录