Ejemplo n.º 1
1
 def test_1(self):
     t = Temperature("64f")
     self.assertEquals(t.value, 64)
     self.assertEquals(t._Temperature__scale, "F")
     t.value = "100k"
     self.assertEquals(t.value, 100)
     self.assertEquals(t._Temperature__scale, "K")
Ejemplo n.º 2
0
 def __init__(self, refPath, dataPath, dbFilename):
     GPIO.cleanup()
     GPIO.setmode(GPIO.BCM)
     GPIO.setup(self.AUTO_START_GPIO_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
     self.__i2c = I2C(2)
     self.__analog = Analog(sel.__i2c.getLock(), 0x49)
     self.default = Default()
     self.database = Database(dataPath, dbFilename)
     self.waterlevel = Waterlevel(debug, self.database)
     self.light = Light(self.database)
     self.curtain = Curtain(self.database)
     self.pressure = Pressure(self.database, self.default, self.__analog)
     self.temperature = Temperature("28-0417716a37ff", self.database)
     self.redox = Redox(debug, self.database, self.default, self.__analog)
     self.ph = PH(debug, self.database, self.default, self.__analog,
                  self.temperature)
     self.robot = Robot(debug, self.database)
     self.pump = Pump(debug, self.database, self.default, self.robot,
                      self.redox, self.ph, self.temperature)
     self.panel = Panel(debug, self.database, self.default, self.pump,
                        self.redox, self.ph, self.__i2c)
     self.statistic = Statistic(debug, self.pump, self.robot, self.redox,
                                self.ph, self.temperature, self.pressure,
                                self.waterlevel)
     self.refPath = refPath
     self.__autoSaveTick = 0
     self.__today = date.today().day - 1
     debug.TRACE(debug.DEBUG, "Initialisation done (Verbosity level: %s)\n",
                 debug)
Ejemplo n.º 3
0
	def __init__(self):
		self.number = '+4917621929963'
		self.pictureInterval = 20
		self.temperatureInterval = 60
		self.smsListeningInterval = 10
		self.gpsReportingInterval = 120
		self.threadLockNumberReports = 0
		self.threadLockNumberPictures = 0
		self.threadLockNumberTemperature = 0
		self.threadLockNumberGpsTime = 0
		self.sendGPSSMS = False
		self.pictureDir = "/root/pictures"
		self.sendTemperature = False
		self.getTimeFromGpsLoop = True
		self.gpsParser = GpsParser()
		self.temperatureClass = Temperature()
		
		try:
			# Create state machine object
			self.sm = gammu.StateMachine()
			# Read ~/.gammurc
			self.sm.ReadConfig(Filename = "/root/.gammurc")
			# Connect to phone
			self.sm.Init()
		except Exception as e:
			# Unplugging the UMTS stick requires a restart
			print e
			self.logMessage(e, "__init__")
			if e.Code == 4:
				print "restarting in 300 sec..."
				time.sleep(300)
				os.system("reboot")
Ejemplo n.º 4
0
 def test_1(self):
     t = Temperature("64f")
     self.assertEquals(t.value, 64)
     self.assertEquals(t._Temperature__scale, "F")
     t.value = "100k"
     self.assertEquals(t.value, 100)
     self.assertEquals(t._Temperature__scale, "K")
Ejemplo n.º 5
0
 def test_6(self):
     Temperature.set_default_scale("f")
     t = Temperature("100")
     self.assertEquals(str(t), "100F")
     Temperature.set_default_scale("k")
     t = Temperature("-50")
     self.assertEquals(str(t), "-50K")
Ejemplo n.º 6
0
 def test_5(self):  # Kelvin + Celsius
     t1 = Temperature("273.15K")
     t2 = Temperature("0C")
     t3 = t1 - t2
     self.assertEquals(t3.value, 0)
     self.assertEquals(t3.scale, "K")
     self.assertEquals(t3.dscale, "K")
Ejemplo n.º 7
0
 def test_making_training_set(self):
     precipitation = {
         170101: Precipitation(17, 1, 1, 20, 123456),
         170102: Precipitation(17, 1, 2, 0.5, 123456)
     }
     water_level = {
         170101: Water_level(17, 1, 1, 0.5),
         170102: Water_level(17, 1, 2, 0.38)
     }
     max_temperature = {
         170101: Temperature(17, 1, 1, 30.5, 123456),
         170102: Temperature(17, 1, 2, 25.4, 123456)
     }
     min_temperature = {
         170101: Temperature(17, 1, 1, 21.3, 123456),
         170102: Temperature(17, 1, 2, 19.8, 123456)
     }
     solar_exposure = {
         170101: Solar(17, 1, 1, 30.6, 123456),
         170102: Solar(17, 1, 2, 20.1, 123456)
     }
     precipitation_key = [170101, 170102]
     water_level_key = [170101, 170102]
     max_temperature_key = [170101, 170102]
     min_temperature_key = [170101, 170102]
     solar_exposure_key = [170101, 170102]
     result = [[30.5, 21.3, 20, 30.6, 0.5], [25.4, 19.8, 0.5, 20.1, 0.38]]
     self.assertEqual(
         methods.making_training_set(precipitation, water_level,
                                     max_temperature, min_temperature,
                                     solar_exposure, precipitation_key,
                                     water_level_key, max_temperature_key,
                                     min_temperature_key,
                                     solar_exposure_key), result)
Ejemplo n.º 8
0
 def test_4(self):  # Fahrenheit + Celsius
     t1 = Temperature("32F")
     t2 = Temperature("0C")
     t1.dscale = "K"
     t2.dscale = "K"
     t3 = t1 - t2
     self.assertEquals(t3.value, 0)
     self.assertEquals(t3.scale, "K")
     self.assertEquals(t3.dscale, "K")
def senseTempAndDisplay():
    sense = SenseHat()
    while True:
        temp = int(round(float(sense.get_temperature())))

        temperature = Temperature(temp, coldMax, hotMin, comfortableMax,
                                  comfortableMin, sense)
        temperature.checkAndDisplay()

        sleep(10)
Ejemplo n.º 10
0
 def test_6_average(self):
     """Test if averaging works as specified."""
     average_temperature = Temperature.average(
         [Temperature(temp) for temp in VALID_TEMPERATURES]).celsius
     self.assertTrue(
         equal_to_n_decimal_places(AVERAGE_TEMPERATURE, average_temperature,
                                   4),
         f"Average temperature should be {AVERAGE_TEMPERATURE} "
         f"degrees celsius, but is {average_temperature} "
         "degrees celsius")
Ejemplo n.º 11
0
def processtemp(amount, inputunit, outputunit):
  degrees = Temperature(temperature=amount, system=inputunit)

  if outputunit == 'celsius':
    printtemperature(temp=degrees.celsius(), unit=outputunit)
  elif outputunit == 'fahrenheit':
    printtemperature(temp=degrees.fahrenheit(), unit=outputunit)
  elif outputunit == 'kalvin':
    printtemperature(temp=degrees.kalvin(), unit=outputunit)
  elif outputunit == 'rankine':
    printtemperature(temp=degrees.rankine(), unit=outputunit)
Ejemplo n.º 12
0
 def test_notequal(self):
     t1 = Temperature()
     t2 = Temperature("273.15k")
     t3 = Temperature("32F")
     t4 = Temperature("100")
     t5 = Temperature("100F")
     self.assertEquals(t1 != t2, False)
     self.assertEquals(t1 != t3, False)
     self.assertEquals(t2 != t3, False)
     self.assertEquals(t3 <> t4, True)
     self.assertEquals(t3 <> t5, True)
     self.assertEquals(t4 <> t5, True)
Ejemplo n.º 13
0
 def test_equal(self):
     t1 = Temperature()
     t2 = Temperature("273.15k")
     t3 = Temperature("32F")
     t4 = Temperature("100")
     t5 = Temperature("100F")
     self.assertEquals(t1 == t2, True)
     self.assertEquals(t1 == t3, True)
     self.assertEquals(t2 == t3, True)
     self.assertEquals(t3 == t4, False)
     self.assertEquals(t3 == t5, False)
     self.assertEquals(t4 == t5, False)
Ejemplo n.º 14
0
 def test_less_than_or_equal(self):
     t1 = Temperature()
     t2 = Temperature("273.15k")
     t3 = Temperature("32F")
     t4 = Temperature("100")
     t5 = Temperature("100F")
     self.assertEquals(t1 <= t2, True)
     self.assertEquals(t1 <= t3, True)
     self.assertEquals(t2 <= t3, True)
     self.assertEquals(t5 <= t3, False)
     self.assertEquals(t4 <= t1, False)
     self.assertEquals(t4 <= t2, False)
Ejemplo n.º 15
0
 def test_less_than(self):
     t1 = Temperature()
     t2 = Temperature("273.15k")
     t3 = Temperature("32F")
     t4 = Temperature("100")
     t5 = Temperature("100F")
     self.assertEquals(t1 < t2, False)
     self.assertEquals(t1 < t3, False)
     self.assertEquals(t2 < t3, False)
     self.assertEquals(t5 < t3, False)
     self.assertEquals(t3 < t5, True)
     self.assertEquals(t1 < t4, True)
Ejemplo n.º 16
0
def task1():
    count = 0
    while True:
        t = Temperature()
        _t = t.get_value()

        r.publish('temperature', _t)
        count += 1

        print 'count: ', count
        print 'temperature: ', _t
        gevent.sleep(0)
Ejemplo n.º 17
0
 def test_greater_than(self):
     t1 = Temperature()
     t2 = Temperature("273.15k")
     t3 = Temperature("32F")
     t4 = Temperature("100")
     t5 = Temperature("100F")
     self.assertEquals(t1 > t2, False)
     self.assertEquals(t1 > t3, False)
     self.assertEquals(t2 > t3, False)
     self.assertEquals(t4 > t1, True)
     self.assertEquals(t4 > t3, True)
     self.assertEquals(t5 > t3, True)
Ejemplo n.º 18
0
 def test_greater_than_or_equal(self):
     t1 = Temperature()
     t2 = Temperature("273.15k")
     t3 = Temperature("32F")
     t4 = Temperature("100")
     t5 = Temperature("100F")
     self.assertEquals(t1 >= t2, True)
     self.assertEquals(t1 >= t3, True)
     self.assertEquals(t2 >= t3, True)
     self.assertEquals(t3 >= t4, False)
     self.assertEquals(t3 >= t5, False)
     self.assertEquals(t5 >= t4, False)
Ejemplo n.º 19
0
 def handle(self, *args, **options):
     mTemp = Temperature(0)
     wTemp = Temperature(2)
     ws = create_connection("ws://127.0.0.1:8000/ws/")
     while True:
         #self.stdout.write(temp.getTemp())
         # print(temp.getTemp())
         m = mTemp.getTemp()
         Group("mTemp").send({'text': str(m)})
         ws.send(str(m))
         # Group("wTemp").send({'temp': wTemp.getTemp()})
         time.sleep(5)
Ejemplo n.º 20
0
        def temperature():
            # TODO request shouldn't be forwarded to application code
            temp = Temperature(request)

            if request.args.get("accuracy"):
                temp.set_accuracy(int(request.args.get("accuracy")))

            # TODO db_session is temporary here
            if request.method == 'GET':
                return temp.process_get(self.db_session)
            elif request.method == 'POST':
                return temp.process_post(self.db_session)
Ejemplo n.º 21
0
def task1():
    count = 0
    r = redis.Redis(host='localhost', port=6379, db=0)
    while True:
        t = Temperature()
        _t = t.get_value()

        r.set('temperature', _t)
        count += 1

        print 'count: ', count
        print 'temperature: ', _t
        gevent.sleep(0)
Ejemplo n.º 22
0
def task1():
    count = 0
    r = redis.Redis(host='localhost', port=6379, db=0)
    while True:            
        t = Temperature()
        _t = t.get_value()

        r.set('temperature', _t)
        count += 1

        print 'count: ', count
        print 'temperature: ', _t 
        gevent.sleep(0)
Ejemplo n.º 23
0
 def test_6(self):
     Temperature.set_default_scale("f")
     t1 = Temperature("1")
     t2 = Temperature("2")
     t3 = t1 + t2
     t4 = t2 + t3
     t5 = t3 + t4
     for i in range(1, 6):
         self.assertEquals(str(eval("t"+str(i)))[-1], "F")
     self.assertEquals(t1.dvalue, 1)
     self.assertEquals(t2.dvalue, 2)
     self.assertEquals(t3.dvalue, 3)
     self.assertEquals(t4.dvalue, 5)
     self.assertEquals(t5.dvalue, 8)
Ejemplo n.º 24
0
 def test_6(self):
     Temperature.set_default_scale("k")
     t1 = Temperature("10")
     t2 = Temperature("20")
     t3 = t1 - t2
     t4 = t2 - t3
     t5 = t3 - t4
     for i in range(1, 6):
         self.assertEquals(str(eval("t" + str(i)))[-1], "K")
     self.assertEquals(t1.dvalue, 10)
     self.assertEquals(t2.dvalue, 20)
     self.assertEquals(t3.dvalue, -10)
     self.assertEquals(t4.dvalue, 30)
     self.assertEquals(t5.dvalue, -40)
Ejemplo n.º 25
0
 def test_6(self):
     Temperature.set_default_scale("k")
     t1 = Temperature("10")
     t2 = Temperature("20")
     t3 = t1 - t2
     t4 = t2 - t3
     t5 = t3 - t4
     for i in range(1, 6):
         self.assertEquals(str(eval("t"+str(i)))[-1], "K")
     self.assertEquals(t1.dvalue, 10)
     self.assertEquals(t2.dvalue, 20)
     self.assertEquals(t3.dvalue, -10)
     self.assertEquals(t4.dvalue, 30)
     self.assertEquals(t5.dvalue, -40)
Ejemplo n.º 26
0
 def test_6(self):
     Temperature.set_default_scale("f")
     t1 = Temperature("1")
     t2 = Temperature("2")
     t3 = t1 + t2
     t4 = t2 + t3
     t5 = t3 + t4
     for i in range(1, 6):
         self.assertEquals(str(eval("t" + str(i)))[-1], "F")
     self.assertEquals(t1.dvalue, 1)
     self.assertEquals(t2.dvalue, 2)
     self.assertEquals(t3.dvalue, 3)
     self.assertEquals(t4.dvalue, 5)
     self.assertEquals(t5.dvalue, 8)
Ejemplo n.º 27
0
 def __init__(self, buss_id, address):
     self.gyro = Gyroscope(buss_id, address)
     self.gyro_full_scale = 245
     self.acc = Accelerometer(buss_id, address)
     self.acc_full_scale = 2
     self.fifo = Fifo(buss_id, address)
     self.temp = Temperature(buss_id, address)
Ejemplo n.º 28
0
def split_serial_values(string):
    data = str(string).split("'")[1]
    data = str(data).split("\\")[0]
    #values = list(filter(None, data))
    variable = data.split(':')[1]
    temperature_real = variable

    global c
    c += 0.5
    if (c >= 10):
        Temperature.add(temperature_real)
        print(temperature_real)
        c = 0
    Temperature.log_realtime
    print(c)
    print(temperature_real)
Ejemplo n.º 29
0
def main():
    # Setup the Rasp.IO LED Strings
    ledstrip = apa.Apa(led_config.numleds)  # initiate an LED strip
    ledstrip.zero_leds()
    ledstrip.write_leds()

    clock = ClockRing(ledstrip)
    clock.start()

    # Set up the handler class
    handlerclass = Temperature(ledstrip)
    # Start MQTT Listener
    Messages.MQTTMessages(config.mqttconfig, handlerclass)

    handlerclass.start()

    pause()
Ejemplo n.º 30
0
    def __init__(self, name, service, view, data, caller):
        Subject.__init__(self)

        self.observers = []
        self.name = name
        self.caller = caller
        self.temperature = Temperature(None)
        self.rainfall = Rainfall(None)
        self.timestamp = None
        self.datestamp = None

        self.serviceType = service
        self.viewType = view
        self.dataType = data

        self.client = None
        self.timer = None
        self.setupClient()
def get_weather(request):
	town = request.matchdict.get('town', 'Paris')
	temp_per = Temperature.get_by(city=town)
	temp = 0
	if temp_per:
		temp = temp_per.temperature
	else:
		d = weather.get_weather(town)
		temp = d[u'data'][u'current_condition'][0][u'temp_C']
		temp_per = Temperature(city=town, temperature=temp)
		temp_per.save()
	return Response("""
<div style="text-align: center">
	<div style="font-size: 72px">{}</div>
	<div style="font-size: 144px">{}°C</div>
	<div style="font-size: 24px">Current temperature</div>
</div>"""\
	.format(town, temp))
Ejemplo n.º 32
0
class Observation:
    """"""
    def __init__(self,
                 latitude=None,
                 longitude=None,
                 temperature=None,
                 precipitation=None,
                 humidity=None,
                 wind=None):
        """"""
        if temperature is None:
            self.temperature = Temperature()
        else:
            # TODO type check on input
            self.temperature = temperature  # Feels like, unit
        self.humidity = None
        self.summary = None
        self.icon = None
        self.date_time = None
        self.latitude = latitude  # TODO input validation
        self.longitude = longitude  # TODO input validation
        self.altitude = None
        if precipitation is None:
            self.precipitation = Precipitation()
        else:
            # TODO type check on input
            self.precipitation = precipitation

        # TODO type check on input
        self.humidity = Reading(humidity, "%")
        if wind is None:
            self.wind = Wind()
        else:
            # TODO type check on input
            self.wind = wind

        self.cloud_cover = None
        self.moon_phase = None
        self.uv_index = None
        self.is_daytime = None
        self.alerts = []
        self.unix = None

    def __str__(self):
        """"""
        # TODO handle empty location / time
        # TODO replace with parameters list
        return "<Observation lat/lon=" + str(self.latitude) + "/" + str(
            self.longitude) + " @" + str(self.date_time) + ">"

    def __repr__(self):
        """"""
        return '{is_daytime=' + self.is_daytime + ', precip_intensity=' + str(
            self.precipitation) + ', temperature=' + str(
                self.temperature) + ', feels_like=' + str(
                    self.temperature.feels_like()) + '}'
Ejemplo n.º 33
0
    def __init__(self):
        # self.URL = "http://192.168.179.227:5001"
        self.URL = "https://pruetpiflask.azurewebsites.net"
        self.token = self.login()
        self.temp_sensor = Temperature()
        self.outlets = Power()
        self.tz = pytz.timezone('US/Central')

        # default state
        self.state = {
            "Temperature": 0,
            "pH": 0,
            "Light_UV_On": True,
            "Light_Refugium_On": True,
            "GasInjection_On": True,
            "Heater_On": True,
            "Pump_Power": 3
        }

        asyncio.run(self.main())
Ejemplo n.º 34
0
 def convert_unit(self, value, input_unit, output_unit):
     if self.measurement is 'length':
         return Length(value, input_unit, output_unit).convert()
     if self.measurement is 'temperature':
         return Temperature(value, input_unit, output_unit).convert()
     if self.measurement is 'area':
         return Area(value, input_unit, output_unit).convert()
     if self.measurement is 'volume':
         return Volume(value, input_unit, output_unit).convert()
     if self.measurement is 'weight':
         return Weight(value, input_unit, output_unit).convert()
     return "Not a valid measurement is entered! Select from : length, temperature, volume, area, weight"
Ejemplo n.º 35
0
    def __init__(self,
                 latitude=None,
                 longitude=None,
                 temperature=None,
                 precipitation=None,
                 humidity=None,
                 wind=None):
        """"""
        if temperature is None:
            self.temperature = Temperature()
        else:
            # TODO type check on input
            self.temperature = temperature  # Feels like, unit
        self.humidity = None
        self.summary = None
        self.icon = None
        self.date_time = None
        self.latitude = latitude  # TODO input validation
        self.longitude = longitude  # TODO input validation
        self.altitude = None
        if precipitation is None:
            self.precipitation = Precipitation()
        else:
            # TODO type check on input
            self.precipitation = precipitation

        # TODO type check on input
        self.humidity = Reading(humidity, "%")
        if wind is None:
            self.wind = Wind()
        else:
            # TODO type check on input
            self.wind = wind

        self.cloud_cover = None
        self.moon_phase = None
        self.uv_index = None
        self.is_daytime = None
        self.alerts = []
        self.unix = None
Ejemplo n.º 36
0
 def test_6(self):
     Temperature.set_default_scale("f")
     t = Temperature("100")
     self.assertEquals(str(t), "100F")
     Temperature.set_default_scale("k")
     t = Temperature("-50")
     self.assertEquals(str(t), "-50K")
Ejemplo n.º 37
0
 def test_4_kelvin(self):
     """Test if kelvin property exists and is computed properly."""
     for temp_value, kelvin in zip(VALID_TEMPERATURES, KELVINS):
         temperature = Temperature(temp_value)
         try:
             self.assertTrue(
                 equal_to_n_decimal_places(temperature.kelvin, kelvin, 4),
                 f"Temperature temperature initialized with "
                 f"{temp_value} should have temperature.kelvin "
                 f"= {kelvin}, but it is "
                 f"{temperature.kelvin}")
         except AttributeError:
             self.fail(f"Temperature instance has no property " "kelvin.")
Ejemplo n.º 38
0
 def test_2_inits(self):
     """Test if the initializer properly sets celsius."""
     for temp_value, celsius in zip(VALID_TEMPERATURES, DEGREES_celsius):
         temperature = Temperature(temp_value)
         try:
             self.assertTrue(
                 equal_to_n_decimal_places(temperature.celsius, celsius, 4),
                 f"Temperature temperature initialized with "
                 f"{temp_value} should have temperature.celsius"
                 f" = {celsius}, but it is "
                 f"{temperature.celsius}")
         except AttributeError:
             self.fail(f"Temperature instance has no attribute " "celsius.")
Ejemplo n.º 39
0
def controlG(stop_event, arg):
	status = 0
	while not stop_event.is_set():
		temp = Temperature().getGlassT()
		if temp > 31 and status == 1:
			GPIO.output(20, True)
			status = 0
			print "Glass OFF"
		elif temp < 29 and status == 0:
			GPIO.output(20, False)
			status = 1
			print "Glass ON"
		time.sleep(10)
	print ("Thread killed: %s" % arg)
Ejemplo n.º 40
0
def controlC(stop_event, arg):
	status = 0
	while not stop_event.is_set():
		temp = Temperature().getConductT()
		if temp > 51 and status == 1:
			GPIO.output(16, True)
			status = 0
			print "Conduct OFF"
		elif temp < 49 and status == 0:
			GPIO.output(16, False)
			status = 1
			print "Conduct ON"
		time.sleep(10)
	print ("Thread killed: %s" % arg)
Ejemplo n.º 41
0
class Minimu:
    VERSION = 'minimu9v5'

    def __init__(self, buss_id, address):
        self.gyro = Gyroscope(buss_id, address)
        self.gyro_full_scale = 245
        self.acc = Accelerometer(buss_id, address)
        self.acc_full_scale = 2
        self.fifo = Fifo(buss_id, address)
        self.temp = Temperature(buss_id, address)

    def enable(self, odr=104):
        self.gyro.enable(odr)
        self.gyro_full_scale = self.gyro.get_full_scale_selection()
        self.acc.enable(odr)
        self.acc_full_scale = self.acc.get_full_scale_selection()
        self.fifo.enable(odr)

    def disable(self):
        self.gyro.disable()
        self.acc.disable()
        self.fifo.disable()

    def read_fifo_raw(self):
        data = np.array(self.fifo.get_data(), dtype=np.int)
        return data

    def read_fifo(self):
        data = np.array(self.fifo.get_data(), dtype=np.double)
        try:
            data[:, :3] *= 1
        except IndexError:
            sleep(0.1)
            data = np.array(self.fifo.get_data(), dtype=np.double)

        data[:, :3] *= self.gyro_full_scale
        data[:, -3:] *= self.acc_full_scale
        data[data > 0] /= 32767
        data[data < 0] /= 32768
        return data

    def read_temperature(self):
        return self.temp.get_temperature()
Ejemplo n.º 42
0
 def test_k2k(self):
     self.assertEquals(Temperature.k2k(100), 100)
Ejemplo n.º 43
0
 def test_2(self):
     t = Temperature("32.F")
     self.assertEquals(t.dvalue, 32)
     t.dscale = "C"
     self.assertEquals(t.dvalue, 0)
Ejemplo n.º 44
0
 def test_3(self):
     t = Temperature("0k")
     self.assertEquals(t.dvalue, 0)
     t.dscale = "c"
     self.assertEquals(t.dvalue, -273.15)
Ejemplo n.º 45
0
 def test_1(self):
     t = Temperature("100c")
     self.assertEquals(t.scale, "C")
     t.scale = "k"
     self.assertEquals(t.scale, "K")
Ejemplo n.º 46
0
 def tearDown(self):
     Temperature.set_default_scale(self.__oldDefaultScale)
Ejemplo n.º 47
0
 def test_1(self):
     t = Temperature("100C")
     with self.assertRaises(TypeError):
         t.value = [1, 2]
Ejemplo n.º 48
0
 def test_2(self):
     t = Temperature()
     with self.assertRaises(ValueError):
         t.value = "30h"
Ejemplo n.º 49
0
 def test_type_error3(self):  # not a str
     with self.assertRaises(TypeError):
         Temperature.set_default_scale(6)
Ejemplo n.º 50
0
 def setUp(self):
     Temperature.set_default_scale("C")
Ejemplo n.º 51
0
 def test_value_error2(self):  # not a single char str
     with self.assertRaises(ValueError):
         Temperature.set_default_scale("")
Ejemplo n.º 52
0
 def test_C(self):
     Temperature.set_default_scale("C")
     self.assertEquals(Temperature.DEFAULT_SCALE, 'C')
Ejemplo n.º 53
0
 def test_value_error3(self):  # not in ["c", "C", "f", "F", "k", "K"]
     with self.assertRaises(ValueError):
         Temperature.set_default_scale("a")
Ejemplo n.º 54
0
 def test_1(self):
     t = Temperature("-50.5F")
     self.assertEquals(t.value, -50.5)
     t.value = "90k"
     self.assertEquals(t.value, 90)
Ejemplo n.º 55
0
 def test_2(self):
     Temperature.set_default_scale("F")
     t = Temperature(32)
     self.assertEquals(str(t), "32F")
     t.scale = "c"
     self.assertEquals(t.scale, "C")
Ejemplo n.º 56
0
def get_temperature_demo():
    tempc = Temperature(sense)      # theoretically this should return the temperature in celsius from the sensehat
    print(tempc.temperature_c())    # it is untested however.
Ejemplo n.º 57
0
 def test_1(self):
     t = Temperature(100)
     self.assertEquals(t._Temperature__scale, Temperature.DEFAULT_SCALE)
     t.scale = "k"
     self.assertEquals(t._Temperature__scale, "K")
Ejemplo n.º 58
0
 def test_2(self):
     t = Temperature("32F")
     t.dscale = "c"
     t -= 32.
     self.assertEquals(t.value, 0)
Ejemplo n.º 59
0
 def setUp(self):
     self.__oldDefaultScale = Temperature.DEFAULT_SCALE
     Temperature.set_default_scale("C")
Ejemplo n.º 60
-1
    def read(self, path=None):
        #f6 01 4b 46 7f ff 0a 10 eb : crc=eb YES
        #f6 01 4b 46 7f ff 0a 10 eb t=31375

        path = self.path if not path else path
        temperature = Temperature()

        try:
            sensor = open(path, "r")
            data = sensor.readlines()
            sensor.close()

            if data[0].strip()[-3:] == "YES":
                equals_pos = data[1].find("t=")
                if equals_pos != -1:
                    temperature.set_data(data[1][equals_pos+2:])
                else:
                    raise IndexError
            else:
                raise IndexError
        except IndexError:
            print 'sensor read error'
            #temperature.set_error(index)
        except IOError:
            print 'sensor not connected'
            #temperature.set_error(io)
        except:
            print 'error'
            #temperature.set_error(other)

        return temperature