From 247cd9ee93323e4bd9cc4554fc6eb1837fddb9b6 Mon Sep 17 00:00:00 2001 From: MateoLostanlen Date: Tue, 30 Jul 2024 14:53:09 +0200 Subject: [PATCH] prevent frame none --- pyroengine/core.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pyroengine/core.py b/pyroengine/core.py index 7c2363a..88f64a7 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