30
30
import time
31
31
from os import uname
32
32
from digitalio import DigitalInOut , Pull , Direction
33
- from microcontroller import Pin
34
33
35
34
_USE_PULSEIO = False
36
35
try :
40
39
except (ImportError , NotImplementedError ):
41
40
pass # This is OK, we'll try to bitbang it!
42
41
42
+ try :
43
+ # Used only for typing
44
+ from typing import Union
45
+ from microcontroller import Pin
46
+ except ImportError :
47
+ pass
43
48
44
49
__version__ = "0.0.0-auto.0"
45
50
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DHT.git"
@@ -61,8 +66,8 @@ def __init__(self, dht11: bool, pin: Pin, trig_wait: int, use_pulseio: bool):
61
66
self ._pin = pin
62
67
self ._trig_wait = trig_wait
63
68
self ._last_called : float = 0
64
- self ._humidity : int | float | None = None
65
- self ._temperature : int | float | None = None
69
+ self ._humidity : Union [ int , float , None ] = None
70
+ self ._temperature : Union [ int , float , None ] = None
66
71
self ._use_pulseio = use_pulseio
67
72
if "Linux" not in uname () and not self ._use_pulseio :
68
73
raise Exception ("Bitbanging is not supported when using CircuitPython." )
@@ -198,8 +203,8 @@ def measure(self) -> None:
198
203
):
199
204
self ._last_called = time .monotonic ()
200
205
201
- new_temperature : int | float = 0
202
- new_humidity : int | float = 0
206
+ new_temperature : Union [ int , float ] = 0
207
+ new_humidity : Union [ int , float ] = 0
203
208
204
209
if self ._use_pulseio :
205
210
pulses = self ._get_pulses_pulseio ()
@@ -251,7 +256,7 @@ def measure(self) -> None:
251
256
self ._humidity = new_humidity
252
257
253
258
@property
254
- def temperature (self ) -> int | float | None :
259
+ def temperature (self ) -> Union [ int , float , None ] :
255
260
"""temperature current reading. It makes sure a reading is available
256
261
257
262
Raises RuntimeError exception for checksum failure and for insufficient
@@ -261,7 +266,7 @@ def temperature(self) -> int | float | None:
261
266
return self ._temperature
262
267
263
268
@property
264
- def humidity (self ) -> int | float | None :
269
+ def humidity (self ) -> Union [ int , float , None ] :
265
270
"""humidity current reading. It makes sure a reading is available
266
271
267
272
Raises RuntimeError exception for checksum failure and for insufficient
0 commit comments