Skip to content

Commit 2c12658

Browse files
committed
REannotate ht16k33.py
1 parent 83025fe commit 2c12658

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

adafruit_ht16k33/ht16k33.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
from adafruit_bus_device import i2c_device
1515
from micropython import const
1616

17+
try:
18+
from typing import Union, List, Tuple, Optional
19+
from busio import I2C
20+
except ImportError:
21+
pass
22+
1723

1824
__version__ = "0.0.0+auto.0"
1925
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git"
@@ -28,7 +34,7 @@ class HT16K33:
2834
"""
2935
The base class for all displays. Contains common methods.
3036
31-
:param I2C i2c: The I2C bus object
37+
:param ~busio.I2C i2c: The I2C bus object
3238
:param int address: The I2C addess of the HT16K33.
3339
:param bool auto_write: True if the display should immediately change when
3440
set. If False, `show` must be called explicitly.
@@ -37,11 +43,11 @@ class HT16K33:
3743

3844
def __init__(
3945
self,
40-
i2c,
41-
address = 0x70,
42-
auto_write = True,
43-
brightness = 1.0,
44-
):
46+
i2c: I2C,
47+
address: Union[int, List[int], Tuple[int, ...]] = 0x70,
48+
auto_write: bool = True,
49+
brightness: float = 1.0,
50+
) -> None:
4551
if isinstance(address, (tuple, list)):
4652
self.i2c_device = []
4753
for addr in address:
@@ -60,18 +66,18 @@ def __init__(
6066
self.blink_rate = 0
6167
self.brightness = brightness
6268

63-
def _write_cmd(self, byte, i2c_index = 0):
69+
def _write_cmd(self, byte: int, i2c_index: int = 0) -> None:
6470
self._temp[0] = byte
6571
with self.i2c_device[i2c_index]:
6672
self.i2c_device[i2c_index].write(self._temp)
6773

6874
@property
69-
def blink_rate(self):
75+
def blink_rate(self) -> int:
7076
"""The blink rate. Range 0-3."""
7177
return self._blink_rate
7278

7379
@blink_rate.setter
74-
def blink_rate(self, rate = None):
80+
def blink_rate(self, rate: int) -> None:
7581
if not 0 <= rate <= 3:
7682
raise ValueError("Blink rate must be an integer in the range: 0-3")
7783
rate = rate & 0x03
@@ -82,12 +88,12 @@ def blink_rate(self, rate = None):
8288
)
8389

8490
@property
85-
def brightness(self):
91+
def brightness(self) -> float:
8692
"""The brightness. Range 0.0-1.0"""
8793
return self._brightness
8894

8995
@brightness.setter
90-
def brightness(self, brightness):
96+
def brightness(self, brightness: float) -> None:
9197
if not 0.0 <= brightness <= 1.0:
9298
raise ValueError(
9399
"Brightness must be a decimal number in the range: 0.0-1.0"
@@ -100,18 +106,18 @@ def brightness(self, brightness):
100106
self._write_cmd(_HT16K33_CMD_BRIGHTNESS | xbright, index)
101107

102108
@property
103-
def auto_write(self):
109+
def auto_write(self) -> bool:
104110
"""Auto write updates to the display."""
105111
return self._auto_write
106112

107113
@auto_write.setter
108-
def auto_write(self, auto_write):
114+
def auto_write(self, auto_write: bool) -> None:
109115
if isinstance(auto_write, bool):
110116
self._auto_write = auto_write
111117
else:
112118
raise ValueError("Must set to either True or False.")
113119

114-
def show(self):
120+
def show(self) -> None:
115121
"""Refresh the display and show the changes."""
116122
for index, i2c_dev in enumerate(self.i2c_device):
117123
with i2c_dev:
@@ -121,7 +127,7 @@ def show(self):
121127
buffer = self._buffer[offset : offset + self._buffer_size]
122128
i2c_dev.write(buffer)
123129

124-
def fill(self, color):
130+
def fill(self, color: bool) -> None:
125131
"""Fill the whole display with the given color.
126132
127133
:param bool color: Whether to fill the display
@@ -134,7 +140,7 @@ def fill(self, color):
134140
if self._auto_write:
135141
self.show()
136142

137-
def _pixel(self, x, y, color = None):
143+
def _pixel(self, x: int, y: int, color: Optional[bool] = None) -> Optional[bool]:
138144
offset = ((x // 16) + (y // 8)) * self._buffer_size
139145
addr = 2 * (y % 8) + ((x % 16) // 8)
140146
addr = (addr % 16) + offset
@@ -151,8 +157,8 @@ def _pixel(self, x, y, color = None):
151157
self.show()
152158
return None
153159

154-
def _set_buffer(self, i, value):
160+
def _set_buffer(self, i: int, value: int) -> None:
155161
self._buffer[i + 1] = value # Offset by 1 to move past register address.
156162

157-
def _get_buffer(self, i):
163+
def _get_buffer(self, i: int) -> int:
158164
return self._buffer[i + 1] # Offset by 1 to move past register address.

0 commit comments

Comments
 (0)