From 68f767a9af6f4b1ebdbb3b7dbd9cfb1f62d9f4dc Mon Sep 17 00:00:00 2001 From: mgfcf Date: Fri, 3 Dec 2021 16:43:36 +0100 Subject: [PATCH] Implemented more hooks --- src/sensor/people_counter.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/sensor/people_counter.py b/src/sensor/people_counter.py index a3d5a24..ddecdb5 100644 --- a/src/sensor/people_counter.py +++ b/src/sensor/people_counter.py @@ -57,9 +57,13 @@ class PeopleCounter (): triggered: bool = self.isTriggerDistance(distance) changed: bool = self.updateState(direction, triggered) + if triggered: + self.handleActivityCallbacks(direction) + if changed: countChange: int = self.getCountChange(self.directionState) - self.handleCallbacks(countChange) + self.handleChangeCallbacks(countChange) + self.handleCountingCallbacks(countChange) # Reset records self.directionState = self.getInitialDirectionState() @@ -127,14 +131,22 @@ class PeopleCounter (): #! TODO: Should be based on the distance from the ground, not them the sensor return distance <= self.maxTriggerDistance - def handleCallbacks(self, countChange: int) -> None: + def handleCountingCallbacks(self, countChange: int) -> None: + # Only notify counting on actual count change if countChange == 0: - # Do nothing if there is no change return for cb in self.callbacks[COUNTING_CB]: cb(countChange) + def handleActivityCallbacks(self, direction: Directions) -> None: + for cb in self.callbacks[ACTIVITY_CB]: + cb(direction) + + def handleChangeCallbacks(self, countChange: int) -> None: + for cb in self.callbacks[CHANGE_CB]: + cb(countChange, self.directionState) + def getDirectionTime(self, direction: Directions, time: str) -> datetime: if len(self.directionState[direction]) <= 0: return None