2023-10-17 00:10:23 +02:00
|
|
|
import Adafruit_DHT
|
|
|
|
|
2023-12-24 15:07:26 +01:00
|
|
|
|
2024-03-03 15:58:12 +01:00
|
|
|
class Dht22Climate():
|
2023-10-17 00:10:23 +02:00
|
|
|
def __init__(self, pin):
|
2023-12-24 15:07:26 +01:00
|
|
|
super().__init__()
|
2023-10-17 00:19:51 +02:00
|
|
|
self.sensor = Adafruit_DHT.AM2302
|
2023-10-17 00:10:23 +02:00
|
|
|
self.pin = pin
|
|
|
|
|
|
|
|
def read(self):
|
|
|
|
humidity, temperature = Adafruit_DHT.read_retry(self.sensor, self.pin)
|
|
|
|
if humidity is not None and temperature is not None:
|
2023-12-24 15:07:26 +01:00
|
|
|
self.last_read = {"temperature": temperature, "humidity": humidity}
|
2023-10-17 17:57:32 +02:00
|
|
|
return self.last_read
|
2023-10-17 00:10:23 +02:00
|
|
|
else:
|
2023-10-17 17:57:32 +02:00
|
|
|
return None
|