From a532a7b17b0f6c66ad4bec7ae806bba68be880ac Mon Sep 17 00:00:00 2001 From: Mateo Date: Tue, 30 Jul 2024 15:01:54 +0200 Subject: [PATCH] prevent frame none (#224) --- pyroengine/core.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pyroengine/core.py b/pyroengine/core.py index 7c2363a7..88f64a71 100644 --- a/pyroengine/core.py +++ b/pyroengine/core.py @@ -81,15 +81,15 @@ async def capture_camera_image(camera: ReolinkCamera, image_queue: asyncio.Queue if frame is not None: await image_queue.put((cam_id, frame)) await asyncio.sleep(0) # Yield control - if not is_day_time(None, frame, "ir"): - return False + if not is_day_time(None, frame, "ir"): + return False else: frame = camera.capture() if frame is not None: await image_queue.put((cam_id, frame)) await asyncio.sleep(0) # Yield control - if not is_day_time(None, frame, "ir"): - return False + if not is_day_time(None, frame, "ir"): + return False except Exception as e: logging.exception(f"Error during image capture from camera {cam_id}: {e}") return True @@ -166,12 +166,14 @@ async def night_mode(self) -> bool: # Move camera to the next pose to avoid waiting next_pos_id = camera.cam_poses[(idx + 1) % len(camera.cam_poses)] camera.move_camera("ToPos", idx=int(next_pos_id), speed=50) - if not is_day_time(None, frame, "ir"): - return False + if frame is not None: + if not is_day_time(None, frame, "ir"): + return False else: frame = camera.capture() - if not is_day_time(None, frame, "ir"): - return False + if frame is not None: + if not is_day_time(None, frame, "ir"): + return False except Exception as e: logging.exception(f"Error during image capture from camera {cam_id}: {e}") return True