Skip to content

Commit

Permalink
no alert send (#218)
Browse files Browse the repository at this point in the history
* no alert send

* missing docstring
  • Loading branch information
MateoLostanlen committed Jul 16, 2024
1 parent 57e4b4c commit 7474e75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 7 additions & 4 deletions pyroengine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@ def check_day_time(self) -> None:
except Exception as e:
logging.exception(f"Exception during initial day time check: {e}")

async def run(self, period: int = 30) -> None:
async def run(self, period: int = 30, send_alerts: bool = True) -> None:
"""
Captures and analyzes all camera streams, then processes alerts.
Args:
period (int): The time period between captures in seconds.
send_alerts (bool): Boolean to activate / deactivate alert sending
"""
try:
self.check_day_time()
Expand All @@ -176,23 +177,25 @@ async def run(self, period: int = 30) -> None:

# Process alerts
try:
self.engine._process_alerts()
if send_alerts:
self.engine._process_alerts()
except Exception as e:
logging.error(f"Error processing alerts: {e}")

except Exception as e:
logging.warning(f"Analyze stream error: {e}")

async def main_loop(self, period: int) -> None:
async def main_loop(self, period: int, send_alerts: bool = True) -> None:
"""
Main loop to capture and process images at regular intervals.
Args:
period (int): The time period between captures in seconds.
send_alerts (bool): Boolean to activate / deactivate alert sending
"""
while True:
start_ts = time.time()
await self.run(period)
await self.run(period, send_alerts)
# Sleep only once all images are processed
loop_time = time.time() - start_ts
sleep_time = max(period - (loop_time), 0)
Expand Down
5 changes: 4 additions & 1 deletion src/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def main(args):
cameras,
)

asyncio.run(sys_controller.main_loop(args.period))
asyncio.run(sys_controller.main_loop(args.period, args.send_alerts))


if __name__ == "__main__":
Expand Down Expand Up @@ -109,7 +109,10 @@ def main(args):
parser.add_argument("--protocol", type=str, default="https", help="Camera protocol")
# Backup
parser.add_argument("--backup-size", type=int, default=10000, help="Local backup can't be bigger than 10Go")

# Debug
parser.add_argument("--save_captured_frames", type=bool, default=False, help="Save all captured frames locally")
parser.add_argument("--send_alerts", type=bool, default=True, help="Save all captured frames locally")

# Time config
parser.add_argument("--period", type=int, default=30, help="Number of seconds between each camera stream analysis")
Expand Down

0 comments on commit 7474e75

Please sign in to comment.