-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAirTemperatureHumidity.py
36 lines (28 loc) · 1.42 KB
/
AirTemperatureHumidity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import math
import logging
logging.basicConfig(encoding='utf-8', level=logging.DEBUG)
from Sensoren.Sensor import Sensor
from Handler.SerialHandler import SerialHandler
class AirTemperatureHumidity(Sensor):
def __init__(self,name:str,collection:str,*args, **kwargs):
dataStructure={
"AirTemperature":{"dataType":float,"unit":"Grad","range":(-20,100)},
"AirHumidity":{"dataType":float,"unit":"Percent","range":(0,100)},
}
super().__init__(name=name,
collection=collection,
dataStructure=dataStructure,
*args,
**kwargs)
self.__deviceName = "SenseIT" #TODO AUslesen aus der Config anstatt hardcoded.
self.__serialHandler = SerialHandler(baudrate=19200)
#prüfe ob benötigtes Device vorhanden ist.
if(self.__serialHandler.check_for_device(self.__deviceName) == False):
raise Exception(f"Gerät {self.__deviceName} nicht vom SerialHandler gefunden")
def genData(self):
command = {"command":"AHT20Value"}
result = self.__serialHandler.send_dict(self.__deviceName,command,readResponse=True)
if("Error" in result.keys()):
raise TypeError("SenseIT hat AHT20 nicht gefunden")
#raise Exception(f"Gerät {self.__deviceName} schreibt: {result}")
return super().createData(result)