6 from datetime import datetime
9 class any_camera_trigger(trigger.trigger):
11 self.triggers_in_the_past_seven_min = {
24 def choose_priority(self, camera, age):
25 base_priority_by_camera = {
31 priority = base_priority_by_camera[camera]
33 priority += trigger.trigger.PRIORITY_HIGH
35 priority += trigger.trigger.PRIORITY_NORMAL + age
37 priority += trigger.trigger.PRIORITY_LOW
40 def get_triggered_page_list(self):
42 cameras_with_recent_triggers = 0
43 camera_list = ["driveway", "frontdoor", "cabin_driveway", "backyard"]
47 # First pass, just see whether each camera is triggered and,
48 # if so, count how many times in the past 7m it has triggered.
49 for camera in camera_list:
50 file = "/timestamps/last_camera_motion_%s" % camera
51 ts = os.stat(file).st_ctime
52 if ts != self.last_trigger[camera] and (now - ts) < 10:
53 print("Camera: %s, age %s" % (camera, (now - ts)))
54 self.last_trigger[camera] = ts
55 cameras_with_recent_triggers += 1
56 self.triggers_in_the_past_seven_min[camera] = 0
57 file = "/timestamps/camera_motion_history_%s" % camera
59 contents = f.readlines()
65 self.triggers_in_the_past_seven_min[camera] += 1
67 # Second pass, see whether we want to trigger due to
68 # camera activity we found. All cameras timestamps were
69 # just considered and should be up-to-date. Some logic to
70 # squelch spammy cameras unless more than one is
71 # triggered at the same time.
72 for camera in camera_list:
73 if (now - self.last_trigger[camera]) < 10:
75 self.triggers_in_the_past_seven_min[camera] <= 4
76 or cameras_with_recent_triggers > 1
78 ts = utils.timestamp()
79 p = self.choose_priority(camera, age)
82 "%s: ****** %s[%d] CAMERA TRIGGER ******"
88 "hidden/%s.html" % camera,
89 self.choose_priority(camera, age),
94 ("%s: Camera %s too spammy, squelching it" % (ts, camera))
96 except Exception as e:
100 if len(triggers) == 0:
106 # x = any_camera_trigger()
107 # print(x.get_triggered_page_list())