示例#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
示例#2
0
文件: device.py 项目: ztardik/PyKNyX
    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
示例#3
0
文件: device.py 项目: ztardik/PyKNyX
    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"
示例#4
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)
示例#5
0
文件: device.py 项目: ztardik/PyKNyX
    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
示例#6
0
文件: alertFB.py 项目: ztardik/PyKNyX
    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)
示例#7
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))
示例#8
0
文件: alertFB.py 项目: ztardik/PyKNyX
    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)
示例#9
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)