Beispiel #1
0
 def __init__(self):
     logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s',
                         level=logging.INFO,
                         datefmt='%Y-%m-%d %H:%M:%S')
     logging.info("started logging")
     threading.Thread.__init__(self)
     self.sensor_object = TempSensorAdaptorTask(20)
     self.sensor_object.start()  # Starting Threaded Class Object
class TempSensorAdaptor:
    #Default Constructor
    def __init__(self):
        self.sreader = TempSensorAdaptorTask()

    #Fetch current readings from the sensor
    def getSensorData(self):
        self.sreader.run()
        return True
Beispiel #3
0
    def setUp(self):

        #instantiate the classes required
        self.sensorDataManager = SensorDataManager()
        self.tempActuatorAdaptor = TempActuatorAdaptor()
        self.tempSensorAdaptor = TempSensorAdaptor()
        self.tempSensorAdaptorTask = TempSensorAdaptorTask()

        pass
 def __init__(self):     #constructor of TempSensorAdaptor 
     
     temp=TempSensorAdaptorTask("Thread")  #object of class TempSensorAdaptorTask is created
     '''
     Starting the thread
     '''
     temp.start()
     sleep(1)
    # temp.generateTemp()
    def setUp(self):
        self.sd = SensorData()
        self.sd.addValue(11)
        self.sdm = SensorDataManager()
        self.actuator = ActuatorData()
        self.actuator.setCommand("Raise Temp")
        self.sdm.threshold = 20
        self.tsa = TempSensorAdaptor()
        self.taa = TempActuatorAdaptor()
        self.tat = TempSensorAdaptorTask()
        self.shla = SenseHatLedActivator()

        pass
Beispiel #6
0
 def setUp(self):
     self.config = ConfigUtil()
     self.config.loadConfig('../../../config/ConnectedDevicesConfig.props')
     self.tempsensor = TempSensorAdaptorTask()
     self.sensordata = SensorData()
     self.actuatordata = ActuatorData()
     self.sensordata.addValue(10)
     self.sensordata.addValue(15)
     self.sensordata.addValue(20)
     self.sensordata.addValue(25)
     self.sensordata.setName('Temperature')
     self.actuatordata.setCommand('Increasing')
     self.actuatordata.setName('SenseHat')
     self.sdmanager = SensorDataManager()
Beispiel #7
0
class TempSensorAdaptor(threading.Thread):
    def __init__(self):
        logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s',
                            level=logging.INFO,
                            datefmt='%Y-%m-%d %H:%M:%S')
        logging.info("started logging")
        threading.Thread.__init__(self)
        self.sensor_object = TempSensorAdaptorTask(20)
        self.sensor_object.start()  # Starting Threaded Class Object

    '''    
    Standard getter function to return the instance of TempSensorAdaptor
    '''

    def getSensorobj(self):
        return self.sensor_object
 def setUp(self):
     #self.adaptor= TempSensorAdaptorTask.getteravg()
     self.datamanager_avg = SensorDataManager().getteravg()
     self.datamanager_current = SensorDataManager().gettercurrent()
     self.datamanager_count = SensorDataManager().gettercount()
     self.adaptorTask_sensor = TempSensorAdaptorTask()
     self.sensorAdaptor = TempSensorAdaptor()
class TempSensorAdaptor(object):
    '''
    classdocs
    '''

    #initialize TempSensorAdaptorTask
    tempSensorAdaptorTask = TempSensorAdaptorTask()

    def __init__(self):
        '''
        Constructor
        '''
        
    #method for creating and running the thread    
    def run(self):
        
        #log the initial message
        logging.info("Starting getTemperature thread()")
        
        #try the running thread
        try:
        
            #enable the temperature fetcher
            self.tempSensorAdaptorTask.enableFetcher = True
            
            #create the thread that calls the getTemperature() method of the tempSensorAdaptorTask
            threadTempSensorAdaptor = threading.Thread(target = self.tempSensorAdaptorTask.getTemperature())
            
            #set the temp sensor adaptor daemon to true (enable main thread to exit when done)
            threadTempSensorAdaptor.daemon = True
          
        #if found error  
        except:
            
            #return false
            return False
        
        #return true for running successfully
        return True
        
Beispiel #10
0
    def __init__(self):  #constructor of TempSensorAdaptor
        '''
        Starting the threads for all the three classes of sensors 
        '''
        while True:
            temp = TempSensorAdaptorTask(
                "Temp Sensor"
            )  #object of class TempSensorAdaptorTask is created
            humidity1 = HumiditySensorAdaptorTask(
                "Humidity sensor"
            )  #object of class HumiditySensorAdaptorTask is created
            humidity2 = HI2CSensorAdaptorTask(
                "I2C Sensor"
            )  #object of class HI2CSensorAdaptorTask is created
            temp.start()  #Thread is started
            temp.join()  #Thread is put on wait until it finishes

            humidity1.start()  #Thread is started
            humidity1.join()  #Thread is put on wait until it finishes

            humidity2.start()  #Thread is started
            humidity2.join()  #Thread is put on wait until it finishes
Beispiel #11
0
    def adaptor(self):

        result = TempSensorAdaptorTask()
        result.run()
Beispiel #12
0
class Module03Test(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.
	"""
    #initialize the rgb values for the led colors

    #no color
    e = [0, 0, 0]

    #red
    r = [255, 0, 0]

    #blue
    b = [0, 0, 255]

    #initialize the red arrow when increasing the temperature on sense hat led matrix
    arrowRedInc = [
        e, e, e, r, r, e, e, e, e, e, r, r, r, r, e, e, e, r, e, r, r, e, r, e,
        r, e, e, r, r, e, e, r, e, e, e, r, r, e, e, e, e, e, e, r, r, e, e, e,
        e, e, e, r, r, e, e, e, e, e, e, r, r, e, e, e
    ]

    #initialize the blue arrow when decreasing the temperature on sense hat led matrix
    arrowBlueDec = [
        e, e, e, b, b, e, e, e, e, e, e, b, b, e, e, e, e, e, e, b, b, e, e, e,
        e, e, e, b, b, e, e, e, b, e, e, b, b, e, e, b, e, b, e, b, b, e, b, e,
        e, e, b, b, b, b, e, e, e, e, e, b, b, e, e, e
    ]

    def setUp(self):

        #instantiate the classes required
        self.sensorDataManager = SensorDataManager()
        self.tempActuatorAdaptor = TempActuatorAdaptor()
        self.tempSensorAdaptor = TempSensorAdaptor()
        self.tempSensorAdaptorTask = TempSensorAdaptorTask()

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

        #set the reference to the variables as none to release the resources they're holding
        self.sensorDataManager = None
        self.tempActuatorAdaptor = None
        self.tempSensorAdaptor = None
        self.tempSensorAdaptorTask = None
        pass

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

    def testGetHandleSensorData(self):

        #initialize sensor data
        sensorData = SensorData()

        #when current value is greater than nominal temp
        sensorData.addValue(90)

        #get the actuatorData returned from the sensor data manager
        actuatorData = self.sensorDataManager.handleSensorData(sensorData)

        #check if actuatorData is of type ActuatorData
        self.assertIsInstance(actuatorData, ActuatorData)

        #test the value, which should be "arrowBlueDec"
        self.assertEqual(self.arrowBlueDec, actuatorData.getValue())

        #actuatorData command should be decrease temp
        self.assertEqual(actuatorData.getCommand(), "DECREASE TEMP")

        #when current value is less than nominal temp
        sensorData.addValue(10)

        #get the actuatorData returned from the sensor data manager
        actuatorData = self.sensorDataManager.handleSensorData(sensorData)

        #check if actuatorData is of type ActuatorData
        self.assertIsInstance(actuatorData, ActuatorData)

        #actuatorData command should be increase temp
        self.assertEqual(actuatorData.getCommand(), "INCREASE TEMP")

        #when current value is equal to the nominal temp
        sensorData.addValue(20)

        #get the actuatorData returned from the sensor data manager
        actuatorData = self.sensorDataManager.handleSensorData(sensorData)

        #actuatorData is none sensor data equal to nominal temp
        self.assertEqual(actuatorData, None)

        pass

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

        #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 TempActuatorAdaptor, it checks whether the actuator is updated 
	(by returning an actuatorData reference) when the trigger is valid (INCREASE TEMP) and when the trigger is invalid 
	(NOT A VALID TRIGGER)
	"""

    def testUpdateActuator(self):

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

        #add a valid value
        actuatorData.setValue(self.arrowBlueDec)

        #updateActuator should return a false
        self.assertEqual(False,
                         self.tempActuatorAdaptor.updateActuator(actuatorData))

        #create a valid actuator trigger
        actuatorData = ActuatorData()
        actuatorData.setCommand("INCREASE TEMP")
        actuatorData.setValue(self.arrowRedInc)

        #updateActuator should return a True
        self.assertEqual(True,
                         self.tempActuatorAdaptor.updateActuator(actuatorData))

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

        pass

    """
	This tests the getTemperature() method of the TempSensorAdaptorTask, it checks whether the fetcher runs when enabled,
	disabled, number of readings to get has been set to 0.
	"""

    def testGetTemperature(self):

        #enable the fetcher
        self.tempSensorAdaptorTask.enableFetcher = True

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

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

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

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

        #run when numReadings = 0 and emulator is enabled, should return false because generator didn't run
        self.assertEqual(False, self.tempSensorAdaptorTask.getTemperature())

        #disable the emulator
        self.tempSensorAdaptorTask.enableFetcher = False

        #change readings to > 0
        self.tempSensorAdaptorTask.numReadings = 1

        #run when numReadings > 0 and emulator is disabled, should return false because generator didn't run
        self.assertEqual(False, self.tempSensorAdaptorTask.getTemperature())

    """
	This tests the run() method of the TempSensorAdaptor, it checks whether it runs successfully.
	"""

    def testTempSensorAdaptor(self):

        #get the reference to the tempSensorEmulatorTask
        tempSensTask = self.tempSensorAdaptor.tempSensorAdaptorTask

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

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

        #enable the tempEmulatorTask's emulator
        tempSensTask.enableFetcher = True

        #run the run function of tempEmulatorAdaptor and get the value of success of the adaptor
        self.assertEqual(True, self.tempSensorAdaptor.run())
Beispiel #13
0
class Module03Test(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.config = ConfigUtil()
        self.config.loadConfig('../../../config/ConnectedDevicesConfig.props')
        self.tempsensor = TempSensorAdaptorTask()
        self.sensordata = SensorData()
        self.actuatordata = ActuatorData()
        self.sensordata.addValue(10)
        self.sensordata.addValue(15)
        self.sensordata.addValue(20)
        self.sensordata.addValue(25)
        self.sensordata.setName('Temperature')
        self.actuatordata.setCommand('Increasing')
        self.actuatordata.setName('SenseHat')
        self.sdmanager = SensorDataManager()

    """
	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 testloadConfig(self):
        self.assertTrue(
            self.config.loadConfig(
                '../../../config/ConnectedDevicesConfig.props'))

    def testhasConfigData(self):
        self.assertTrue(self.config.hasConfigData())

    def testgetValue(self):
        self.assertEqual(self.config.getValue("smtp.cloud", "port"), '465')

    def testgetSensorData(self):
        assert self.tempsensor.getTemperature(
        ) > 0 and self.tempsensor.getTemperature() < 30

    def testgetAverageValue(self):
        assert self.sensordata.getAverageValue(
        ) > 0 and self.sensordata.getAverageValue() < 30

    def testgetCount(self):
        self.assertEqual(self.sensordata.getCount(), 4)

    def testgetCurrentValue(self):
        assert self.sensordata.getCurrentValue(
        ) > 0 and self.sensordata.getCurrentValue() < 30

    def testMinValue(self):
        assert self.sensordata.getMinValue(
        ) >= 0 and self.sensordata.getMinValue() < 30

    def testMaxValue(self):
        assert self.sensordata.getMaxValue(
        ) > 0 and self.sensordata.getMaxValue() < 30

    def testName(self):
        self.assertEqual(self.sensordata.getName(), 'Temperature')

    def testgetCommand(self):
        self.assertEqual(self.actuatordata.getCommand(), 'Increasing')

    def testName2(self):
        self.assertEqual(self.actuatordata.getName(), 'SenseHat')

    def testhandleSenseData(self):
        assert self.sdmanager.handleSensorData(self.sensordata) is not None
class Module03Test(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.sdm = SensorDataManager()
        self.actuator = ActuatorData()
        self.actuator.setCommand("Raise Temp")
        self.sdm.threshold = 20
        self.tsa = TempSensorAdaptor()
        self.taa = TempActuatorAdaptor()
        self.tat = TempSensorAdaptorTask()
        self.shla = SenseHatLedActivator()

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

    '@Test'

    def testreadSensorValueMax(self):
        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")
'''
Created on Feb 5, 2020

@author: sk199
'''
import logging
from time import sleep
from labs.module03.TempSensorAdaptorTask import TempSensorAdaptorTask

#logging.getLogger().setLevel(logging.DEBUG)
#logger = logging.getLogger(__name__)
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s',
                    level=logging.DEBUG)
logging.info("Starting temperature sensor adaptor  daemon thread...")

tempsensoradaptor = TempSensorAdaptorTask()
tempsensoradaptor.daemon = True
tempsensoradaptor.enableEmulator = True
tempsensoradaptor.start()

while (True):
    sleep(10)
    pass
 def __init__(self):
     self.sreader = TempSensorAdaptorTask()