Пример #1
0
    def get_discovery(self):
        """
        Hitting the "discovery" button on the UI triggers this generator.

        Run a discovery for everything connected to this protocol and return a list of of all connected:
        items, messages, and endpoint types
        """

        print "----------------------------"
        print "Discovery function started!"
        print "----------------------------"

        t1 = time.time()

        # If there is a deferred item, yield that first
        if self._attached_item_d is not None:
            yield self._attached_item_d

        # If we were already in the process of a discovery we should
        # return a deferred object.
        if self._in_progress:
            defer.returnValue(self._discovery_deferred)

        self._in_progress = True
        self.items = []
        for subsystem_id in self._subsystem_ids:
            try:
                yield self._get_item_discovery_info(subsystem_id)
            except Exception as e:
                print("Exception while discovering! Skipping subsystem : " + str(subsystem_id) + "\n    " + str(e))

        self._in_progress = False

        t2 = time.time()

        print "Discovery took", (t2 - t1), "seconds"
        # At this point self.items should be populated with
        # the ParlayStandardItem objects that represent the items we discovered.
        # By calling BaseProtocol's get_discovery() function we can get that information
        # to the adapter and furthermore to the broker.
        defer.returnValue(BaseProtocol.get_discovery(self))