Skip to content

Commit cdd12b8

Browse files
authored
Change assertions to ValueErrors
#15
1 parent 7f16dc9 commit cdd12b8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

adafruit_ads1x15/differential.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def read_adc_difference(self, differential, gain=1, data_rate=None):
5151
- 2 = Channel 1 minus channel 3
5252
- 3 = Channel 2 minus channel 3
5353
"""
54-
assert 0 <= differential <= 3, 'Differential must be a value within 0-3!'
54+
if not 0 <= differential <= 3:
55+
raise ValueError('Differential must be a value within 0-3!')
5556
# Perform a single shot read using the provided differential value
5657
# as the mux value (which will enable differential mode).
5758
return self._read(differential, gain, data_rate, ADS1X15_CONFIG_MODE_SINGLE)
@@ -64,7 +65,8 @@ def read_volts_difference(self, differential, gain=1, data_rate=None):
6465
- 2 = Channel 1 minus channel 3
6566
- 3 = Channel 2 minus channel 3
6667
"""
67-
assert 0 <= differential <= 3, 'Differential must be a value within 0-3!'
68+
if not 0 <= differential <= 3:
69+
raise ValueError('Differential must be a value within 0-3!')
6870
raw = self.read_adc_difference(differential, gain, data_rate)
6971
volts = raw * (ADS1X15_PGA_RANGE[gain] / (2**(self.bits-1) - 1))
7072
return volts
@@ -80,7 +82,8 @@ def start_adc_difference(self, differential, gain=1, data_rate=None):
8082
function continuously to read the most recent conversion result. Call
8183
stop_adc() to stop conversions.
8284
"""
83-
assert 0 <= differential <= 3, 'Differential must be a value within 0-3!'
85+
if not 0 <= differential <= 3:
86+
raise ValueError('Differential must be a value within 0-3!')
8487
# Perform a single shot read using the provided differential value
8588
# as the mux value (which will enable differential mode).
8689
return self._read(differential, gain, data_rate, ADS1X15_CONFIG_MODE_CONTINUOUS)

0 commit comments

Comments
 (0)