Ejemplo n.º 1
0
    def handler(self):
        while 1:
            defer = tasks.get()
            logging.debug('handler: getting defer from task queue')

            if defer.message.command == "discovery":
                logging.debug('handler: processing discovery request')
                nodes = pyzwave.discover()
                gateway_id = nodes[0]
                total_nodes = nodes[1]
                # remaining are the discovered nodes
                discovered_nodes = nodes[2:]
                try:
                    discovered_nodes.remove(gateway_id)
                except ValueError:
                    pass # sometimes gateway_id is not in the list
                defer.callback(discovered_nodes)
            elif defer.message.command == "routing":
                logging.debug('handler: processing routing request')
                routing = {}
                nodes = pyzwave.discover()
                gateway_id = nodes[0]
                nodes = nodes[2:]
                try:
                    nodes.remove(gateway_id)
                except ValueError:
                    pass # sometimes gateway_id is not in the list
                for node in nodes:
                    routing[node] = pyzwave.routing(node)
                    try:
                        routing[node].remove(gateway_id)
                    except ValueError:
                        pass
                defer.callback(routing)
            else:
                logging.debug('handler: processing send request')
                retries = 1
                destination = defer.message.destination
                command = defer.message.command
                payload = defer.message.payload

                while retries > 0:
                    try:
                        logging.debug("handler: sending message from defer")
                        pyzwave.send(destination, [0x88, command] + payload)

                        if len(defer.allowed_replies) > 0:
                            BrokerAgent.init().append(defer)

                        break
                    except Exception as e:
                        log = "==IOError== retries remaining: " + str(retries)
                        logging.exception(log)
                    retries -= 1

                if retries == 0 or len(defer.allowed_replies) == 0:
                    logging.error("handler: returns immediately to handle failues, or defer has no expected replies")
                    defer.callback(None)

            gevent.sleep(0)
Ejemplo n.º 2
0
 def getNodeRoutingInfo(self, address):
     ret = []
     with self._global_lock:
         ret = pyzwave.routing(address)
         try:
             ret.remove(gateway_id)
         except ValueError:
             pass
     return ret
Ejemplo n.º 3
0
    def handler(self):
        while 1:
            defer = tasks.get()
            print 'handler: getting defer from task queue'

            if defer.message.command == "discovery":
                print 'handler: processing discovery request'
                nodes = pyzwave.discover()
                gateway_id = nodes[0]
                total_nodes = nodes[1]
                # remaining are the discovered nodes
                discovered_nodes = nodes[2:]
                try:
                    discovered_nodes.remove(gateway_id)
                except ValueError:
                    pass # sometimes gateway_id is not in the list
                defer.callback(discovered_nodes)
            elif defer.message.command == "routing":
                print 'handler: processing routing request'
                routing = {}
                nodes = pyzwave.discover()
                gateway_id = nodes[0]
                nodes = nodes[2:]
                try:
                    nodes.remove(gateway_id)
                except ValueError:
                    pass # sometimes gateway_id is not in the list
                for node in nodes:
                    routing[node] = pyzwave.routing(node)
                    try:
                        routing[node].remove(gateway_id)
                    except ValueError:
                        pass
                defer.callback(routing)
            else:
                print 'handler: processing send request'
                retries = 1
                destination = defer.message.destination
                command = defer.message.command
                payload = defer.message.payload

                # prevent pyzwave send got preempted and defer is not in queue
                if len(defer.allowed_replies) > 0:
                    print "handler: appending defer", defer, "to queue"
                    getAgent().append(defer)

                while retries > 0:
                    try:
                        print "handler: sending message from defer"
                        pyzwave.send(destination, [0x88, command] + payload)

                        break
                    except Exception as e:
                        log = "==IOError== retries remaining: " + str(retries)
                        print log
                    retries -= 1

                if retries == 0 or len(defer.allowed_replies) == 0:
                    print "handler: returns immediately to handle failues, or defer has no expected replies"
                    defer.callback(None)

            gevent.sleep(0)
Ejemplo n.º 4
0
    def handler(self):
        while 1:
            defer = tasks.get()
            #print 'handler: getting defer from task queue'

            if defer.message.command == "discovery":
                #print 'handler: processing discovery request'
                nodes = pyzwave.discover()
                gateway_id = nodes[0]
                total_nodes = nodes[1]
                # remaining are the discovered nodes
                discovered_nodes = nodes[2:]
                try:
                    discovered_nodes.remove(gateway_id)
                except ValueError:
                    pass  # sometimes gateway_id is not in the list
                defer.callback(discovered_nodes)
            elif defer.message.command == "routing":
                #print 'handler: processing routing request'
                routing = {}
                nodes = pyzwave.discover()
                gateway_id = nodes[0]
                nodes = nodes[2:]
                try:
                    nodes.remove(gateway_id)
                except ValueError:
                    pass  # sometimes gateway_id is not in the list
                for node in nodes:
                    routing[node] = pyzwave.routing(node)
                    try:
                        routing[node].remove(gateway_id)
                    except ValueError:
                        pass
                defer.callback(routing)
            elif defer.message.command == "device_type":
                #print 'handler: processing routing request'
                device_type = pyzwave.getDeviceType(defer.message.destination)
                defer.callback(device_type)
            else:
                #print 'handler: processing send request'
                retries = 1
                destination = defer.message.destination
                command = defer.message.command
                payload = defer.message.payload

                # prevent pyzwave send got preempted and defer is not in queue
                if len(defer.allowed_replies) > 0:
                    print "[transport] handler: appending defer", defer, "to queue"
                    getAgent().append(defer)

                while retries > 0:
                    try:
                        #print "handler: sending message from defer"
                        pyzwave.send(destination, [0x88, command] + payload)

                        break
                    except Exception as e:
                        log = "==IOError== retries remaining: " + str(retries)
                        print '[transport] ' + log
                    retries -= 1

                if retries == 0 or len(defer.allowed_replies) == 0:
                    print "[transport] handler: returns immediately to handle failues, or defer has no expected replies"
                    defer.callback(None)

            gevent.sleep(0)