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
@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
for the main stream, and buffer_count number of images in the buffer"""
raise NotImplementedError(
@ -132,7 +134,11 @@ class BaseCamera(Thing):
return JPEGBlob.from_bytes(frame)
@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"""
raise NotImplementedError(
"CameraThings must define their own capture_image method"
@ -211,7 +217,10 @@ class BaseCamera(Thing):
) -> Image:
"""Capture an image in memory and return it with metadata
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):
try:

View file

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