55
55
from adafruit_bus_device .i2c_device import I2CDevice
56
56
from micropython import const
57
57
58
+ try :
59
+ import typing # pylint: disable=unused-import
60
+ from busio import I2C
61
+ except ImportError :
62
+ pass
63
+
58
64
59
65
# Set I2C addresses:
60
66
_VEML6070_ADDR_ARA = const (0x18 >> 1 )
@@ -125,7 +131,9 @@ class VEML6070:
125
131
126
132
"""
127
133
128
- def __init__ (self , i2c_bus , _veml6070_it = "VEML6070_1_T" , ack = False ):
134
+ def __init__ (
135
+ self , i2c_bus : I2C , _veml6070_it : str = "VEML6070_1_T" , ack : bool = False
136
+ ) -> None :
129
137
# Check if the IT is valid
130
138
if _veml6070_it not in _VEML6070_INTEGRATION_TIME :
131
139
raise ValueError (
@@ -162,7 +170,7 @@ def __init__(self, i2c_bus, _veml6070_it="VEML6070_1_T", ack=False):
162
170
i2c_cmd .write (self .buf )
163
171
164
172
@property
165
- def uv_raw (self ):
173
+ def uv_raw (self ) -> int :
166
174
"""
167
175
Reads and returns the value of the UV intensity.
168
176
"""
@@ -176,7 +184,7 @@ def uv_raw(self):
176
184
return buffer [1 ] << 8 | buffer [0 ]
177
185
178
186
@property
179
- def ack (self ):
187
+ def ack (self ) -> int :
180
188
"""
181
189
Turns on or off the ACKnowledge function of the sensor. The ACK function will send
182
190
a signal to the host when the value of the sensed UV light changes beyond the
@@ -185,9 +193,9 @@ def ack(self):
185
193
return self ._ack
186
194
187
195
@ack .setter
188
- def ack (self , new_ack ) :
196
+ def ack (self , new_ack : int ) -> None :
189
197
if new_ack != bool (new_ack ):
190
- raise ValueError ("ACK must be 'True' or 'False' ." )
198
+ raise ValueError ("ACK must be '1' (On) or '0' (Off) ." )
191
199
self ._ack = int (new_ack )
192
200
self .buf [0 ] = (
193
201
self ._ack << 5
@@ -199,7 +207,7 @@ def ack(self, new_ack):
199
207
i2c_cmd .write (self .buf )
200
208
201
209
@property
202
- def ack_threshold (self ):
210
+ def ack_threshold (self ) -> int :
203
211
"""
204
212
The ACKnowledge Threshold, which alerts the host controller to value changes
205
213
greater than the threshold. Available settings are: :const:`0` = 102 steps;
@@ -208,7 +216,7 @@ def ack_threshold(self):
208
216
return self ._ack_thd
209
217
210
218
@ack_threshold .setter
211
- def ack_threshold (self , new_ack_thd ) :
219
+ def ack_threshold (self , new_ack_thd : int ) -> None :
212
220
if new_ack_thd not in (0 , 1 ):
213
221
raise ValueError ("ACK Threshold must be '0' or '1'." )
214
222
self ._ack_thd = int (new_ack_thd )
@@ -222,7 +230,7 @@ def ack_threshold(self, new_ack_thd):
222
230
i2c_cmd .write (self .buf )
223
231
224
232
@property
225
- def integration_time (self ):
233
+ def integration_time (self ) -> str :
226
234
"""
227
235
The Integration Time of the sensor, which is the refresh interval of the
228
236
sensor. The higher the refresh interval, the more accurate the reading is (at
@@ -232,7 +240,7 @@ def integration_time(self):
232
240
return self ._it
233
241
234
242
@integration_time .setter
235
- def integration_time (self , new_it ) :
243
+ def integration_time (self , new_it : str ) -> None :
236
244
if new_it not in _VEML6070_INTEGRATION_TIME :
237
245
raise ValueError (
238
246
"Integration Time invalid. Valid values are: " ,
@@ -249,7 +257,7 @@ def integration_time(self, new_it):
249
257
with self .i2c_cmd as i2c_cmd :
250
258
i2c_cmd .write (self .buf )
251
259
252
- def sleep (self ):
260
+ def sleep (self ) -> None :
253
261
"""
254
262
Puts the VEML6070 into sleep ('shutdown') mode. Datasheet claims a current draw
255
263
of 1uA while in shutdown.
@@ -258,7 +266,7 @@ def sleep(self):
258
266
with self .i2c_cmd as i2c_cmd :
259
267
i2c_cmd .write (self .buf )
260
268
261
- def wake (self ):
269
+ def wake (self ) -> None :
262
270
"""
263
271
Wakes the VEML6070 from sleep. :class:`VEML6070.uv_raw` will also wake from sleep.
264
272
"""
@@ -271,7 +279,7 @@ def wake(self):
271
279
with self .i2c_cmd as i2c_cmd :
272
280
i2c_cmd .write (self .buf )
273
281
274
- def get_index (self , _raw ) :
282
+ def get_index (self , _raw : int ) -> str :
275
283
"""
276
284
Calculates the UV Risk Level based on the captured UV reading. Requires the ``_raw``
277
285
argument (from :meth:`veml6070.uv_raw`). Risk level is available for Integration Times (IT)
0 commit comments