Skip to content

Commit de7c7f4

Browse files
committed
Add typing annotations.
1 parent 9891c66 commit de7c7f4

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

adafruit_max9744.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards:
2525
https://github.com/adafruit/circuitpython/releases
2626
"""
27+
try:
28+
# Imports only used for typing.
29+
30+
# First check if the the typing module exists, to avoid loading
31+
# other typing-only modules when running under circuitpython.
32+
import typing # pylint: disable=unused-import
33+
import busio
34+
except ImportError:
35+
pass
36+
2737
from micropython import const
2838

2939
__version__ = "0.0.0+auto.0"
@@ -53,14 +63,14 @@ class MAX9744:
5363
# design!
5464
_BUFFER = bytearray(1)
5565

56-
def __init__(self, i2c, *, address=_MAX9744_DEFAULT_ADDRESS):
66+
def __init__(self, i2c: busio.I2C, *, address: int = _MAX9744_DEFAULT_ADDRESS):
5767
# This device doesn't use registers and instead just accepts a single
5868
# command string over I2C. As a result we don't use bus device or
5969
# other abstractions and just talk raw I2C protocol.
6070
self._i2c = i2c
6171
self._address = address
6272

63-
def _write(self, val):
73+
def _write(self, val: int) -> None:
6474
# Perform a write to update the amplifier state.
6575
try:
6676
# Make sure bus is locked before write.
@@ -73,7 +83,7 @@ def _write(self, val):
7383
# Ensure bus is always unlocked.
7484
self._i2c.unlock()
7585

76-
def _set_volume(self, volume):
86+
def _set_volume(self, volume: int) -> None:
7787
# Set the volume to the specified level (0-63).
7888
assert 0 <= volume <= 63
7989
self._write(_MAX9744_COMMAND_VOLUME | (volume & 0x3F))
@@ -82,14 +92,15 @@ def _set_volume(self, volume):
8292
volume = property(
8393
None,
8494
_set_volume,
95+
None,
8596
"Set the volume of the amplifier. Specify a value from 0-63 where 0 is muted/off and 63 is maximum volume.",
8697
)
8798
# pylint: enable=line-too-long
8899

89-
def volume_up(self):
100+
def volume_up(self) -> None:
90101
"""Increase the volume by one level."""
91102
self._write(_MAX9744_COMMAND_VOLUME_UP)
92103

93-
def volume_down(self):
104+
def volume_down(self) -> None:
94105
"""Decrease the volume by one level."""
95106
self._write(_MAX9744_COMMAND_VOLUME_DOWN)

0 commit comments

Comments
 (0)