def __init__(self):
     '''
     Constructor
     '''
     self.config = ConfigUtil()
     self.connector = SmtpClientConnector()
     self.multiActuator = MultiActuatorAdaptor()
예제 #2
0
    def setUp(self):

        #instantiate the classes required
        self.sensorDataManager = SensorDataManager()
        self.hI2CSensorAdaptorTask = HI2CSensorAdaptorTask()
        self.humiditySensorAdaptorTask = HumiditySensorAdaptorTask()
        self.multiActuatorAdaptor = MultiActuatorAdaptor()
        self.multiSensorAdaptor = MultiSensorAdaptor()
        self.sense = sense_hat.SenseHat()
 def setUp(self):
     self.sd = SensorData()
     self.sd.addValue(11)
     self.sd.setName("Test")
     self.sdm = SensorDataManager()
     self.sdm.actuator.addValue(11)
     self.actuator = ActuatorData()
     self.actuator.addValue(2)
     self.actuator.setName("Test")
     self.tsa = MultiSensorAdaptor()
     self.taa = MultiActuatorAdaptor()
     self.tat = HumiditySensorAdaptorTask()
     self.tat.sensorData = SensorData()
     self.shla = SenseHatLedActivator()
 def __init__(self):
     self.actuator = ActuatorData()
     self.sensorAdaptor = MultiSensorAdaptor()
     self.config = ConfigUtil()
     self.config.loadConfig("../../../config/ConnectedDevicesConfig.props")
     self.threshold = float(self.config.getValue("device", "nominalTemp"))
     self.actuatorOP = MultiActuatorAdaptor.getInstance()
예제 #5
0
class Module04Test(unittest.TestCase):

    confU = ConfigUtil()
    sensorD = SensorData()
    hasConf = confU.hasConfig()
    curVal = sensorD.getCurrentValue()
    avgVal = sensorD.getAverageValue()
    actD = ActuatorData()
    senDM = SensorDataManager()
    multiAct = MultiActuatorAdaptor()
    """
	it checks for the datatype of hasConf to be boolean, If true test case is passed.
	"""
    def testConfigUtil(self):
        self.assertTrue(isinstance(self.hasConf, bool), "Boolean Value")

    """
	it checks for the datatype of curVal to be float, If true test case is passed. 
	Second checks for the avgVal to be within the specified range.If true test case is passed. 
	"""

    def testSensorData(self):
        self.assertTrue(isinstance(self.curVal, float), "Float Value")
        self.assertTrue(self.avgVal >= 0.0 and self.avgVal <= 30.0,
                        "Average Temperature within the range")

    '''
	It checks for the datatype of the getCommand function to be String.
	'''

    def testActuatorData(self):
        self.assertTrue(isinstance(self.actD.getCommand(), str), "String")

    '''
	It checks for the returntype of the function handleSensorData of class SensorDataManager to be of type actuator data. 
	'''

    def testSensorDataManager(self):
        self.assertTrue(
            isinstance(self.senDM.handleSensorData(self.sensorD),
                       ActuatorData), "Type Actuator Data")

    '''
	It checks for the returntype of the function updateActuator of class MultiActuatorAdaptor to be of type Boolean. 
	'''

    def testMultiActuatorAdaptor(self):
        self.assertTrue(
            isinstance(self.multiAct.updateActuator(ActuatorData), bool),
            "Type Boolean")
예제 #6
0
 def trigger_actuation(self):
         self.maa = MultiActuatorAdaptor()        
class HI2CSensorAdaptorTask(Thread):
    '''
    Variables are defined and objects of required classes are created with the class scope.
    '''
    sensorData = SensorData()  #constructor of sensorData is created.
    multiAct = MultiActuatorAdaptor(
    )  #constructor of TempActuatorAdaptor is created.
    sensorDataM = SensorDataManager(
    )  #constructor of SensorDataManager is created.
    avgValue = 0.0
    count = 0.0
    total = 0.0
    currentValue = 0.0
    maxValue = 0.0
    minValue = 0.0
    timestamp = None
    sh = SenseHat()

    def __init__(self, name):  #constructor is called
        Thread.__init__(self)
        self.name = name

    '''
    this run function overrides the run function of Thread and calculates the Humidity values from the I2C bus,addValue fnctn of sensorData is called
    humidityI2C of class sensorDataManager is called and sensorData object is passed as a parameter.
    This function will return the actuator data.
     
    '''

    def run(self):
        logging.basicConfig(level=logging.INFO,
                            format='%(asctime)s:%(levelname)s:%(message)s')

        while True:

            lsb1 = i2cBus.read_byte_data(0x5f, 0x36)
            msb1 = i2cBus.read_byte_data(0x5f, 0x37)
            H0 = numpy.int16((msb1 << 8) | lsb1)

            lsb2 = i2cBus.read_byte_data(0x5f, 0x3A)
            msb2 = i2cBus.read_byte_data(0x5f, 0x3B)
            H1 = numpy.int16((msb2 << 8) | lsb2)

            lsb3 = i2cBus.read_byte_data(0x5f, 0x28)
            msb3 = i2cBus.read_byte_data(0x5f, 0x29)
            H = numpy.int16((msb3 << 8) | lsb3)

            h1 = numpy.uint16(i2cBus.read_byte_data(0x5f, 0x31) >> 1)
            h0 = numpy.uint16(i2cBus.read_byte_data(0x5f, 0x30) >> 1)

            per = ((h1 - h0) * (H - H0) / (H1 - H0)) + h0
            self.sensorData.addValue(per)
            self.act_data = self.sensorDataM.humidityI2C(self.sensorData)
            self.getSensorData()
            if (self.act_data != None):
                self.multiAct.updateActuator(self.act_data)
        # logger.info("I2C: " +str(per)+"%" )
            logging.basicConfig(level=logging.INFO)
            data = "HI2C Sensor:\nTime:    " + str(
                self.timestamp) + "\nCurrent:    " + str(
                    self.currentValue) + "\nAverage:    " + str(
                        self.avgValue) + "\nSamples:    " + str(
                            self.count) + "\nMin:    " + str(
                                self.minValue) + "\nMax:    " + str(
                                    self.maxValue)
            logging.info(data)
            print("\n")
        return None

    '''
     This function fetches the values from sensorData and store it to the local variables of this class.
    '''

    def getSensorData(self):
        self.avgValue = self.sensorData.getAverageValue()
        self.count = self.sensorData.getCount()
        self.total = self.sensorData.getTotal()
        self.currentValue = self.sensorData.getCurrentValue()
        self.maxValue = self.sensorData.getMaxValue()
        self.minValue = self.sensorData.getMinValue()
        self.timestamp = self.sensorData.getTimestamp()
예제 #8
0
class Module04Test(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):

        #instantiate the classes required
        self.sensorDataManager = SensorDataManager()
        self.hI2CSensorAdaptorTask = HI2CSensorAdaptorTask()
        self.humiditySensorAdaptorTask = HumiditySensorAdaptorTask()
        self.multiActuatorAdaptor = MultiActuatorAdaptor()
        self.multiSensorAdaptor = MultiSensorAdaptor()
        self.sense = sense_hat.SenseHat()

    """
	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):

        #set the reference to the variables as none to release the resources they're holding
        self.sensorDataManager = None
        self.hI2CSensorAdaptorTask = None
        self.multiActuatorAdaptor = None
        self.multiSensorAdaptorTask = None
        self.multiSensorAdaptor = None
        self.sense = None
        pass

    """
	This method tests the handleSensorData() of SensorDataManager module. It tests whether the sensor data list passed to the method triggers the correct
	actuator command.
	"""

    def testGetHandleSensorData(self):

        #log the test
        logging.info(
            "\nTesting the handleSensorData() method of SensorDataManager")

        #initialize sensor data to represent reading from I2C
        sensorDataI2C = SensorData()

        #add a humidity value
        sensorDataI2C.addValue(10)

        #set the name for i2c
        sensorDataI2C.setName("i2c humidity")

        #initialize sensor data to represent reading from SenseHAT API
        sensorDataAPI = SensorData()

        #add a humidity value
        sensorDataAPI.addValue(9)

        #set the name for i2c
        sensorDataAPI.setName("sense_hat API humidity")

        #add them to a list
        sensorDataTest = []
        sensorDataTest.append(sensorDataI2C)
        sensorDataTest.append(sensorDataAPI)

        #get the actuatorDataList returned from the sensor data manager
        actuatorDataList = self.sensorDataManager.handleSensorData(
            sensorDataTest)

        #check if actuatorData at both indexes are of type ActuatorData
        self.assertIsInstance(actuatorDataList[0], ActuatorData)
        self.assertIsInstance(actuatorDataList[1], ActuatorData)

        #test the actuatorData value at the first index, which should simply be the first value (10)
        self.assertEqual(10, actuatorDataList[0].getValue())

        #test the actuatorData command at the first index which should be DISPLAY I2C Humidity
        self.assertEqual(actuatorDataList[0].getCommand(),
                         "DISPLAY I2C Humidity")

        #test the actuatorData name at the second index which should be I2C Humidity
        self.assertEqual(actuatorDataList[0].getName(), "I2C Humidity")

        #test the value at the second index, which should simply be the first value (9)
        self.assertEqual(9, actuatorDataList[1].getValue())

        #test the actuatorData command at the second index which should be DISPLAY I2C Humidity
        self.assertEqual(actuatorDataList[1].getCommand(),
                         "DISPLAY SENSE HAT API Humidity")

        #test the actuatorData name at the second index which should be I2C Humidity
        self.assertEqual(actuatorDataList[1].getName(),
                         "SENSE HAT API Humidity")

        #initialize a random sensorData object and add it to the list and call the manager again
        sensorData = SensorData()

        #set invalid sensor data name
        sensorData.setName("blah blah")

        #append to list
        sensorDataTest.append(sensorData)

        #get the actuatorDataList returned from the manager should still have a length of 2 because we only added an invalid type
        actuatorDataList = self.sensorDataManager.handleSensorData(
            sensorDataTest)

        #check if length of actuatorDataList is 2
        self.assertEqual(len(actuatorDataList), 2)

        #clear the list and only add invalid sensor data
        sensorDataTest = []
        sensorDataTest.append(sensorData)

        #get the actuatorDataList returned from the manager should be None
        actuatorDataList = self.sensorDataManager.handleSensorData(
            sensorDataTest)

        #check if it is none
        self.assertEqual(actuatorDataList, None)

    """
	This tests the sendNotification() method of the SensorDataManager, it simply whether
	 the notification is being sent or not. This has been shown in documentation using screenshot of the
	 email
	"""

    def testSendNotification(self):

        #log the test
        logging.info(
            "\nTesting the sendNotification() method of SensorDataManager")

        #if the config file is loaded: while testing on system
        if self.sensorDataManager.smtpClientConnector.config.configFileLoaded == True:

            #returns true, notification is being sent
            self.assertEqual(
                True,
                self.sensorDataManager.sendNotification(
                    "Hello", "This is a test"))

        pass

    """
	This tests the updateActuator() method of the MultiActuatorAdaptor, it checks whether the actuator is updated 
	(by returning an actuatorData reference) when the trigger is valid and when the trigger is invalid 
	(NOT A VALID TRIGGER)
	"""

    def testUpdateActuator(self):

        #log the test
        logging.info(
            "\nTesting the updateActuator() method of MultiActuatorAdaptor")

        #create an invalid actuator trigger
        actuatorData = ActuatorData()
        actuatorData.setCommand("NOT A VALID TRIGGER")

        #add a valid value
        actuatorData.setValue(90)

        #add it to list of actuatorDataTest
        actuatorDataTest = []
        actuatorDataTest.append(actuatorData)

        #updateActuator should return a false
        self.assertEqual(
            False, self.multiActuatorAdaptor.updateActuator(actuatorDataTest))

        #create a valid actuator trigger
        actuatorData = ActuatorData()
        actuatorData.setCommand("DISPLAY SENSE HAT API Humidity")
        actuatorData.setValue(12)

        actuatorDataTest = []
        actuatorDataTest.append(actuatorData)

        #updateActuator should return a True
        self.assertEqual(
            True, self.multiActuatorAdaptor.updateActuator(actuatorDataTest))

        #sending a none should throw an exception, where when caught, returns a false
        self.assertEqual(False, self.multiActuatorAdaptor.updateActuator(None))

        pass

    """
	This tests the getHumidityData() method of the HI2CSensorAdaptorTask, it checks whether the returned value and the sense_hat api value
	have difference < 1
	"""

    def testGetHumidityDataHI12C(self):

        #log the test
        logging.info(
            "\nTesting the getHumidityData() method of HI2CSensorAdaptorTask")

        #get the humidity data
        sensorData = self.hI2CSensorAdaptorTask.getHumidityData()

        #sleep for little time
        sleep(1)

        #get the absolute difference between sensorData from i2c and the sense hat api
        self.assertTrue(
            abs(sensorData.getCurrentValue() - self.sense.get_humidity()) <=
            1.0, "Value" + str(sensorData.getCurrentValue()))

    """
	This tests the getHumidityData() method of the HI2CSensorAdaptorTask, it checks whether the returned value and the sense_hat api value
	have difference < 1
	"""

    def testGetHumidityDataAPI(self):

        #log the test
        logging.info(
            "\nTesting the getHumidityData() method of HumiditySensorAdaptorTask"
        )

        #get the humidity data
        sensorData = self.humiditySensorAdaptorTask.getHumidityData()

        #sleep for little time
        sleep(0.5)

        #get the absolute difference between sensorData from i2c and the sense hat api
        self.assertTrue(
            abs(sensorData.getCurrentValue() -
                self.sense.get_humidity()) <= 1.0)

    """
	Tests the getSensorData() method of both the HI2CSensorAdaptorTask and HumiditySensorAdaptorTask 
	"""

    def testGetSensorData(self):

        #get the sensor data reference from the getSensorData method
        sensorDataHI2C = self.hI2CSensorAdaptorTask.getSensorData()
        sensorDataHumidity = self.humiditySensorAdaptorTask.getSensorData()

        #check if instance of SensorData
        self.assertIsInstance(sensorDataHI2C, SensorData)
        self.assertIsInstance(sensorDataHumidity, SensorData)

    """
	This tests the whether the difference between the sensor values detected from , it checks whether the 
	i2c bus and sense hat API have a difference of <= 1.0 
	"""

    def testComparisonI2CSenseHat(self):

        #log the test
        logging.info(
            "\nTesting the comparison between readings of I2C Bus and API")

        #get the sensor data references from both
        sensorDataHumidity = self.humiditySensorAdaptorTask.getSensorData()

        #sleep for little time
        sleep(0.5)

        sensorDataHI2C = self.hI2CSensorAdaptorTask.getSensorData()

        #check for difference
        self.assertTrue(
            abs(sensorDataHumidity.getCurrentValue() -
                sensorDataHI2C.getCurrentValue()) <= 1.0, "Value more than 1")

    """
	This test checks the run() method of the MultiSensorAdaptor
	"""

    def testRun(self):

        #log the test
        logging.info("\nTesting the run() method of MultiSensorAdaptor()")

        #enable the fetcher
        self.multiSensorAdaptor.hI2CSensorAdaptorTask.enableFetcher = True
        self.multiSensorAdaptor.humiditySensorAdaptorTask.enableFetcher = True

        #change numReadings to a small finite value to check
        self.multiSensorAdaptor.numReadings = 1

        #change sleep time (rateInSec) to a small amount
        self.multiSensorAdaptor.rateInSec = 1

        #run when numReadings > 0 and adaptor is enabled
        self.assertEqual(True, self.multiSensorAdaptor.run())

        #change numReadings to 0
        self.multiSensorAdaptor.numReadings = 0

        #run when numReadings = 0 and fetcher is enabled, should return false because run will not fetch
        self.assertEqual(False, self.multiSensorAdaptor.run())
예제 #9
0
class HumiditySensorAdaptorTask(Thread):
    '''
    Variables are defined and objects of required classes are created with the class scope.
    '''
    sensorData = SensorData()  #constructor of sensorData is created.
    multiAct = MultiActuatorAdaptor(
    )  #constructor of TempActuatorAdaptor is created.
    sensorDataM = SensorDataManager(
    )  #constructor of SensorDataManager is created.
    avgValue = 0.0
    count = 0.0
    total = 0.0
    currentValue = 0.0
    maxValue = 0.0
    minValue = 0.0
    timestamp = None
    sh = SenseHat()

    def __init__(self, name):  #constructor is initialized
        Thread.__init__(self)
        self.name = name

    '''
    this run function overrides the run function of Thread and calls the sense hat function to generate the Humidity values,addValue fnctn of sensorData is called
    humidity of class sensorDataManager is called and sensorData object is passed as a parameter.
    This function will return the actuator data.
    '''

    def run(self):  #run method of thread is overriden
        logging.basicConfig(level=logging.INFO,
                            format='%(asctime)s:%(levelname)s:%(message)s')
        sh = SenseHat()
        res = sh.get_humidity()
        self.sensorData.addValue(res)
        self.act_data = self.sensorDataM.humidity(self.sensorData)
        self.getSensorData()
        if (self.act_data != None):
            self.multiAct.updateActuator(
                self.act_data)  #calling of updateActuator

        logging.basicConfig(level=logging.INFO)
        data = "Humidity Sensor:\nTime:    " + str(
            self.timestamp) + "\nCurrent:    " + str(
                self.currentValue) + "\nAverage:    " + str(
                    self.avgValue) + "\nSamples:    " + str(
                        self.count) + "\nMin:    " + str(
                            self.minValue) + "\nMax:    " + str(self.maxValue)
        logging.info(data)
        print("\n")

    '''
    This function fetches the values from sensorData and store it to the local variables of this class.
    '''

    def getSensorData(self):
        self.avgValue = self.sensorData.getAverageValue()
        self.count = self.sensorData.getCount()
        self.total = self.sensorData.getTotal()
        self.currentValue = self.sensorData.getCurrentValue()
        self.maxValue = self.sensorData.getMaxValue()
        self.minValue = self.sensorData.getMinValue()
        self.timestamp = self.sensorData.getTimestamp()
예제 #10
0
class SensorDataManager(object):
    '''
    classdocs
    '''

    #instantiate TempActuatorAdaptor
    multiActuatorAdaptor = MultiActuatorAdaptor()

    #instantiate ConfigUtil
    configUtil = ConfigUtil()

    #instantiate smtp client connector
    smtpClientConnector = SmtpClientConnector()

    def __init__(self):
        '''
        Constructor
        '''

    #this method takes in sensorData as a parameter and checks it against the type of readings and takes appropriate action
    def handleSensorData(self, sensorDatas):

        #initialize the list for actuatorData
        actuatorDataList = []

        #iterate through the sensorDatas list
        for sensorData in sensorDatas:

            #if the reading is directly from i2c bus
            if sensorData.getName() == "i2c humidity":

                #get the current sensor value
                sensorVal = sensorData.getCurrentValue()

                #instantiate ActuatorData
                actuatorData = ActuatorData()

                #the actuator should display the current humidity
                actuatorData.setCommand("DISPLAY I2C Humidity")

                #set the name of the actuator
                actuatorData.setName("I2C Humidity")

                #set the value to the current humidity value
                actuatorData.setValue(sensorVal)

                #send email notification consisting of the reading
                self.sendNotification(sensorData.loggingData,
                                      "Humidity Reading from I2C Bus")

                #append the actuator data to the list
                actuatorDataList.append(actuatorData)

            #if the reading is directly from sensehat api
            elif sensorData.getName() == "sense_hat API humidity":

                #get the current sensor value
                sensorVal = sensorData.getCurrentValue()

                #instantiate ActuatorData
                actuatorData = ActuatorData()

                #the actuator should display the current humidity
                actuatorData.setCommand("DISPLAY SENSE HAT API Humidity")

                #set the name of the actuator
                actuatorData.setName("SENSE HAT API Humidity")

                #set the value to the current humidity value
                actuatorData.setValue(sensorVal)

                #send email notification consisting of the reading
                self.sendNotification(sensorData.loggingData,
                                      "Humidity Reading from SenseHAT API")

                #append the actuator data to the list
                actuatorDataList.append(actuatorData)

        #if no valid sensor data reading
        if len(actuatorDataList) == 0:

            #return none
            return None

        #send the list to the updateActuator method of the multiActuatorAdaptor
        self.multiActuatorAdaptor.updateActuator(actuatorDataList)

        #return the list of actuatorData
        return actuatorDataList

    #method for sending the notification via e-mail
    def sendNotification(self, data, topic):

        #send email with topic indicating excessive temperature
        self.smtpClientConnector.publishMessage(data, topic)

        #create a delay for email to be sent
        sleep(2)

        #return true for running successfully
        return True
class SensorDataManager(object):
    '''
    classdocs
    '''
    actuatorData = ActuatorData()

    def __init__(self):
        '''
        Constructor
        '''
        self.config = ConfigUtil()
        self.connector = SmtpClientConnector()
        self.multiActuator = MultiActuatorAdaptor()

    '''
    If current temperature exceeds or falls below the 'nominalTemp', the new SensorData instance will trigger an actuation
    It will return the new ActualatorData instance with the appropriate data value and command embedded;
    Otherwise, it returns None
    Also,if an actuation is triggered, the SmtpClientConnector instance will be created to send the e-mail 
    message to the appropriate destination    
    '''

    def handleSensorData(self, sensorData):
        self.nominalTemp = float(
            self.config.getValue(ConfigConst.DEVICE, ConfigConst.NOMINAL_TEMP))
        self.nominalHumid = float(
            self.config.getValue(ConfigConst.DEVICE,
                                 ConfigConst.NOMINAL_HUMID))
        self.time = sensorData.timeStamp
        self.average = sensorData.avgValue
        self.samples = sensorData.getCount()
        self.min = sensorData.minValue
        self.max = sensorData.maxValue
        self.name = sensorData.getName()

        if (self.name == 'Temp'):
            self.message = 'Temperature\n' + '\tTime: ' + str(
                self.time) + '\n\tCurrent: ' + str(
                    sensorData.curValue) + '\n\tAverage: ' + str(
                        self.average) + '\n\tSamples: ' + str(
                            self.samples) + '\n\tMin: ' + str(
                                self.min) + '\n\tMax: ' + str(self.max)
            if (sensorData.curValue > self.nominalTemp):

                logging.info(
                    '\nCurrent temperature exceeds nonminalTemp by > ' +
                    str(self.nominalTemp) + '. Triggering alert...')
                #print('\nCurrent temperature exceeds nonminalTemp by > ' +str(self.nominalTemp) + '. Triggering alert...')

                self.connector.publishMessage('Excessive Temperature',
                                              self.message)
                self.actuatorData.setCommand('Increasing')
                self.actuatorData.getValue(sensorData.curValue)
                self.multiActuator.updateActuator(self.actuatorData)
                print(self.message)
                return (self.actuatorData)

            elif (sensorData.curValue < self.nominalTemp):

                logging.info(
                    '\nCurrent temperature lower than nonminalTemp by < ' +
                    str(self.nominalTemp) + '. Triggering alert...')

                self.connector.publishMessage('Decreasing Temperature',
                                              self.message)
                self.actuatorData.setCommand('Decreasing')
                self.actuatorData.getValue(sensorData.curValue)
                self.multiActuator.updateActuator(self.actuatorData)
                print(self.message)
                return (self.actuatorData)

            else:
                return (None)

        if (self.name == 'Humid'):
            self.message = 'SenseHat API Humidity\n' + '\tTime: ' + str(
                self.time) + '\n\tCurrent: ' + str(
                    sensorData.curValue) + '\n\tAverage: ' + str(
                        self.average) + '\n\tSamples: ' + str(
                            self.samples) + '\n\tMin: ' + str(
                                self.min) + '\n\tMax: ' + str(self.max)
            if (sensorData.curValue > self.nominalHumid):

                logging.info('\nCurrent humidity exceeds nonminalHumid by > ' +
                             str(self.nominalHumid) + '. Triggering alert...')
                #print('\nCurrent temperature exceeds nonminalTemp by > ' +str(self.nominalTemp) + '. Triggering alert...')

                self.connector.publishMessage('Moist Humidity', self.message)
                self.actuatorData.setCommand('sensehatMoist')
                self.actuatorData.getValue(sensorData.curValue)
                self.multiActuator.updateActuator(self.actuatorData)
                print(self.message)
                return (self.actuatorData)

            elif (sensorData.curValue < self.nominalHumid):

                logging.info(
                    '\nCurrent Humidity lower than nonminalHumid by < ' +
                    str(self.nominalTemp) + '. Triggering alert...')

                self.connector.publishMessage('Dry Humidity', self.message)
                self.actuatorData.setCommand('sensehatDry')
                self.actuatorData.getValue(sensorData.curValue)
                self.multiActuator.updateActuator(self.actuatorData)
                print(self.message)
                return (self.actuatorData)

            else:
                return (None)

        if (self.name == 'I2C_Humid'):
            self.message = 'I2C Direct Humidity\n' + '\tTime: ' + str(
                self.time) + '\n\tCurrent: ' + str(
                    sensorData.curValue) + '\n\tAverage: ' + str(
                        self.average) + '\n\tSamples: ' + str(
                            self.samples) + '\n\tMin: ' + str(
                                self.min) + '\n\tMax: ' + str(self.max)
            if (sensorData.curValue > self.nominalHumid):

                logging.info('\nCurrent humidity exceeds nonminalHumid by > ' +
                             str(self.nominalHumid) + '. Triggering alert...')
                #print('\nCurrent temperature exceeds nonminalTemp by > ' +str(self.nominalTemp) + '. Triggering alert...')

                self.connector.publishMessage('Moist Humidity', self.message)
                self.actuatorData.setCommand('i2cMoist')
                self.actuatorData.getValue(sensorData.curValue)
                self.multiActuator.updateActuator(self.actuatorData)
                print(self.message)
                return (self.actuatorData)

            elif (sensorData.curValue < self.nominalHumid):

                logging.info(
                    '\nCurrent Humidity lower than nonminalHumid by < ' +
                    str(self.nominalTemp) + '. Triggering alert...')

                self.connector.publishMessage('Dry Humidity', self.message)
                self.actuatorData.setCommand('i2cDry')
                self.actuatorData.getValue(sensorData.curValue)
                self.multiActuator.updateActuator(self.actuatorData)
                print(self.message)
                return (self.actuatorData)

            else:
                return (None)
class Module04Test(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.sd = SensorData()
        self.sd.addValue(11)
        self.sd.setName("Test")
        self.sdm = SensorDataManager()
        self.sdm.actuator.addValue(11)
        self.actuator = ActuatorData()
        self.actuator.addValue(2)
        self.actuator.setName("Test")
        self.tsa = MultiSensorAdaptor()
        self.taa = MultiActuatorAdaptor()
        self.tat = HumiditySensorAdaptorTask()
        self.tat.sensorData = SensorData()
        self.shla = SenseHatLedActivator()

    """
	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.
	"""
    '@Test'

    def testSendNotification(self):
        self.assertTrue(self.sdm.sendNotification(),
                        "Notification Unsucessful")
        pass

    '@Test'

    def testhadleSensorData(self):
        self.assertTrue(self.sdm.hadleSensorData(self.sd),
                        "Sensor handle data method not working")

    '@Test'

    def testgetSensorData(self):
        self.assertTrue(self.tsa.getSensorData(),
                        "Issue in temperature adaptor")

    '@Test'

    def testreadSensorValueMin(self):
        self.assertGreaterEqual(self.tat.readSensorValue(), 0.0,
                                'sensor value coming less than 0')
        self.assertGreaterEqual(100, self.tat.readSensorValue(),
                                'sensor value coming more than 100')

    '@Test'

    def testupdateActuator(self):
        self.assertTrue(self.taa.updateActuator(self.actuator),
                        "Actuator update failed")

    '@Test'

    def testupdateLed(self):
        self.assertTrue(self.shla.updateLed("Test Message"),
                        "Led update failed")

    '@Test'

    def testreadSensorValuePushNotification(self):
        self.tat.sensorData = SensorData()
        self.tat.sensorData.addValue(12)
        self.tat.sensorData.setName("Test")
        self.tat.sdm = SensorDataManager()
        self.assertTrue(self.tat.pushData(),
                        "Message not getting pushed to Sensor Data Manager")