Skip to content

Commit 982dee3

Browse files
authored
Merge pull request #11 from tekktrik/dev/led-types
Add type annotation protocols for LEDs
2 parents 9a0276f + 64f0a7d commit 982dee3

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

circuitpython_typing/led.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Alec Delaney
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
`circuitpython_typing.led`
7+
================================================================================
8+
9+
Type annotation definitions for device drivers. Used for where LEDs are
10+
type annotated.
11+
12+
* Author(s): Alec Delaney
13+
"""
14+
15+
# # Protocol was introduced in Python 3.8.
16+
try:
17+
from typing import Union, Tuple, Protocol
18+
except ImportError:
19+
from typing_extensions import Protocol
20+
21+
ColorBasedColorUnion = Union[int, Tuple[int, int, int]]
22+
FillBasedColorUnion = Union[ColorBasedColorUnion, Tuple[int, int, int, int]]
23+
24+
25+
class ColorBasedLED(Protocol):
26+
"""Protocol for LEDs using the :meth:`color` method"""
27+
28+
def color(self, value: ColorBasedColorUnion) -> None:
29+
"""Sets the color of the LED"""
30+
...
31+
32+
33+
class FillBasedLED(Protocol):
34+
"""Protocol for LEDs using the :meth:`fill` method"""
35+
36+
def fill(self, color: FillBasedColorUnion) -> None:
37+
"""Sets the color of the LED"""
38+
...

0 commit comments

Comments
 (0)