Skip to content

Commit

Permalink
pybricks.parameters: Add typing, part 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensvalk committed Jun 10, 2022
1 parent 2690804 commit 8ec1b18
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 87 deletions.
1 change: 1 addition & 0 deletions doc/common/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def on_missing_reference(app, env, node, contnode):
"°C",
"J",
"Ω",
"N",
]:

# If they match on raw source, we are dealing with argument types.
Expand Down
106 changes: 61 additions & 45 deletions src/pybricks/pupdevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""LEGO® Powered Up motor, sensors, and lights."""

from typing import Optional, Union, overload, Tuple
from typing import Collection, Optional, Union, overload, Tuple

from ._common import (
Keypad as _Keypad,
Expand Down Expand Up @@ -95,7 +95,7 @@ def name(self, *args):
class TiltSensor:
"""LEGO® Powered Up Tilt Sensor."""

def __init__(self, port):
def __init__(self, port: Port):
"""TiltSensor(port)
Arguments:
Expand Down Expand Up @@ -179,72 +179,82 @@ def __init__(self, port: Port):
"""
pass

def distance(self):
"""Measures the distance between the sensor and an object using
def distance(self) -> int:
"""distance() -> int: mm
Measures the distance between the sensor and an object using
ultrasonic sound waves.
Returns:
:ref:`distance`: Measured distance. If no valid distance was
measured, it returns 2000 mm.
Measured distance. If no valid distance was measured,
it returns 2000 mm.
"""
pass

def presence(self):
"""Checks for the presence of other ultrasonic sensors by detecting
def presence(self) -> bool:
"""presence() -> bool
Checks for the presence of other ultrasonic sensors by detecting
ultrasonic sounds.
Returns:
bool: ``True`` if ultrasonic sounds are detected,
``False`` if not.
``True`` if ultrasonic sounds are detected, ``False`` if not.
"""
pass


class ForceSensor:
"""LEGO® SPIKE Force Sensor."""

def __init__(self, port):
def __init__(self, port: Port):
"""ForceSensor(port)
Arguments:
port (Port): Port to which the sensor is connected.
"""
pass

def force(self):
"""Measures the force exerted on the sensor.
def force(self) -> float:
"""force() -> float: N
Measures the force exerted on the sensor.
Returns:
:ref:`force`: Measured force (up to approximately 10.00 N).
Measured force (up to approximately 10.00 N).
"""

def distance(self):
"""Measures by how much the sensor button has moved.
def distance(self) -> float:
"""distance() -> float: mm
Measures by how much the sensor button has moved.
Returns:
:ref:`distance`: How much the sensor button has
moved (up to approximately 8.00 mm).
Movement up to approximately 8.00 mm.
"""

def pressed(self, force=3):
"""Checks if the sensor button is pressed.
def pressed(self, force=3) -> bool:
"""pressed(force=3) -> bool
Checks if the sensor button is pressed.
Arguments:
force (:ref:`force`): Minimum force to be considered pressed.
force (Number, N): Minimum force to be considered pressed.
Returns:
bool: ``True`` if the sensor is pressed, ``False`` if it is not.
``True`` if the sensor is pressed, ``False`` if it is not.
"""

def touched(self):
"""Checks if the sensor is touched.
def touched(self) -> bool:
"""touched() -> bool
Checks if the sensor is touched.
This is similar to :meth:`pressed`, but it detects slight movements of
the button even when the measured force is still considered zero.
Returns:
bool: ``True`` if the sensor is touched or pressed, ``False``
``True`` if the sensor is touched or pressed, ``False``
if it is not.
"""

Expand All @@ -256,7 +266,7 @@ class ColorLightMatrix:
LEGO® SPIKE 3x3 Color Light Matrix.
"""

def __init__(self, port):
def __init__(self, port: Port):
"""ColorLightMatrix(port)
Arguments:
Expand All @@ -265,8 +275,9 @@ def __init__(self, port):
"""
...

def on(self, colors):
"""
def on(self, color: Union[Color, Collection[Color]]) -> None:
"""on(colors)
Turns the lights on.
Arguments:
Expand All @@ -277,61 +288,66 @@ def on(self, colors):
"""
...

def off(self):
"""
Turns all of the lights off.
def off(self) -> None:
"""off()
Turns all lights off.
"""
...


class InfraredSensor:
"""LEGO® Powered Up Infrared Sensor."""

def __init__(self, port):
def __init__(self, port: Port):
"""InfraredSensor(port)
Arguments:
port (Port): Port to which the sensor is connected.
"""
pass

def reflection(self):
"""Measures the reflection of a surface using an infrared light.
def reflection(self) -> int:
"""reflection() -> int: %
Measures the reflection of a surface using an infrared light.
Returns:
:ref:`percentage`: Reflection, ranging from 0.0 (no reflection) to
100.0 (high reflection).
Measured reflection, ranging from 0% (no reflection) to
100% (high reflection).
"""
pass

def distance(self):
"""Measures the relative distance between the sensor and an object
def distance(self) -> int:
"""distance() -> int: %
Measures the relative distance between the sensor and an object
using infrared light.
Returns:
:ref:`relativedistance`: Relative distance ranging from 0 (closest)
to 100 (farthest).
Distance ranging from 0% (closest) to 100% (farthest).
"""
pass

def count(self):
"""Counts the number of objects that have passed by the sensor.
def count(self) -> int:
"""count() -> int
Counts the number of objects that have passed by the sensor.
Returns:
int: Number of objects counted.
Number of objects counted.
"""
pass


class Light:
"""LEGO® Powered Up Light."""

def __init__(self, port):
def __init__(self, port: Port):
"""Light(port)
Arguments:
port (Port): Port to which the device is connected.
"""
pass

Expand Down
42 changes: 0 additions & 42 deletions src/pybricks/pupdevices.pyi

This file was deleted.

0 comments on commit 8ec1b18

Please sign in to comment.