Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions circuitpython_typing/led.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 Alec Delaney
#
# SPDX-License-Identifier: MIT

"""
`circuitpython_typing.led`
================================================================================

Type annotation definitions for device drivers. Used for where LEDs are
type annotated.

* Author(s): Alec Delaney
"""

# # Protocol was introduced in Python 3.8.
try:
from typing import Union, Tuple, Protocol
except ImportError:
from typing_extensions import Protocol

ColorBasedColorUnion = Union[int, Tuple[int, int, int]]
FillBasedColorUnion = Union[ColorBasedColorUnion, Tuple[int, int, int, int]]


class ColorBasedLED(Protocol):
"""Protocol for LEDs using the :meth:`color` method"""

def color(self, value: ColorBasedColorUnion) -> None:
"""Sets the color of the LED"""
...


class FillBasedLED(Protocol):
"""Protocol for LEDs using the :meth:`fill` method"""

def fill(self, color: FillBasedColorUnion) -> None:
"""Sets the color of the LED"""
...