import glob
import os
import time
-from typing import List, Tuple
+from typing import List, Tuple, Optional
import trigger
import utils
self.triggers_in_the_past_seven_min = {
"driveway": 0,
"frontdoor": 0,
+ "doorbell": 0,
"cabin_driveway": 0,
}
self.last_trigger_timestamp = {
"driveway": 0,
"frontdoor": 0,
+ "doorbell": 0,
"cabin_driveway": 0,
}
def choose_priority(self, camera: str, age: int) -> int:
"""Based on the camera name and last trigger age, compute priority."""
base_priority_by_camera = {
- "driveway": 1,
+ "driveway": 3,
"frontdoor": 2,
- "cabin_driveway": 1,
+ "doorbell": 1,
+ "cabin_driveway": 3,
}
priority = base_priority_by_camera[camera]
if age < 10:
priority += trigger.trigger.PRIORITY_LOW
return priority
- def get_triggered_page_list(self) -> List[Tuple[str, int]]:
+ def get_triggered_page_list(self) -> Optional[List[Tuple[str, int]]]:
"""Return a list of triggered pages with priorities."""
triggers = []
num_cameras_with_recent_triggers = 0
- camera_list = ["driveway", "frontdoor", "cabin_driveway"]
+ camera_list = ["driveway", "frontdoor", "doorbell", "cabin_driveway"]
now = time.time()
try:
self.triggers_in_the_past_seven_min[camera] <= 4
or num_cameras_with_recent_triggers > 1
):
- ts = utils.timestamp()
- priority = self.choose_priority(camera, age)
+ priority = self.choose_priority(camera, int(age))
print(
- f"{ts}: ****** {camera}[{priority}] CAMERA TRIGGER ******"
+ f"{utils.timestamp()}: *** {camera}[{priority}] CAMERA TRIGGER ***"
)
triggers.append(
(
)
)
else:
- print(f"{ts}: Camera {camera} too spammy, squelching it")
+ print(f"{utils.timestamp()}: Camera {camera} too spammy, squelching it")
except Exception as e:
print(e)
pass