Add typehints and docstrings as suggested in review

This commit is contained in:
Julian Stirling 2025-06-25 15:55:48 +01:00
parent 0933ece63a
commit ce5b5b781c
2 changed files with 13 additions and 4 deletions

View file

@ -76,7 +76,9 @@ class BaseCamera(Thing):
self._memory_metadata = None self._memory_metadata = None
@thing_action @thing_action
def start_streaming(self, main_resolution, buffer_count) -> None: def start_streaming(
self, main_resolution: tuple[int, int], buffer_count: int
) -> None:
"""Start (or stop and restart) the camera with the given resolution """Start (or stop and restart) the camera with the given resolution
for the main stream, and buffer_count number of images in the buffer""" for the main stream, and buffer_count number of images in the buffer"""
raise NotImplementedError( raise NotImplementedError(
@ -132,7 +134,11 @@ class BaseCamera(Thing):
return JPEGBlob.from_bytes(frame) return JPEGBlob.from_bytes(frame)
@thing_action @thing_action
def capture_image(self, stream_name, wait): def capture_image(
self,
stream_name: Literal["main", "lores", "raw"],
wait: Optional[float],
) -> None:
"""Capture a PIL image from stream stream_name with timeout wait""" """Capture a PIL image from stream stream_name with timeout wait"""
raise NotImplementedError( raise NotImplementedError(
"CameraThings must define their own capture_image method" "CameraThings must define their own capture_image method"
@ -211,7 +217,10 @@ class BaseCamera(Thing):
) -> Image: ) -> Image:
"""Capture an image in memory and return it with metadata """Capture an image in memory and return it with metadata
CaptureError raised if the capture fails for any reason CaptureError raised if the capture fails for any reason
returns tuple with PIL Image, and dict of metadata returns tuple with PIL Image, and dict of metadata.
This robust capturing method attempts to capture the image five times
each time with a 5 second timeout set.
""" """
for capture_attempts in range(5): for capture_attempts in range(5):
try: try:

View file

@ -444,7 +444,7 @@ class StreamingPiCamera2(BaseCamera):
self, self,
stream_name: Literal["main", "lores", "raw"] = "main", stream_name: Literal["main", "lores", "raw"] = "main",
wait: Optional[float] = 0.9, wait: Optional[float] = 0.9,
): ) -> None:
"""Acquire one image from the camera. """Acquire one image from the camera.
Return it as a PIL Image Return it as a PIL Image