Some more fixes

This commit is contained in:
2026-02-18 05:59:06 +07:00
parent 0337d35b42
commit b0ce911be3

View File

@@ -58,6 +58,10 @@ class FrigateCounter:
self.counter_lock = threading.Lock()
self.seen_objects = {}
# State pintu tracking
self.timer_active_pintu = False
self.timer_start_time_pintu = None
# Load previous counter value on startup
self.load_previous_counter()
@@ -219,6 +223,21 @@ class FrigateCounter:
"""Check if both pintu-kiri-buka and pintu-kanan-buka have been detected"""
if self.pintu_kiri_buka_detected and self.pintu_kanan_buka_detected:
self.start_timer()
return
if not self.timer_active_pintu:
self.start_timer_pintu()
def start_timer_pintu(self):
"""Start the 5-minute timer Pintu"""
logger.info("Starting 5-minute timer Pintu")
self.timer_active_pintu = True
self.timer_start_time_pintu = datetime.now()
# Schedule timer expiration check
timer_thread = threading.Thread(target=self.check_timer_expiration_pintu)
timer_thread.daemon = True
timer_thread.start()
def start_timer(self):
"""Start the 30-minute timer"""
@@ -235,6 +254,16 @@ class FrigateCounter:
self.pintu_kiri_buka_detected = False
self.pintu_kanan_buka_detected = False
def check_timer_expiration_pintu(self):
"""Check if timer has expired (5 minutes)"""
time.sleep(5 * 60) # Wait 5 minutes
if self.timer_active_pintu:
logger.info("Timer Pintu expired (5 minutes)")
self.timer_active_pintu = False
self.pintu_kiri_buka_detected = False
self.pintu_kanan_buka_detected = False
def check_timer_expiration(self):
"""Check if timer has expired (30 minutes)"""
time.sleep(30 * 60) # Wait 30 minutes
@@ -276,7 +305,7 @@ class FrigateCounter:
cursor.execute('''
INSERT INTO karung_counts (camera_name, date, counter_value)
VALUES (?, ?, ?)
''', ('frigate_camera', date.today(), self.counter))
''', (self.camera_name, date.today(), self.counter))
conn.commit()
conn.close()
logger.info(f"Saved counter result to database: {self.counter}")
@@ -285,7 +314,7 @@ class FrigateCounter:
# Ensure we don't lose data due to database errors
# We should still try to save to JSON as backup
try:
self.save_to_json('frigate_camera')
self.save_to_json(self.camera_name)
logger.info("Fallback save to JSON successful")
except Exception as e2:
logger.error(f"Fallback save to JSON also failed: {e2}")