class Module06Test(unittest.TestCase):
    """
	Use this to setup your tests. This is where you may want to load configuration
	information (if needed), initialize class-scoped variables, create class-scoped
	instances of complex objects, initialize any requisite connections, etc.
	"""
    def setUp(self):
        self.ddm = DeviceDataManager()
        self.ddm.actuator.addValue(15)
        self.mqt = MqttClientConnector()
        self.sd = SensorData()
        self.sd.addValue(14)
        mm = MQTTMessage()
        mm.payload = "ss"
        pass

    """
	Use this to tear down any allocated resources after your tests are complete. This
	is where you may want to release connections, zero out any long-term data, etc.
	"""

    def tearDown(self):
        pass

    """
	Place your comments describing the test here.
	"""

    def testconnect(self):
        self.assertTrue(self.mqt.connect(), "Connection Failed")
        pass


# 	def testpublishActuatorCommand(self):
# 		ac = ActuatorData();
# 		ac.addValue(14)
# 		self.assertTrue(self.mqt.publishActuatorCommand(ac,1), "publishActuator Failed")
# 		pass

    def testpublishSensorData(self):
        self.assertTrue(self.mqt.publishSensorData(self.sd, 1),
                        "publishSensor Failed")
        pass

    def testMessageReceived(self):
        self.assertTrue(self.mqt.MessageReceived(MQTTMessage),
                        "Message Failed")
        pass

    def testClientClose(self):
        self.assertTrue(self.mqt.clientClose(),
                        "Client connection close Failed")
        pass
예제 #2
0
class DeviceDataManager:
    #Default Constructor
    def __init__(self):
        self.sensorAdaptor = MultiSensorAdaptor()
        self.mqtt = MqttClientConnector()
        
    # Method execution block
    def run(self):
        i=0
        logging.info("Connecting to broker")
        self.mqtt.connect()
        logging.info("Connecting to broker")    
        while(i<2):
            logging.info("Publishing data using QoS1")
            message = DataUtil.toJsonFromSensorData(self.sensorAdaptor.getSensorData())
            self.mqtt.publishSensorData(message,1)
            i+=1
            sleep(5)
        while(i<4):
            logging.info("Publishing data using QoS2")
            message = DataUtil.toJsonFromSensorData(self.sensorAdaptor.getSensorData())
            self.mqtt.publishSensorData(message,2)
            i+=1
            sleep(10)
        self.mqtt.clientClose()
        logging.info("Finished Publishing")
        return True
    
    #Method for evaluating the sensor values and create decision for actuation  
    def handleActuatorData(self,SensorData):
        self.actuator.max_value = SensorData.max_value
        self.actuator.min_value = SensorData.min_value
        self.actuator.readings_number = SensorData.readings_number
        self.actuator.value  = SensorData.getCurrentValue()
        self.actuator.avgTemp = (SensorData.total_value / SensorData.readings_number)
        self.actuator.total_value = SensorData.total_value
        self.actuator.setName(SensorData.getName())      
        self.actuatorOP.updateActuator(self.actuator)
        return True