Skip to content

Commit 5ca81ee

Browse files
committed
Addressing PR comments
1 parent 641ba14 commit 5ca81ee

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ _build
4545
.idea
4646
.vscode
4747
*~
48-
.venv
48+
.env

adafruit_ads1x15/ads1015.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ class ADS1015(ADS1x15):
4141
"""Class for the ADS1015 12 bit ADC."""
4242

4343
@property
44-
def bits(self):
44+
def bits(self) -> int:
4545
"""The ADC bit resolution."""
4646
return 12
4747

4848
@property
49-
def rates(self):
49+
def rates(self) -> list[int]:
5050
"""Possible data rate settings."""
5151
r = list(_ADS1015_CONFIG_DR.keys())
5252
r.sort()
5353
return r
5454

5555
@property
56-
def rate_config(self):
56+
def rate_config(self) -> dict[int, int]:
5757
"""Rate configuration masks."""
5858
return _ADS1015_CONFIG_DR
5959

adafruit_ads1x15/ads1115.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ class ADS1115(ADS1x15):
4242
"""Class for the ADS1115 16 bit ADC."""
4343

4444
@property
45-
def bits(self):
45+
def bits(self) -> int:
4646
"""The ADC bit resolution."""
4747
return 16
4848

4949
@property
50-
def rates(self):
50+
def rates(self) -> list[int]:
5151
"""Possible data rate settings."""
5252
r = list(_ADS1115_CONFIG_DR.keys())
5353
r.sort()
5454
return r
5555

5656
@property
57-
def rate_config(self):
57+
def rate_config(self) -> dict[int, int]:
5858
"""Rate configuration masks."""
5959
return _ADS1115_CONFIG_DR
6060

adafruit_ads1x15/ads1x15.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,53 +86,58 @@ def __init__(
8686
self.i2c_device = I2CDevice(i2c, address)
8787

8888
@property
89-
def data_rate(self):
89+
def bits(self) -> int:
90+
"""The ADC bit resolution."""
91+
raise NotImplementedError("Subclass must implement bits property.")
92+
93+
@property
94+
def data_rate(self) -> int:
9095
"""The data rate for ADC conversion in samples per second."""
9196
return self._data_rate
9297

9398
@data_rate.setter
94-
def data_rate(self, rate: int):
99+
def data_rate(self, rate: int) -> None:
95100
possible_rates = self.rates
96101
if rate not in possible_rates:
97102
raise ValueError("Data rate must be one of: {}".format(possible_rates))
98103
self._data_rate = rate
99104

100105
@property
101-
def rates(self):
106+
def rates(self) -> list[int]:
102107
"""Possible data rate settings."""
103108
raise NotImplementedError("Subclass must implement rates property.")
104109

105110
@property
106-
def rate_config(self):
111+
def rate_config(self) -> dict[int, int]:
107112
"""Rate configuration masks."""
108113
raise NotImplementedError("Subclass must implement rate_config property.")
109114

110115
@property
111-
def gain(self):
116+
def gain(self) -> float:
112117
"""The ADC gain."""
113118
return self._gain
114119

115120
@gain.setter
116-
def gain(self, gain: float):
121+
def gain(self, gain: float) -> None:
117122
possible_gains = self.gains
118123
if gain not in possible_gains:
119124
raise ValueError("Gain must be one of: {}".format(possible_gains))
120125
self._gain = gain
121126

122127
@property
123-
def gains(self):
128+
def gains(self) -> list[float]:
124129
"""Possible gain settings."""
125130
g = list(_ADS1X15_CONFIG_GAIN.keys())
126131
g.sort()
127132
return g
128133

129134
@property
130-
def mode(self):
135+
def mode(self) -> int:
131136
"""The ADC conversion mode."""
132137
return self._mode
133138

134139
@mode.setter
135-
def mode(self, mode: int):
140+
def mode(self, mode: int) -> None:
136141
if mode not in (Mode.CONTINUOUS, Mode.SINGLE):
137142
raise ValueError("Unsupported mode.")
138143
self._mode = mode

adafruit_ads1x15/analog_in.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"""
1313

1414
try:
15-
from typing import Optional, cast
16-
15+
from typing import Optional
1716
from .ads1x15 import ADS1x15
1817
except ImportError:
1918
pass
@@ -38,7 +37,7 @@ def __init__(
3837
self._negative_pin = negative_pin
3938
self.is_differential = False
4039
if negative_pin is not None:
41-
pins = (self._pin_setting, cast(int, self._negative_pin))
40+
pins = (self._pin_setting, self._negative_pin)
4241
if pins not in _ADS1X15_DIFF_CHANNELS:
4342
raise ValueError(
4443
"Differential channels must be one of: {}".format(
@@ -49,14 +48,14 @@ def __init__(
4948
self.is_differential = True
5049

5150
@property
52-
def value(self):
51+
def value(self) -> int:
5352
"""Returns the value of an ADC pin as an integer."""
5453
return self._ads.read(
5554
self._pin_setting, is_differential=self.is_differential
5655
) << (16 - self._ads.bits)
5756

5857
@property
59-
def voltage(self):
58+
def voltage(self) -> float:
6059
"""Returns the voltage from the ADC pin as a floating point value."""
6160
volts = self.value * _ADS1X15_PGA_RANGE[self._ads.gain] / 32767
6261
return volts

0 commit comments

Comments
 (0)