Ejemplo n.º 1
0
    def postControlNotification (self, nodeId, notification):
        with self.lock:
            nodeIdStr = str(nodeId)
            previous = self.getLatestNotificationFromNode (nodeIdStr)
            logger.info("Got latest notification to be: " + str(previous))

            if previous is not None:
                diff = notification.time - previous.time
                diffSeconds = diff.total_seconds()
                logger.info("Last notification arrived " + str(diffSeconds) + " seconds ago")

                if (diffSeconds <= self.ignoreSeconds):
                    if (notification.value == previous.value) :
                        logger.info("Ignoring notification: " + str(notification.nid) + " since previous notification with same value came " + str(diffSeconds) + " seconds ago.")
                        notification.ignore = True

                if notification.value == 'False':
                    if previous.value == 'False':
                        # If a sensor is closed, and it is still closed, we
                        # do not really care about it.
                        # However, if a sensor is open, we care about it no
                        # matter what the previous state was.
                        logger.info("Ignoring notification: " + str(notification.nid) + " since previous notification was false and current notification is false")
                        notification.ignore = True
            else:
                logger.info("Making a dummy previous")
                previous = ValueNotification(notification.nodeId, notification.commandClass, notification.fullHex, "False")
                previous.time = datetime.datetime(1970, 1, 1)
                #Insert dummy notification
                self.notifications.insert_one(previous.__dict__)
            print "inserting one: " + str(notification.__dict__)
            self.notifications.insert_one(notification.__dict__)
            ncb = self.getNCB(nodeId)
            ncb.setValue(notification.value)
            self.nodes.replace_one({"_id": ncb._id}, ncb.__dict__)
Ejemplo n.º 2
0
    def postControlNotification (self, nodeId, notification):
        with self.lock:
            #Critical Section
            nodeIdStr = str(nodeId)
            previous = self.getLatestNotificationFromNode (nodeIdStr)
            logger.info("Got latest notification to be: " + str(previous))

            if previous is not None:
                diff = notification.time - previous.time
                diffSeconds = diff.total_seconds()
                logger.info("Last notification arrived " + str(diffSeconds) + " seconds ago")

                if (diffSeconds <= self.ignoreSeconds):
                    if (notification.value == previous.value) :
                        logger.info("Ignoring notification: " + str(notification.nid) + " since previous notification with same value came " + str(diffSeconds) + " seconds ago.")
                        notification.ignore = True

                if notification.value == 'False':
                    if previous.value == 'False':
                        # If a sensor is closed, and it is still closed, we
                        # do not really care about it.
                        # However, if a sensor is open, we care about it no
                        # matter what the previous state was.
                        logger.info("Ignoring notification: " + str(notification.nid) + " since previous notification was false and current notification is false")
                        notification.ignore = True
            else:
                logger.info("Making a dummy previous")
                previous = ValueNotification(notification.nodeId, notification.commandClass, notification.fullHex, "False")
                previous.time = datetime.datetime(1970, 1, 1)
                ncb = self.shelf.get(nodeIdStr, NodeControlBlock(nodeIdStr))
                l = ncb.notifications
                l.insert(0,previous)
                self.shelf[nodeIdStr] = ncb

            ncb = self.shelf.get(nodeIdStr, NodeControlBlock(nodeIdStr))
            l = ncb.notifications
            # Truncate list to maxNotifcationsPerNode size
            l.insert(0,notification)
            if len(l)>self.maxNotifcationsPerNode:
                ncb.notifications = l[:self.maxNotifcationsPerNode]

            # Set overall control value for this node and put it on the shelf
            ncb.setValue(notification.value)
            self.shelf[nodeIdStr] = ncb
            self.shelf.sync()
            #End critical section
        self.callRobots('control', notification, previous)