Skip to content

Commit 34a60aa

Browse files
committed
Add type annotations
1 parent abecce7 commit 34a60aa

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

adafruit_bd3491fs.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
import adafruit_bus_device.i2c_device as i2cdevice
3636
from adafruit_register.i2c_struct import UnaryStruct
3737

38+
try:
39+
import typing # pylint: disable=unused-import
40+
from busio import I2C
41+
except ImportError:
42+
pass
43+
3844
_INPUT_SELECTOR = const(0x04)
3945
_INPUT_GAIN = const(0x06)
4046
_VOLUME_GAIN_CH1 = const(0x21)
@@ -133,21 +139,21 @@ class BD3491FS: # pylint: disable=too-many-instance-attributes
133139
_ch2_attenuation = UnaryStruct(_VOLUME_GAIN_CH2, "<B")
134140
_system_reset = UnaryStruct(_SYSTEM_RESET, "<B")
135141

136-
def __init__(self, i2c_bus):
142+
def __init__(self, i2c_bus: I2C) -> None:
137143
self.i2c_device = i2cdevice.I2CDevice(i2c_bus, 0x41)
138144
self._current_active_input = 7 # mute
139145
self._current_input_gain = 0 # 0dB
140146
self._current_ch1_attenuation = 255 # muted
141147
self._current_ch2_attenuation = 255 # muted
142148
self.reset()
143149

144-
def reset(self):
150+
def reset(self) -> None:
145151
"""Reset the sensor, muting the input, reducting input gain to 0dB, and the output channnel
146152
attenuation to maximum"""
147153
self._reset = 0x81
148154

149155
@property
150-
def active_input(self):
156+
def active_input(self) -> int:
151157
"""The currently selected input. Must be an ``Input``
152158
153159
This example sets A1 and A2 to the active input pair.
@@ -160,12 +166,12 @@ def active_input(self):
160166
return self._current_active_input
161167

162168
@active_input.setter
163-
def active_input(self, value):
169+
def active_input(self, value: int) -> None:
164170
self._input_selector = value
165171
self._current_active_input = value
166172

167173
@property
168-
def input_gain(self):
174+
def input_gain(self) -> int:
169175
"""The gain applied to all inputs equally
170176
171177
This example sets the input gain to 10dB.
@@ -178,15 +184,15 @@ def input_gain(self):
178184
return self._current_input_gain
179185

180186
@input_gain.setter
181-
def input_gain(self, value):
187+
def input_gain(self, value: int) -> None:
182188
allowed_gains = [0, 1, 2, 3, 4, 6, 8, 10]
183189
if not value in allowed_gains:
184190
raise ValueError("input gain must be one of 0, 2, 4, 6, 8, 12, 16, 20 dB")
185191
self._input_gain = value
186192
self._current_input_gain = value
187193

188194
@property
189-
def channel_1_attenuation(self):
195+
def channel_1_attenuation(self) -> int:
190196
"""The attenuation applied to channel 1 of the currently selected input pair in -dB.
191197
Maximum is -87dB. To mute set to 255.
192198
@@ -200,14 +206,14 @@ def channel_1_attenuation(self):
200206
return self._current_ch1_attenuation
201207

202208
@channel_1_attenuation.setter
203-
def channel_1_attenuation(self, value):
209+
def channel_1_attenuation(self, value: int) -> None:
204210
if (value < 0) or ((value > 87) and (value != 255)):
205211
raise ValueError("channel 1 attenuation must be from 0-87db")
206212
self._ch1_attenuation = value
207213
self._current_ch1_attenuation = value
208214

209215
@property
210-
def channel_2_attenuation(self):
216+
def channel_2_attenuation(self) -> int:
211217
"""The attenuation applied to channel 2 of the currently selected input pair in -dB.
212218
Maximum is -87dB. To mute set to 255.
213219
@@ -221,7 +227,7 @@ def channel_2_attenuation(self):
221227
return self._current_ch2_attenuation
222228

223229
@channel_2_attenuation.setter
224-
def channel_2_attenuation(self, value):
230+
def channel_2_attenuation(self, value: int) -> None:
225231
if (value < 0) or ((value > 87) and (value != 255)):
226232
raise ValueError("channel 2 attenuation must be from 0-87db")
227233
self._ch2_attenuation = value

0 commit comments

Comments
 (0)