Skip to content

Commit 841cc4e

Browse files
committed
Address review comments
1 parent 2ab2b1c commit 841cc4e

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

external_samples/color_range_sensor.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from component import Component, PortType, InvalidPortException
2-
from collections.abc import Callable, Protocol
2+
from collections.abc import Protocol
33

44
class DistanceCallable(Protocol):
55
def __call__(self, distance : float) -> None:
@@ -11,7 +11,6 @@ def __call__(self, hue : int, saturation : int, value : int) -> None:
1111
class ColorRangeSensor(Component):
1212
# Required methods
1313
def __init__(self, ports : list[tuple[PortType, int]]):
14-
self.is_pressed = None
1514
portType, port = ports[0]
1615
if portType != PortType.I2C_PORT:
1716
raise InvalidPortException
@@ -37,27 +36,29 @@ def periodic(self) -> None:
3736
pass
3837

3938
# Component specific methods
40-
def get_color_rgb(self) -> list[int, int, int]:
39+
def get_color_rgb(self) -> tuple[int, int, int]:
4140
'''gets the color in rgb (red, green, blue)'''
4241
pass
43-
def get_color_hsv(self) -> list[int, int, int]:
42+
def get_color_hsv(self) -> tuple[int, int, int]:
4443
'''gets the color in hsv (hue, saturation, value)'''
4544
pass
4645
def get_distance_mm(self) -> float:
4746
'''gets the distance of the object seen'''
4847
pass
4948

50-
def register_when_less_than_distance(self, distance : float, callback: DistanceCallable) -> None:
49+
def register_when_less_than_distance(self, distance : float,
50+
callback: DistanceCallable) -> None:
5151
'''Event when item is seen closer than a distance'''
5252
self.less_than_distance_callback = callback
5353

54-
def register_when_hue_in_range(self, min_hue : int, max_hue : int, callback: ColorCallable) -> None:
54+
def register_when_hue_in_range(self, min_hue : int,
55+
max_hue : int,
56+
callback: ColorCallable) -> None:
5557
'''Event when hue is in range'''
5658
self.hue_in_range_callback = callback
5759

58-
def register_when_saturation_in_range(self, min_saturation : int, max_saturation : int, callback : ColorCallable) -> None:
60+
def register_when_saturation_in_range(self, min_saturation : int,
61+
max_saturation : int,
62+
callback : ColorCallable) -> None:
5963
'''Event when saturation is in range'''
60-
self.saturation_in_range_callback = callback
61-
62-
63-
64+
self.saturation_in_range_callback = callback

external_samples/component.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from abc import ABC, abstractmethod
22
from enum import Enum
3-
from collections.abc import Callable, Protocol
3+
from collections.abc import Protocol
44

55
class EmptyCallable(Protocol):
66
def __call__(self) -> None:
@@ -17,7 +17,7 @@ class InvalidPortException(Exception):
1717
pass
1818

1919
# This is an abstract class
20-
class Component:
20+
class Component(ABC):
2121
@abstractmethod
2222
def __init__(self, ports : list[tuple[PortType, int]]):
2323
pass
@@ -39,7 +39,8 @@ def get_url(self) -> str:
3939
pass
4040
# This is the version of the software (returned as a (major, minor, revision) tuple where
4141
# major and minor are positive integers
42-
# revision is an optional string
42+
# revision can be an empty string or specify small changes that are less than a
43+
# minor revision
4344
@abstractmethod
4445
def get_version(self) -> tuple[int, int, str]:
4546
pass
@@ -49,7 +50,7 @@ def get_version(self) -> tuple[int, int, str]:
4950
def stop(self) -> None:
5051
pass
5152

52-
# any reset required (if any) at the beginning of each opmode
53+
# This performs any reset required (if any) at the beginning of each opmode
5354
# This might remove any registered callbacks
5455
@abstractmethod
5556
def reset(self) -> None:

external_samples/rev_touch_sensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ def is_pressed(self) -> bool:
4444

4545
# Events
4646
def register_when_pressed(self, callback: EmptyCallable) -> None:
47-
'''Event when touch sensor is first pressed'''
47+
'''Event when touch sensor is pressed (after being not pressed)'''
4848
self.pressed_callback = callback
4949

5050

5151
def register_when_released(self, callback: EmptyCallable) -> None:
52-
'''Event when touch sensor is first released'''
52+
'''Event when touch sensor is released (after being pressed)'''
5353
self.released_callback = callback

external_samples/servo.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from component import Component, PortType, InvalidPortException
2-
from collections.abc import Callable
32

43
class Servo(Component):
54
# Required methods
65
def __init__(self, ports : list[tuple[PortType, int]]):
7-
self.is_pressed = None
86
portType, port = ports[0]
97
if portType != PortType.SERVO_PORT:
108
raise InvalidPortException

external_samples/smart_motor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
class SmartMotor(Component):
44
# Required methods
55
def __init__(self, ports : list[tuple[PortType, int]]):
6-
self.is_pressed = None
76
portType, port = ports[0]
87
if portType != PortType.SMART_MOTOR_PORT:
98
raise InvalidPortException

0 commit comments

Comments
 (0)