78
78
_ENABLE_PON = const (0x01 )
79
79
_GAINS = (1 , 4 , 16 , 60 )
80
80
_CYCLES = (0 , 1 , 2 , 3 , 5 , 10 , 15 , 20 , 25 , 30 , 35 , 40 , 45 , 50 , 55 , 60 )
81
+ _INTEGRATION_TIME_THRESHOLD_LOW = 2.4
82
+ _INTEGRATION_TIME_THRESHOLD_HIGH = 614.4
81
83
# pylint: enable=bad-whitespace
82
84
83
85
@@ -172,7 +174,9 @@ def integration_time(self):
172
174
173
175
@integration_time .setter
174
176
def integration_time (self , val ):
175
- assert 2.4 <= val <= 614.4
177
+ if not _INTEGRATION_TIME_THRESHOLD_LOW <= val <= _INTEGRATION_TIME_THRESHOLD_HIGH :
178
+ raise ValueError ("Integration Time must be between '{0}' and '{1}'" .format (
179
+ _INTEGRATION_TIME_THRESHOLD_LOW , _INTEGRATION_TIME_THRESHOLD_HIGH ))
176
180
cycles = int (val / 2.4 )
177
181
self ._integration_time = cycles * 2.4 # pylint: disable=attribute-defined-outside-init
178
182
self ._write_u8 (_REGISTER_ATIME , 256 - cycles )
@@ -186,7 +190,8 @@ def gain(self):
186
190
187
191
@gain .setter
188
192
def gain (self , val ):
189
- assert val in _GAINS
193
+ if val not in _GAINS :
194
+ raise ValueError ("Gain should be one of the following values: {0}" .format (_GAINS ))
190
195
self ._write_u8 (_REGISTER_CONTROL , _GAINS .index (val ))
191
196
192
197
@property
@@ -198,7 +203,8 @@ def interrupt(self):
198
203
199
204
@interrupt .setter
200
205
def interrupt (self , val ):
201
- assert not val
206
+ if val :
207
+ raise ValueError ("Interrupt should be set to False in order to clear the interrupt" )
202
208
with self ._device :
203
209
self ._device .write (b'\xe6 ' )
204
210
@@ -262,7 +268,8 @@ def cycles(self, val):
262
268
if val == - 1 :
263
269
self ._write_u8 (_REGISTER_ENABLE , enable & ~ (_ENABLE_AIEN ))
264
270
else :
265
- assert val in _CYCLES
271
+ if val not in _CYCLES :
272
+ raise ValueError ("Only the following values for cycles are permitted: {0}" .format (_CYCLES ))
266
273
self ._write_u8 (_REGISTER_ENABLE , enable | _ENABLE_AIEN )
267
274
self ._write_u8 (_REGISTER_APERS , _CYCLES .index (val ))
268
275
0 commit comments