Skip to content

Commit 0429b55

Browse files
authored
Merge pull request #10 from process1183/asserts
Raise exceptions instead of using assert checks (fixes #8).
2 parents cf5e680 + f9b104d commit 0429b55

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

adafruit_drv2605.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ def mode(self):
167167

168168
@mode.setter
169169
def mode(self, val):
170-
assert 0 <= val <= 7
170+
if not 0 <= val <= 7:
171+
raise ValueError('Mode must be a value within 0-7!')
171172
self._write_u8(_DRV2605_REG_MODE, val)
172173

173174
@property
@@ -191,7 +192,8 @@ def library(self):
191192

192193
@library.setter
193194
def library(self, val):
194-
assert 0 <= val <= 6
195+
if not 0 <= val <= 6:
196+
raise ValueError('Library must be a value within 0-6!')
195197
self._write_u8(_DRV2605_REG_LIBRARY, val)
196198

197199
def set_waveform(self, effect_id, slot=0):
@@ -200,8 +202,10 @@ def set_waveform(self, effect_id, slot=0):
200202
datasheet for a complete table of effect ID values and the associated
201203
waveform / effect.
202204
"""
203-
assert 0 <= effect_id <= 123
204-
assert 0 <= slot <= 6
205+
if not 0 <= effect_id <= 123:
206+
raise ValueError('Effect ID must be a value within 0-123!')
207+
if not 0 <= slot <= 6:
208+
raise ValueError('Slot must be a value within 0-6!')
205209
self._write_u8(_DRV2605_REG_WAVESEQ1 + slot, effect_id)
206210

207211
# pylint: disable=invalid-name

0 commit comments

Comments
 (0)