Esempio n. 1
0
class DelayTimerActionRule(AbstractActionRule):

	def __init__(self, context, logger, mqttServiceProvider):
		super(DelayTimerActionRule, self).__init__(context, logger, mqttServiceProvider)
		self.isDelayTimerOn = False
		self.DEFAULT_TIMER_IN_MINUTES = 10
		self.defaultTimerInMills = self.toMinutes(self.DEFAULT_TIMER_IN_MINUTES) 
		
	def run (self):
		self.logger.info("DelayTimerActionRule.run(): switching off the applicances")
		isRuleEnabled = True
		try:
			isRuleEnabled = Utilities.to_bool (self.context.getProperty(ConfigurationConstants.getIsRuleEnabled()))
		except ValueError, e:
			self.logger.error("Error on DelayTimerActionRule.run(): %s. Setting True as defalut value for isRuleEnabled" % (e))

		fullActuatorList = self.context.getProperty(ConfigurationConstants.getFullActuatorList())
		if isRuleEnabled and fullActuatorList:
			tokens =  ''.join(fullActuatorList.split()).split(';')
			for tok in tokens:
				if tok:
					eventTopic = self.makeActionEvent(EventTopics.getActuatorAction(), tok, ActuationCommands.getSwitchOff())
					self.publishEvent(eventTopic, tok, ActuationCommands.getSwitchOff(), ActuationCommands.getSwitchOff())
					try:
						time.sleep(0.01)
					except Exception, e:
						self.logger.error("Error on DelayTimerActionRule.run(): %s" % (e))
Esempio n. 2
0
	def sendCommands(self, action):
		fullActuatorList = self.context.getProperty(ConfigurationConstants.getFullActuatorList())
		if fullActuatorList:
			tokens =  ''.join(fullActuatorList.split()).split(';')
			for tok in tokens:
				if tok:
					eventTopic = self.makeActionEvent(EventTopics.getActuatorAction(), tok, action)
					self.publishEvent(eventTopic, tok, action, action)
					try:
						time.sleep(0.01)
					except Exception, e:
						self.logger.error("Error on TimeShiftActionRule.sendCommands(): %s" % (e))
Esempio n. 3
0
class SwitchOffAllActionRule(AbstractActionRule):
    def __init__(self, context, logger, mqttServiceProvider):
        super(SwitchOffAllActionRule, self).__init__(context, logger,
                                                     mqttServiceProvider)

    def process(self):
        self.logger.debug("Processing SwitchOffAllActionRule...")
        isRuleEnabled = True
        presence = False

        try:
            isRuleEnabled = Utilities.to_bool(
                self.context.getProperty(
                    ConfigurationConstants.getIsRuleEnabled()))
        except ValueError, e:
            self.logger.error(
                "Error on SwitchOffAllActionRule.process(): %s. Setting True as default value for isRuleEnabled"
                % (e))

        isTobeOff = self.context.getProperty(
            ConfigurationConstants.getSwitchOffAll())

        if isRuleEnabled and isTobeOff == "True":

            fullActuatorList = self.context.getProperty(
                ConfigurationConstants.getFullActuatorList())
            if fullActuatorList:
                devices = ''.join(fullActuatorList.split()).split(';')
                for dev in devices:
                    if dev:
                        try:
                            eventTopic = self.makeActionEvent(
                                EventTopics.getActuatorAction(), dev,
                                ActuationCommands.getSwitchOff())
                            self.publishEvent(eventTopic, dev,
                                              ActuationCommands.getSwitchOff(),
                                              ActuationCommands.getSwitchOff())
                            self.context.updateProperty(
                                ConfigurationConstants.getSwitchOffAll(),
                                "False")
                        except Exception, e:
                            self.logger.error(
                                "Error on SwitchOffAllActionRule.process(): %s"
                                % (e))