예제 #1
0
class BaseActuatorSimTask():
    """
	Shell representation of class for student implementation.
	
	"""
    def __init__(self,
                 actuatorType: int = ActuatorData.DEFAULT_ACTUATOR_TYPE,
                 simpleName: str = "Actuator"):
        self.actuatorType = actuatorType
        self.simpleName = simpleName
        self.actuatorData = ActuatorData(name=simpleName)

    def activateActuator(self, val: float) -> bool:
        logging.info("""\n*******\n* ON *\n*******\n%s Value: %f\n""",
                     self.simpleName, val)
        self.actuatorData.setCommand(ActuatorData.COMMAND_ON)
        return True

    def deactivateActuator(self) -> bool:
        logging.info("""\n*******\n* OFF *\n*******\n""")
        self.actuatorData.setCommand(ActuatorData.COMMAND_OFF)
        return True

    def getLatestActuatorResponse(self) -> ActuatorData:
        return self.actuatorData

    def getSimpleName(self) -> str:
        return self.simpleName

    def updateActuator(self, data: ActuatorData) -> bool:
        if data is not None:
            if data.getCommand() == ActuatorData.COMMAND_ON:
                self.activateActuator(data.value)
            else:
                self.deactivateActuator()
        self.actuatorData._handleUpdateData(data)
        self.actuatorData.setAsResponse()
        logging.info(
            "Emulating %s actuator %s:", self.simpleName,
            "ON" if self.actuatorData.getCommand() == ActuatorData.COMMAND_ON
            else "OFF")
        return True
class BaseActuatorSimTask():
	"""
	Shell representation of class for student implementation.
	
	"""

	def __init__(self, actuatorType: int = ActuatorData.DEFAULT_ACTUATOR_TYPE, simpleName: str = "Actuator"):
		self.actuatorType = actuatorType
		
		self.LatestActuatorData = ActuatorData(actuatorType)
		self.simpleName = simpleName
	
		
	def activateActuator(self, val: float) -> bool:
		logging.info("Sending Actuator On Command")
		self.LatestActuatorData.command = ActuatorData.COMMAND_ON
		return True
		
	def deactivateActuator(self) -> bool:
		logging.info("Sending Actuator Off Command")
		self.LatestActuatorData.command = ActuatorData.COMMAND_OFF
		return True

		
	def getLatestActuatorResponse(self) -> ActuatorData:
		return self.LatestActuatorData

	
	def getSimpleName(self) -> str:
		return self.simpleName
	
	
	def updateActuator(self, data: ActuatorData) -> bool:
		if data != None:
			if (data.getCommand() == 0):
				self.deactivateActuator()
			else:
				self.activateActuator(data.getCommand())
				self.LatestActuatorData = data
				self.LatestActuatorData.setAsResponse()
		return True
예제 #3
0
class BaseActuatorSimTask():
    """
	Shell representation of class for student implementation.
	
	"""
    def __init__(self,
                 actuatorType: int = ActuatorData.DEFAULT_ACTUATOR_TYPE,
                 simpleName: str = "Actuator",
                 actuatorName=ConfigConst.NOT_SET):
        """
		Initialization of class.
		Create an instance of BaseActuatorSimTask
		"""
        self.actuatorType = actuatorType
        self.simpleName = simpleName
        self.latestAd = ActuatorData(name=actuatorName)

    def activateActuator(self, val: float) -> bool:
        """
		Activate the Actuator
		
		@return bool
		"""
        logging.info("---> Emulating %s actuator ON:",
                     str(self.getActuatorTypeName()))
        print('*******')
        print('* O N *')
        print('*******')
        print(self.getActuatorTypeName() + ' VALUE -> ' + str(val))
        self.latestAd.setCommand(ActuatorData.COMMAND_ON)
        return True

    def deactivateActuator(self) -> bool:
        """
		Deactivate the Actuator
		
		@return bool
		"""
        logging.info("---> Emulating %s actuator OFF: ",
                     str(self.getActuatorTypeName()))
        print('*******')
        print('* OFF *')
        print('*******')
        self.latestAd.setCommand(ActuatorData.COMMAND_OFF)
        return True

    def getActuatorType(self):
        """
		Get the ActuatorType of the instance
		
		@return str
		"""
        return self.actuatorType

    def getLatestActuatorResponse(self) -> ActuatorData:
        """
		Get the LatestActuatorResponse of the instance
		
		@return ActuatorData
		"""
        return self.latestAd

    def getSimpleName(self) -> str:
        """
		Get the SimpleName of the instance
		
		@return str
		"""
        return self.simpleName

    def updateActuator(self, data: ActuatorData) -> bool:
        """
		Update the Actuator
		
		@return bool
		"""
        if data:
            if data.getCommand() == ActuatorData.COMMAND_ON:
                self.activateActuator(data.getValue())
            else:
                self.deactivateActuator()
            self.latestAd._handleUpdateData(data)

        self.latestAd.setAsResponse()
        return True

    def getActuatorTypeName(self):
        """
		Get the ActuatorTypeName of the instance
		
		@return str
		"""
        if self.actuatorType == 1:
            return 'HVAC'
        if self.actuatorType == 2:
            return 'HUMIDIFIER'
        return 'Unknown'
class BaseActuatorSimTask():
    """
	Base class for ActuatorSimTask
	
	"""
    def __init__(self,
                 actuatorType: int = ActuatorData.DEFAULT_ACTUATOR_TYPE,
                 simpleName: str = ConfigConst.NOT_SET):
        """
		Init BaseActuatorSimTask with default values
		:param actuatorType: Type of actuator
		:param simpleName: Name of actuator
		"""
        self.actuatorType = actuatorType
        self.simpleName = simpleName
        self.latestActuatorData = ActuatorData(self.actuatorType,
                                               self.simpleName)
        pass

    def activateActuator(self, val: float) -> bool:
        """
		Turn actuator on with given target value
		As a sim actuator, there is no real action
		:param val: Given target actuator value
		:return: If succeed to activate Actuator, always True as a sim actuator
		"""
        logging.info("\n======\nSim %s actuator ON, with value = %d.\n======" %
                     (self.getSimpleName(), val))
        self.latestActuatorData.setCommand(ActuatorData.COMMAND_ON)
        self.latestActuatorData.setValue(val)
        return True
        pass

    def deactivateActuator(self) -> bool:
        """
		Turn actuator off with given target value
		As a sim actuator, there is no real action
		:return: If succeed to deactivate Actuator, always True as a sim actuator
		"""
        logging.info("\n======\nSim %s actuator OFF.\n======" %
                     self.getSimpleName())
        self.latestActuatorData.setCommand(ActuatorData.COMMAND_OFF)
        return True
        pass

    def getLatestActuatorResponse(self) -> ActuatorData:
        """
		Get latest actuator data
		:return: Latest ActuatorData
		"""
        return self.latestActuatorData
        pass

    def getSimpleName(self) -> str:
        """
		Get name of the sim actuator
		:return: Name string
		"""
        return self.simpleName
        pass

    def updateActuator(self, data: ActuatorData) -> bool:
        """
		Use ActuatorData as command:
		Update current maintained latest ActuatorData
		Use given ActuatorData to execute command
		:param data: Given ActuatorData
		:return: If succeed to update and execute
		"""
        if data is None:
            logging.error("Got an invalid ActuatorData, which is None!")
            return False
        if not isinstance(data, ActuatorData):
            logging.error(
                "Got an invalid ActuatorData, which type is not ActuatorData!")
            return False
        if data.getCommand(
        ) is not ActuatorData.COMMAND_ON and data.getCommand(
        ) is not ActuatorData.COMMAND_OFF:
            logging.error(
                "Got an invalid ActuatorData, whose command is invalid!")
            return False
        ret = False
        if data.getCommand() is ActuatorData.COMMAND_ON:
            ret = self.activateActuator(data.getValue())
        else:
            ret = self.deactivateActuator()
        self.latestActuatorData.updateData(data)
        self.latestActuatorData.setName(self.simpleName)
        self.latestActuatorData.setStatusCode(int(ret))
        self.latestActuatorData.setAsResponse()
        return ret
        pass