Skip to content

Commit d596014

Browse files
committed
Error on missing middle reflectance sensor
Add a runtime check in Reflectance.get_middle that raises RuntimeError when the middle reflectance pin is not supported on the board. Update the docstring to document the raised error and clarify the return value (reflectance 0..1). This prevents calling _get_value with a None sensor and gives a clearer failure mode for unsupported hardware configurations.
1 parent 89fa5b8 commit d596014

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

XRPLib/reflectance.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ def get_left(self) -> float:
5252

5353
def get_middle(self) -> float:
5454
"""
55-
Gets the the reflectance of the left reflectance sensor
56-
: return: The reflectance ranging from 0 (white) to 1 (black)
55+
Gets the reflectance of the middle sensor if available.
56+
:raises RuntimeError: If the middle pin is not supported on this board.
57+
:return: Reflectance from 0 (white) to 1 (black)
5758
: rtype: float
5859
"""
60+
if self._middleReflectance is None:
61+
raise RuntimeError(f"Middle reflectance sensor is not available on this board configuration.")
62+
5963
return self._get_value(self._middleReflectance)
6064

6165
def get_right(self) -> float:

0 commit comments

Comments
 (0)