Beispiel #1
0
    def cmdChanged(self, event):
        """ Method called when the 'cmd' datapoint changes

        We just copy the 'cmd' datapoint value to the 'state' datapoint.
        """
        logger.debug("ActuatorFB.cmdChanged(): event=%s" % repr(event))

        value = event['newValue']
        logger.info("%s: switch output %s" % (self.name, value))
        self.dp["state"].value = value
Beispiel #2
0
 def stateChanged(self, event):
     if event['newValue'] == "On":
         delay = self.dp["delay"].value
         logger.info("%s: start timer for %ds" % (self.name, delay))
         self._timer = delay
     elif event['newValue'] == "Off":
         if self._timer:
             logger.info("%s: switched off detected; cancel timer" %
                         self.name)
             self._timer = 0
Beispiel #3
0
    def delayChanged(self, event):
        """ Method called when the 'delay' datapoint changes
        """
        logger.debug("TimerFB.delayChanged(): event=%s" % repr(event))

        # If the timer is running, we reset it to the new delay
        if self._timer:
            delay = self.dp["delay"].value
            logger.info("%s: delay changed; restart timer" % self._name)
            self._timer = delay
Beispiel #4
0
    def updateTimer(self):
        """ Method called every second.
        """
        #logger.trace("TimerFB.updateTimer()")

        if self._timer:
            self._timer -= 1
            logger.debug("TimerFB.updateTimer(): timer=%d" % self._timer)
            if not self._timer:
                logger.info("%s: timer expired; switch off" % self._name)
                self.dp["cmd"].value = "Off"
Beispiel #5
0
    def RegisterStateChanged(self, event):
        """ Method called when any of the 'reg_x' Datapoint change
        """
        logger.debug("%s: event=%s" % (self.name, repr(event)))

        dpName = event['dp']
        newValue = event['newValue']
        oldValue = event['oldValue']
        logger.info("%s: '%s' value changed from %s to %s" % (self.name, dpName, oldValue, newValue))

        # Send new register value to modbus client
        self._write(config.KNX_TO_MODBUS[dpName], newValue)
Beispiel #6
0
    def stateChanged(self, event):
        """ Method called when the 'state' datapoint changes
        """
        logger.debug("TimerFB.stateChanged(): event=%s" % repr(event))

        if event['newValue'] == "On":
            delay = self.dp["delay"].value
            logger.info("%s: start timer for %ds" % (self._name, delay))
            self._timer = delay
        elif event['newValue'] == "Off":
            if self._timer:
                logger.info("%s: switched off detected; cancel timer" % self._name)
                self._timer = 0
Beispiel #7
0
    def doorChanged(self, event):
        """ Method called when 'door' Datapoint change
        """
        logger.debug("%s event=%s" % (self.name, repr(event)))

        dpName = event['dp']
        newValue = event['newValue']
        oldValue = event['oldValue']
        logger.info("%s: '%s' value changed from %s to %s" %
                    (self.name, dpName, oldValue, newValue))

        # Check new value
        if newValue == "Open" and oldValue == "Close":
            msg = "'%s' value is now %s" % (dpName, newValue)
            logger.warning("%s: %s" % (self.name, msg))
            self._mua.send(msg)
Beispiel #8
0
    def tempChanged(self, event):
        """ Method called when any of the 'temp_x' Datapoint change
        """
        logger.debug("%s: event=%s" % (self.name, repr(event)))

        dpName = event['dp']
        newValue = event['newValue']
        oldValue = event['oldValue']
        logger.info("%s: '%s' value changed from %s to %s" %
                    (self.name, dpName, oldValue, newValue))

        # Compute new average
        average = 0.
        for dpName in ("temp_1", "temp_2", "temp_3"):
            average += self.dp[dpName].value
        average /= 3.

        # Store new average in Datapoint
        self.dp["temp_average"].value = average
        logger.info("%s: new average is %.1f" % (self.name, average))
Beispiel #9
0
    def tempChanged(self, event):
        """ Method called when any of the 'temp_x' Datapoint change
        """
        logger.debug("%s: event=%s" % (self.name, repr(event)))

        dpName = event['dp']
        newValue = event['newValue']
        oldValue = event['oldValue']
        logger.info("%s: '%s' value changed from %s to %s" %
                    (self.name, dpName, oldValue, newValue))

        # Check if new value is outside limits
        if not settings.TEMP_LIMITS[dpName][
                0] <= newValue <= settings.TEMP_LIMITS[dpName][1]:
            msg = "'%s' value (%s) is outside limits %s" % (
                dpName, newValue, repr(settings.TEMP_LIMITS[dpName]))
            logger.warning("%s: %s" % (self.name, msg))

            # Only send e-mail if old value was inside limits
            if settings.TEMP_LIMITS[dpName][
                    0] <= oldValue <= settings.TEMP_LIMITS[dpName][1]:
                self._mua.send(msg)
Beispiel #10
0
    def processQueue(self):
        """ Process queue

        Get the older entry in the sequence (queue).
        If replay is active and time elapsed, the matching Datapoint is set with the stored value.
        Otherwise, the entry is discarded.
        """
        try:
            item = self._sequence.get_nowait()
            #logger.debug("%s: item=%s" % (self.name, item))
        except Queue.Empty:
            logger.exception("%s: storage sequence is empty; skipping...",
                             self.name)

        # Check if item needs to be replayed
        delta = (time.time() - item['time']) / 60.
        if self.dp['replay'].value == "Active" and delta > self.dp[
                'replay_period'].value:
            self.dp[item['dp']].value = item['value']
            logger.info(
                "%s: '%s' replayed at %s (%s)" %
                (self.name, dpName,
                 time.strftime("%a, %d %b %Y %H:%M:%S",
                               time.localtime(item['time'])), item['value']))
Beispiel #11
0
    def lightStateChanged(self, event):
        """ Method called when any of the 'light_x' Datapoint change
        """
        logger.debug("%s: event=%s" % (self.name, repr(event)))

        dpName = event['dp']
        newValue = event['newValue']
        oldValue = event['oldValue']
        time_ = time.time()
        logger.info(
            "%s: '%s' value changed from %s to %s at %s" %
            (self.name, dpName, oldValue, newValue,
             time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(time_))))

        # Store Datapoint new value and current date/time
        try:
            self._sequence.put_nowait({
                'dp': dpName,
                'value': newValue,
                'time': time_
            })
        except Queue.Full:
            logger.exception("%s: storage sequence is full; skipping...",
                             self.name)
Beispiel #12
0
 def delayChanged(self, event):
     if self._timer:
         delay = self.dp["delay"].value
         logger.info("%s: delay changed; restart timer" % self.name)
         self._timer = delay
Beispiel #13
0
 def updateTimer(self):
     if self._timer:
         self._timer -= 1
         if not self._timer:
             logger.info("%s: timer expired; switch off" % self.name)
             self.dp["cmd"].value = "Off"