88import tempfile
99import time
1010from tempfile import TemporaryDirectory
11- import uuid
1211
1312from pydantic import BaseModel , BeforeValidator , RootModel
1413
@@ -579,7 +578,7 @@ def snap_image(self) -> ArrayModel:
579578 def capture_array (
580579 self ,
581580 stream_name : Literal ["main" , "lores" , "raw" , "full" ] = "main" ,
582- wait : Optional [float ] = None ,
581+ wait : Optional [float ] = 0.9 ,
583582 ) -> ArrayModel :
584583 """Acquire one image from the camera and return as an array
585584
@@ -588,7 +587,9 @@ def capture_array(
588587 binary image formats will be added in due course.
589588
590589 stream_name: (Optional) The PiCamera2 stream to use, should be one of ["main", "lores", "raw", "full"]. Default = "main"
591- wait: (Optional, float) Set a timeout in seconds. A TimeoutError is raised if this time is exceeded during capture. Default = None
590+ wait: (Optional, float) Set a timeout in seconds.
591+ A TimeoutError is raised if this time is exceeded during capture.
592+ Default = 0.9s, lower than the 1s timeout default in picamera yaml settings
592593 """
593594 if stream_name == "full" :
594595 with self .picamera (pause_stream = True ) as picam2 :
@@ -603,19 +604,24 @@ def capture_raw(
603604 states_getter : GetThingStates ,
604605 get_states : bool = True ,
605606 get_processing_inputs : bool = True ,
607+ wait : Optional [float ] = 0.9 ,
606608 ) -> RawImageModel :
607609 """Capture a raw image
608610
609611 This function is intended to be as fast as possible, and will return
610612 as soon as an image has been captured. The output format is not intended
611613 to be useful, except as input to `raw_to_png`.
612-
614+
615+ wait: (Optional, float) Set a timeout in seconds.
616+ A TimeoutError is raised if this time is exceeded during capture.
617+ Default = 0.9s, lower than the 1s timeout default in picamera yaml settings
618+
613619 When used via the HTTP interface, this function returns the data as a
614620 `Blob` object, meaning it can be passed to another action without
615621 transferring it over the network.
616622 """
617623 with self .picamera () as cam :
618- (buffer , ), parameters = cam .capture_buffers (["raw" ])
624+ (buffer , ), parameters = cam .capture_buffers (["raw" ], wait = wait )
619625 configuration = cam .camera_configuration ()
620626 return RawImageModel (
621627 image_data = RawBlob .from_bytes (buffer .tobytes ()),
@@ -757,6 +763,7 @@ def capture_jpeg(
757763 self ,
758764 metadata_getter : GetThingStates ,
759765 resolution : Literal ["lores" , "main" , "full" ] = "main" ,
766+ wait : Optional [float ] = 0.9 ,
760767 ) -> JPEGBlob :
761768 """Acquire one image from the camera as a JPEG
762769
@@ -770,6 +777,10 @@ def capture_jpeg(
770777 MJPEG stream and reconfigure the camera to capture a full
771778 resolution image.
772779
780+ wait: (Optional, float) Set a timeout in seconds.
781+ A TimeoutError is raised if this time is exceeded during capture.
782+ Default = 0.9s, lower than the 1s timeout default in picamera yaml settings
783+
773784 Note that this always uses the image processing pipeline - to
774785 bypass this, you must use a raw capture.
775786 """
@@ -781,7 +792,7 @@ def capture_jpeg(
781792 # to reconfigure for these
782793 if resolution in ("lores" , "main" ) and config [resolution ]:
783794 with self .picamera () as cam :
784- cam .capture_file (path , name = resolution , format = "jpeg" )
795+ cam .capture_file (path , name = resolution , format = "jpeg" , wait = wait )
785796 else :
786797 if resolution != "full" :
787798 logging .warning (
@@ -793,7 +804,7 @@ def capture_jpeg(
793804 cam .start ()
794805 cam .options ["quality" ] = 95
795806 logging .info ("capturing" )
796- cam .capture_file (path , name = "main" , format = "jpeg" , wait = 5 )
807+ cam .capture_file (path , name = "main" , format = "jpeg" , wait = wait )
797808 logging .info ("done" )
798809 # After the file is written, add metadata about the current Things
799810 exif_dict = piexif .load (path )
0 commit comments