Handle pet and wildlife events in event processor

This commit is contained in:
Aaron D. Lee 2026-04-03 13:20:46 -04:00
parent 53daf58c78
commit d0acf7703c
2 changed files with 69 additions and 0 deletions

View File

@ -327,3 +327,57 @@ class TestEventHistory:
assert len(rows_offset) == 2
# Should be different events
assert rows[0]["id"] != rows_offset[0]["id"]
# ---------------------------------------------------------------------------
# Pet / Wildlife Event Classification
# ---------------------------------------------------------------------------
class TestPetEventClassification:
def test_pet_detected_event(self):
from vigilar.events.processor import EventProcessor
from vigilar.constants import EventType, Severity
processor = EventProcessor.__new__(EventProcessor)
etype, sev, source = processor._classify_event(
"vigilar/camera/kitchen/pet/detected",
{"pet_name": "Angel", "confidence": 0.92},
)
assert etype == EventType.PET_DETECTED
assert sev == Severity.INFO
assert source == "kitchen"
def test_wildlife_predator_event(self):
from vigilar.events.processor import EventProcessor
from vigilar.constants import EventType, Severity
processor = EventProcessor.__new__(EventProcessor)
etype, sev, source = processor._classify_event(
"vigilar/camera/front/wildlife/detected",
{"species": "bear", "threat_level": "PREDATOR"},
)
assert etype == EventType.WILDLIFE_PREDATOR
assert sev == Severity.CRITICAL
assert source == "front"
def test_wildlife_nuisance_event(self):
from vigilar.events.processor import EventProcessor
from vigilar.constants import EventType, Severity
processor = EventProcessor.__new__(EventProcessor)
etype, sev, source = processor._classify_event(
"vigilar/camera/back/wildlife/detected",
{"species": "raccoon", "threat_level": "NUISANCE"},
)
assert etype == EventType.WILDLIFE_NUISANCE
assert sev == Severity.WARNING
assert source == "back"
def test_wildlife_passive_event(self):
from vigilar.events.processor import EventProcessor
from vigilar.constants import EventType, Severity
processor = EventProcessor.__new__(EventProcessor)
etype, sev, source = processor._classify_event(
"vigilar/camera/front/wildlife/detected",
{"species": "deer", "threat_level": "PASSIVE"},
)
assert etype == EventType.WILDLIFE_PASSIVE
assert sev == Severity.INFO
assert source == "front"

View File

@ -127,6 +127,21 @@ class EventProcessor:
if suffix in _TOPIC_EVENT_MAP:
etype, sev = _TOPIC_EVENT_MAP[suffix]
return etype, sev, camera_id
# Pet detection
if suffix == "pet/detected":
return EventType.PET_DETECTED, Severity.INFO, camera_id
# Wildlife detection — severity depends on threat_level in payload
if suffix == "wildlife/detected":
threat = payload.get("threat_level", "PASSIVE")
if threat == "PREDATOR":
return EventType.WILDLIFE_PREDATOR, Severity.CRITICAL, camera_id
elif threat == "NUISANCE":
return EventType.WILDLIFE_NUISANCE, Severity.WARNING, camera_id
else:
return EventType.WILDLIFE_PASSIVE, Severity.INFO, camera_id
# Ignore heartbeats etc.
return None, None, None