Switch from mypy to pyright

This commit is contained in:
Edgar P. Burkhart 2024-12-09 13:25:00 +01:00
parent 7b26d3a160
commit cc0c978f0c
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
12 changed files with 1000 additions and 17 deletions

View file

@ -0,0 +1,19 @@
"""
This type stub file was generated by pyright.
"""
from .sense_hat import SenseHat
from .stick import (
ACTION_HELD,
ACTION_PRESSED,
ACTION_RELEASED,
DIRECTION_DOWN,
DIRECTION_LEFT,
DIRECTION_MIDDLE,
DIRECTION_RIGHT,
DIRECTION_UP,
InputEvent,
SenseStick,
)
__version__ = ...

View file

@ -0,0 +1,222 @@
"""
This type stub file was generated by pyright.
"""
"""
Python library for the TCS3472x and TCS340x Color Sensors
Documentation (including datasheet): https://ams.com/tcs34725#tab/documents
https://ams.com/tcs3400#tab/documents
The sense hat for AstroPi on the ISS uses the TCS34725.
The sense hat v2 uses the TCS3400 the successor of the TCS34725.
The TCS34725 is not available any more. It was discontinued by ams in 2021.
"""
class HardwareInterface:
"""
`HardwareInterface` is the abstract class that sits between the
`ColourSensor` class (providing the TCS34725/TCS3400 sensor API)
and the actual hardware. Using this intermediate layer of abstraction,
a `ColourSensor` object interacts with the hardware without being
aware of how this interaction is implemented.
Different subclasses of the `HardwareInterface` class can provide
access to the hardware through e.g. I2C, `libiio` and its system
files or even a hardware emulator.
"""
@staticmethod
def max_value(integration_cycles): # -> Literal[65535]:
"""
The maximum raw value for the RBGC channels depends on the number
of integration cycles.
"""
...
def get_enabled(self):
"""
Return True if the sensor is enabled and False otherwise
"""
...
def set_enabled(self, status):
"""
Enable or disable the sensor, depending on the boolean `status` flag
"""
...
def get_gain(self):
"""
Return the current value of the sensor gain.
See GAIN_VALUES for the set of possible values.
"""
...
def set_gain(self, gain):
"""
Set the value for the sensor `gain`.
See GAIN_VALUES for the set of possible values.
"""
...
def get_integration_cycles(self):
"""
Return the current number of integration_cycles (1-256).
It takes `integration_cycles` * CLOCK_STEP to obtain a new
sensor reading.
"""
...
def set_integration_cycles(self, integration_cycles):
"""
Set the current number of integration_cycles (1-256).
It takes `integration_cycles` * CLOCK_STEP to obtain a new
sensor reading.
"""
...
def get_raw(self):
"""
Return a tuple containing the raw values of the RGBC channels.
The maximum for these raw values depends on the number of
integration cycles and can be computed using `max_value`.
"""
...
def get_red(self):
"""
Return the raw value of the R (red) channel.
The maximum for this raw value depends on the number of
integration cycles and can be computed using `max_value`.
"""
...
def get_green(self):
"""
Return the raw value of the G (green) channel.
The maximum for this raw value depends on the number of
integration cycles and can be computed using `max_value`.
"""
...
def get_blue(self):
"""
Return the raw value of the B (blue) channel.
The maximum for this raw value depends on the number of
integration cycles and can be computed using `max_value`.
"""
...
def get_clear(self):
"""
Return the raw value of the C (clear light) channel.
The maximum for this raw value depends on the number of
integration cycles and can be computed using `max_value`.
"""
...
class I2C(HardwareInterface):
"""
An implementation of the `HardwareInterface` for the TCS34725/TCS3400
sensor that uses I2C to control the sensor and retrieve measurements.
Use the datasheets as a reference.
"""
BUS = ...
ENABLE = ...
ATIME = ...
CONTROL = ...
ID = ...
STATUS = ...
CDATA = ...
RDATA = ...
GDATA = ...
BDATA = ...
OFF = ...
PON = ...
AEN = ...
ON = ...
AVALID = ...
GAIN_REG_VALUES = ...
ADDR = ...
GAIN_VALUES = ...
CLOCK_STEP = ...
GAIN_TO_REG = ...
REG_TO_GAIN = ...
def __init__(self) -> None: ...
@staticmethod
def i2c_enabled(): # -> bool:
"""Returns True if I2C is enabled or False otherwise."""
...
def get_enabled(self):
"""
Return True if the sensor is enabled and False otherwise
"""
...
def set_enabled(self, status): # -> None:
"""
Enable or disable the sensor, depending on the boolean `status` flag
"""
...
def get_gain(self): # -> Literal[1, 4, 16, 60, 64]:
"""
Return the current value of the sensor gain.
See GAIN_VALUES for the set of possible values.
"""
...
def set_gain(self, gain): # -> None:
"""
Set the value for the sensor `gain`.
See GAIN_VALUES for the set of possible values.
"""
...
def get_integration_cycles(self):
"""
Return the current number of integration_cycles (1-256).
It takes `integration_cycles` * CLOCK_STEP to obtain a new
sensor reading.
"""
...
def set_integration_cycles(self, integration_cycles): # -> None:
"""
Set the current number of integration_cycles (1-256).
It takes `integration_cycles` * CLOCK_STEP to obtain a new
sensor reading.
"""
...
def get_raw(self): # -> tuple[Any, Any, Any, Any]:
"""
Return a tuple containing the raw values of the RGBC channels.
The maximum for these raw values depends on the number of
integration cycles and can be computed using `max_value`.
"""
...
get_red = ...
get_green = ...
get_blue = ...
get_clear = ...
class ColourSensor:
def __init__(self, gain=..., integration_cycles=..., interface=...) -> None: ...
@property
def enabled(self): ...
@enabled.setter
def enabled(self, status): ...
@property
def gain(self): ...
@gain.setter
def gain(self, gain): ...
@property
def integration_cycles(self): ...
@integration_cycles.setter
def integration_cycles(self, integration_cycles): ...
@property
def integration_time(self): ...
@property
def max_raw(self): ...
@property
def colour_raw(self): ...
color_raw = ...
red_raw = ...
green_raw = ...
blue_raw = ...
clear_raw = ...
brightness = ...
@property
def colour(self): ...
@property
def rgb(self): ...
color = ...
red = ...
green = ...
blue = ...
clear = ...

View file

@ -0,0 +1,20 @@
"""
This type stub file was generated by pyright.
"""
class SenseHatException(Exception):
"""
The base exception class for all SenseHat exceptions.
"""
fmt = ...
def __init__(self, **kwargs) -> None: ...
class ColourSensorInitialisationError(SenseHatException):
fmt = ...
class InvalidGainError(SenseHatException):
fmt = ...
class InvalidIntegrationCyclesError(SenseHatException):
fmt = ...

View file

@ -0,0 +1,224 @@
"""
This type stub file was generated by pyright.
"""
from sense_hat.stick import SenseStick
class SenseHat:
SENSE_HAT_FB_NAME = ...
SENSE_HAT_FB_FBIOGET_GAMMA = ...
SENSE_HAT_FB_FBIOSET_GAMMA = ...
SENSE_HAT_FB_FBIORESET_GAMMA = ...
SENSE_HAT_FB_GAMMA_DEFAULT = ...
SENSE_HAT_FB_GAMMA_LOW = ...
SENSE_HAT_FB_GAMMA_USER = ...
SETTINGS_HOME_PATH = ...
def __init__(self, imu_settings_file=..., text_assets=...) -> None: ...
@property
def stick(self) -> SenseStick: ...
@property
def colour(self): ...
color = ...
def has_colour_sensor(self): ...
@property
def rotation(self): ...
@rotation.setter
def rotation(self, r): ...
def set_rotation(self, r=..., redraw=...): # -> None:
"""
Sets the LED matrix rotation for viewing, adjust if the Pi is upside
down or sideways. 0 is with the Pi HDMI port facing downwards
"""
...
def flip_h(self, redraw=...): # -> list[Any]:
"""
Flip LED matrix horizontal
"""
...
def flip_v(self, redraw=...): # -> list[Any]:
"""
Flip LED matrix vertical
"""
...
def set_pixels(self, pixel_list: list[tuple[int, int, int]]) -> None: # -> None:
"""
Accepts a list containing 64 smaller lists of [R,G,B] pixels and
updates the LED matrix. R,G,B elements must integers between 0
and 255
"""
...
def get_pixels(self): # -> list[Any]:
"""
Returns a list containing 64 smaller lists of [R,G,B] pixels
representing what is currently displayed on the LED matrix
"""
...
def set_pixel(self, x, y, *args): # -> None:
"""
Updates the single [R,G,B] pixel specified by x and y on the LED matrix
Top left = 0,0 Bottom right = 7,7
e.g. ap.set_pixel(x, y, r, g, b)
or
pixel = (r, g, b)
ap.set_pixel(x, y, pixel)
"""
...
def get_pixel(self, x, y): # -> list[int]:
"""
Returns a list of [R,G,B] representing the pixel specified by x and y
on the LED matrix. Top left = 0,0 Bottom right = 7,7
"""
...
def load_image(self, file_path, redraw=...): # -> list[list[Any]]:
"""
Accepts a path to an 8 x 8 image file and updates the LED matrix with
the image
"""
...
def clear(self, *args): # -> None:
"""
Clears the LED matrix with a single colour, default is black / off
e.g. ap.clear()
or
ap.clear(r, g, b)
or
colour = (r, g, b)
ap.clear(colour)
"""
...
def show_message(
self, text_string, scroll_speed=..., text_colour=..., back_colour=...
): # -> None:
"""
Scrolls a string of text across the LED matrix using the specified
speed and colours
"""
...
def show_letter(self, s, text_colour=..., back_colour=...): # -> None:
"""
Displays a single text character on the LED matrix using the specified
colours
"""
...
@property
def gamma(self): ...
@gamma.setter
def gamma(self, buffer): ...
def gamma_reset(self): # -> None:
"""
Resets the LED matrix gamma correction to default
"""
...
@property
def low_light(self): ...
@low_light.setter
def low_light(self, value): ...
def get_humidity(self): # -> Literal[0]:
"""
Returns the percentage of relative humidity
"""
...
@property
def humidity(self): ...
def get_temperature_from_humidity(self): # -> Literal[0]:
"""
Returns the temperature in Celsius from the humidity sensor
"""
...
def get_temperature_from_pressure(self): # -> Literal[0]:
"""
Returns the temperature in Celsius from the pressure sensor
"""
...
def get_temperature(self): # -> Literal[0]:
"""
Returns the temperature in Celsius
"""
...
@property
def temp(self): ...
@property
def temperature(self): ...
def get_pressure(self): # -> Literal[0]:
"""
Returns the pressure in Millibars
"""
...
@property
def pressure(self): ...
def set_imu_config(self, compass_enabled, gyro_enabled, accel_enabled): # -> None:
"""
Enables and disables the gyroscope, accelerometer and/or magnetometer
input to the orientation functions
"""
...
def get_orientation_radians(self): # -> dict[str, Any] | dict[str, int]:
"""
Returns a dictionary object to represent the current orientation in
radians using the aircraft principal axes of pitch, roll and yaw
"""
...
@property
def orientation_radians(self): ...
def get_orientation_degrees(self): # -> dict[str, Any] | dict[str, int]:
"""
Returns a dictionary object to represent the current orientation
in degrees, 0 to 360, using the aircraft principal axes of
pitch, roll and yaw
"""
...
def get_orientation(self): ...
@property
def orientation(self): ...
def get_compass(self): # -> int | None:
"""
Gets the direction of North from the magnetometer in degrees
"""
...
@property
def compass(self): ...
def get_compass_raw(self): # -> dict[str, Any] | dict[str, int]:
"""
Magnetometer x y z raw data in uT (micro teslas)
"""
...
@property
def compass_raw(self): ...
def get_gyroscope(self): # -> dict[str, Any] | dict[str, int]:
"""
Gets the orientation in degrees from the gyroscope only
"""
...
@property
def gyro(self): ...
@property
def gyroscope(self): ...
def get_gyroscope_raw(self): # -> dict[str, Any] | dict[str, int]:
"""
Gyroscope x y z raw data in radians per second
"""
...
@property
def gyro_raw(self): ...
@property
def gyroscope_raw(self): ...
def get_accelerometer(self): # -> dict[str, Any] | dict[str, int]:
"""
Gets the orientation in degrees from the accelerometer only
"""
...
@property
def accel(self): ...
@property
def accelerometer(self): ...
def get_accelerometer_raw(self): # -> dict[str, Any] | dict[str, int]:
"""
Accelerometer x y z raw data in Gs
"""
...
@property
def accel_raw(self): ...
@property
def accelerometer_raw(self): ...

132
typings/sense_hat/stick.pyi Normal file
View file

@ -0,0 +1,132 @@
"""
This type stub file was generated by pyright.
"""
from collections.abc import Callable
from typing import Any, NamedTuple
# native_str = str
# str = ...
DIRECTION_UP = ...
DIRECTION_DOWN = ...
DIRECTION_LEFT = ...
DIRECTION_RIGHT = ...
DIRECTION_MIDDLE = ...
ACTION_PRESSED = ...
ACTION_RELEASED = ...
ACTION_HELD = ...
class InputEvent(NamedTuple):
timestamp: int
direction: str
action: str
class SenseStick:
"""
Represents the joystick on the Sense HAT.
"""
SENSE_HAT_EVDEV_NAME = ...
EVENT_FORMAT = ...
EVENT_SIZE = ...
EV_KEY = ...
STATE_RELEASE = ...
STATE_PRESS = ...
STATE_HOLD = ...
KEY_UP = ...
KEY_LEFT = ...
KEY_RIGHT = ...
KEY_DOWN = ...
KEY_ENTER = ...
def __init__(self) -> None: ...
def close(self): ...
def __enter__(self): ...
def __exit__(self, exc_type, exc_value, exc_tb): ...
def wait_for_event(self, emptybuffer=...): # -> InputEvent | None:
"""
Waits until a joystick event becomes available. Returns the event, as
an `InputEvent` tuple.
If *emptybuffer* is `True` (it defaults to `False`), any pending
events will be thrown away first. This is most useful if you are only
interested in "pressed" events.
"""
...
def get_events(self): # -> list[Any]:
"""
Returns a list of all joystick events that have occurred since the last
call to `get_events`. The list contains events in the order that they
occurred. If no events have occurred in the intervening time, the
result is an empty list.
"""
...
@property
def direction_up(self): # -> None:
"""
The function to be called when the joystick is pushed up. The function
can either take a parameter which will be the `InputEvent` tuple that
has occurred, or the function can take no parameters at all.
"""
...
@direction_up.setter
def direction_up(self, value: Callable[[InputEvent], Any]) -> None: ...
@property
def direction_down(self): # -> None:
"""
The function to be called when the joystick is pushed down. The
function can either take a parameter which will be the `InputEvent`
tuple that has occurred, or the function can take no parameters at all.
Assign `None` to prevent this event from being fired.
"""
...
@direction_down.setter
def direction_down(self, value: Callable[[InputEvent], Any]) -> None: ...
@property
def direction_left(self): # -> None:
"""
The function to be called when the joystick is pushed left. The
function can either take a parameter which will be the `InputEvent`
tuple that has occurred, or the function can take no parameters at all.
Assign `None` to prevent this event from being fired.
"""
...
@direction_left.setter
def direction_left(self, value: Callable[[InputEvent], Any]) -> None: ...
@property
def direction_right(self): # -> None:
"""
The function to be called when the joystick is pushed right. The
function can either take a parameter which will be the `InputEvent`
tuple that has occurred, or the function can take no parameters at all.
Assign `None` to prevent this event from being fired.
"""
...
@direction_right.setter
def direction_right(self, value: Callable[[InputEvent], Any]) -> None: ...
@property
def direction_middle(self): # -> None:
"""
The function to be called when the joystick middle click is pressed. The
function can either take a parameter which will be the `InputEvent` tuple
that has occurred, or the function can take no parameters at all.
Assign `None` to prevent this event from being fired.
"""
...
@direction_middle.setter
def direction_middle(self, value: Callable[[InputEvent], Any]) -> None: ...
@property
def direction_any(self): # -> None:
"""
The function to be called when the joystick is used. The function
can either take a parameter which will be the `InputEvent` tuple that
has occurred, or the function can take no parameters at all.
This event will always be called *after* events associated with a
specific action. Assign `None` to prevent this event from being fired.
"""
...
@direction_any.setter
def direction_any(self, value: Callable[[InputEvent], Any]) -> None: ...