5555from adafruit_bus_device .i2c_device import I2CDevice
5656from micropython import const
5757
58+ try :
59+ import typing # pylint: disable=unused-import
60+ from busio import I2C
61+ except ImportError :
62+ pass
63+
5864
5965# Set I2C addresses:
6066_VEML6070_ADDR_ARA = const (0x18 >> 1 )
@@ -125,7 +131,9 @@ class VEML6070:
125131
126132 """
127133
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 :
129137 # Check if the IT is valid
130138 if _veml6070_it not in _VEML6070_INTEGRATION_TIME :
131139 raise ValueError (
@@ -162,7 +170,7 @@ def __init__(self, i2c_bus, _veml6070_it="VEML6070_1_T", ack=False):
162170 i2c_cmd .write (self .buf )
163171
164172 @property
165- def uv_raw (self ):
173+ def uv_raw (self ) -> int :
166174 """
167175 Reads and returns the value of the UV intensity.
168176 """
@@ -176,7 +184,7 @@ def uv_raw(self):
176184 return buffer [1 ] << 8 | buffer [0 ]
177185
178186 @property
179- def ack (self ):
187+ def ack (self ) -> int :
180188 """
181189 Turns on or off the ACKnowledge function of the sensor. The ACK function will send
182190 a signal to the host when the value of the sensed UV light changes beyond the
@@ -185,9 +193,9 @@ def ack(self):
185193 return self ._ack
186194
187195 @ack .setter
188- def ack (self , new_ack ) :
196+ def ack (self , new_ack : int ) -> None :
189197 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) ." )
191199 self ._ack = int (new_ack )
192200 self .buf [0 ] = (
193201 self ._ack << 5
@@ -199,7 +207,7 @@ def ack(self, new_ack):
199207 i2c_cmd .write (self .buf )
200208
201209 @property
202- def ack_threshold (self ):
210+ def ack_threshold (self ) -> int :
203211 """
204212 The ACKnowledge Threshold, which alerts the host controller to value changes
205213 greater than the threshold. Available settings are: :const:`0` = 102 steps;
@@ -208,7 +216,7 @@ def ack_threshold(self):
208216 return self ._ack_thd
209217
210218 @ack_threshold .setter
211- def ack_threshold (self , new_ack_thd ) :
219+ def ack_threshold (self , new_ack_thd : int ) -> None :
212220 if new_ack_thd not in (0 , 1 ):
213221 raise ValueError ("ACK Threshold must be '0' or '1'." )
214222 self ._ack_thd = int (new_ack_thd )
@@ -222,7 +230,7 @@ def ack_threshold(self, new_ack_thd):
222230 i2c_cmd .write (self .buf )
223231
224232 @property
225- def integration_time (self ):
233+ def integration_time (self ) -> str :
226234 """
227235 The Integration Time of the sensor, which is the refresh interval of the
228236 sensor. The higher the refresh interval, the more accurate the reading is (at
@@ -232,7 +240,7 @@ def integration_time(self):
232240 return self ._it
233241
234242 @integration_time .setter
235- def integration_time (self , new_it ) :
243+ def integration_time (self , new_it : str ) -> None :
236244 if new_it not in _VEML6070_INTEGRATION_TIME :
237245 raise ValueError (
238246 "Integration Time invalid. Valid values are: " ,
@@ -249,7 +257,7 @@ def integration_time(self, new_it):
249257 with self .i2c_cmd as i2c_cmd :
250258 i2c_cmd .write (self .buf )
251259
252- def sleep (self ):
260+ def sleep (self ) -> None :
253261 """
254262 Puts the VEML6070 into sleep ('shutdown') mode. Datasheet claims a current draw
255263 of 1uA while in shutdown.
@@ -258,7 +266,7 @@ def sleep(self):
258266 with self .i2c_cmd as i2c_cmd :
259267 i2c_cmd .write (self .buf )
260268
261- def wake (self ):
269+ def wake (self ) -> None :
262270 """
263271 Wakes the VEML6070 from sleep. :class:`VEML6070.uv_raw` will also wake from sleep.
264272 """
@@ -271,7 +279,7 @@ def wake(self):
271279 with self .i2c_cmd as i2c_cmd :
272280 i2c_cmd .write (self .buf )
273281
274- def get_index (self , _raw ) :
282+ def get_index (self , _raw : int ) -> str :
275283 """
276284 Calculates the UV Risk Level based on the captured UV reading. Requires the ``_raw``
277285 argument (from :meth:`veml6070.uv_raw`). Risk level is available for Integration Times (IT)
0 commit comments