Skip to content

Commit ff399fc

Browse files
authored
Merge pull request #9 from tekktrik/doc/doc-updates
Documentation updates
2 parents e61bb1e + 34a60aa commit ff399fc

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

adafruit_bd3491fs.py

Lines changed: 38 additions & 17 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,80 +139,95 @@ 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+
154161
.. code-block:: python
155-
bd3491fs.active_input = adafruit_bd3491fs.Input.A
162+
163+
bd3491fs.active_input = adafruit_bd3491fs.Input.A
164+
156165
"""
157166
return self._current_active_input
158167

159168
@active_input.setter
160-
def active_input(self, value):
169+
def active_input(self, value: int) -> None:
161170
self._input_selector = value
162171
self._current_active_input = value
163172

164173
@property
165-
def input_gain(self):
166-
"""The gain applied to all inputs equally"
174+
def input_gain(self) -> int:
175+
"""The gain applied to all inputs equally
176+
167177
This example sets the input gain to 10dB.
178+
168179
.. code-block:: python
169-
bd3491fs.input_gain = adafruit_bd3491fs.Level.10_DB""
180+
181+
bd3491fs.input_gain = adafruit_bd3491fs.Level.10_DB
182+
170183
"""
171184
return self._current_input_gain
172185

173186
@input_gain.setter
174-
def input_gain(self, value):
187+
def input_gain(self, value: int) -> None:
175188
allowed_gains = [0, 1, 2, 3, 4, 6, 8, 10]
176189
if not value in allowed_gains:
177190
raise ValueError("input gain must be one of 0, 2, 4, 6, 8, 12, 16, 20 dB")
178191
self._input_gain = value
179192
self._current_input_gain = value
180193

181194
@property
182-
def channel_1_attenuation(self):
195+
def channel_1_attenuation(self) -> int:
183196
"""The attenuation applied to channel 1 of the currently selected input pair in -dB.
184-
Maximum is -87dB. To mute set to 255
197+
Maximum is -87dB. To mute set to 255.
198+
185199
This example sets the attenuation for input channel 1 to -10dB.
200+
186201
.. code-block:: python
187-
bd3491fs.channel_1_attenuation = 10""
202+
203+
bd3491fs.channel_1_attenuation = 10
204+
188205
"""
189206
return self._current_ch1_attenuation
190207

191208
@channel_1_attenuation.setter
192-
def channel_1_attenuation(self, value):
209+
def channel_1_attenuation(self, value: int) -> None:
193210
if (value < 0) or ((value > 87) and (value != 255)):
194211
raise ValueError("channel 1 attenuation must be from 0-87db")
195212
self._ch1_attenuation = value
196213
self._current_ch1_attenuation = value
197214

198215
@property
199-
def channel_2_attenuation(self):
216+
def channel_2_attenuation(self) -> int:
200217
"""The attenuation applied to channel 2 of the currently selected input pair in -dB.
201-
Maximum is -87dB. To mute set to 255
218+
Maximum is -87dB. To mute set to 255.
219+
202220
This example sets the attenuation for input channel 2 to -10dB.
221+
203222
.. code-block:: python
204-
bd3491fs.channel_2_attenuation = 10""
223+
224+
bd3491fs.channel_2_attenuation = 10
225+
205226
"""
206227
return self._current_ch2_attenuation
207228

208229
@channel_2_attenuation.setter
209-
def channel_2_attenuation(self, value):
230+
def channel_2_attenuation(self, value: int) -> None:
210231
if (value < 0) or ((value > 87) and (value != 255)):
211232
raise ValueError("channel 2 attenuation must be from 0-87db")
212233
self._ch2_attenuation = value

0 commit comments

Comments
 (0)