mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-09-28 17:53:51 +02:00
* Use event metadata updater to handle sub label operations * Use event metadata publisher for sub label setting * Formatting * fix tests * Cleanup
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
"""Facilitates communication between processes."""
|
|
|
|
import logging
|
|
from enum import Enum
|
|
|
|
from .zmq_proxy import Publisher, Subscriber
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class EventMetadataTypeEnum(str, Enum):
|
|
all = ""
|
|
regenerate_description = "regenerate_description"
|
|
sub_label = "sub_label"
|
|
|
|
|
|
class EventMetadataPublisher(Publisher):
|
|
"""Simplifies receiving event metadata."""
|
|
|
|
topic_base = "event_metadata/"
|
|
|
|
def __init__(self) -> None:
|
|
super().__init__()
|
|
|
|
def publish(self, topic: EventMetadataTypeEnum, payload: any) -> None:
|
|
super().publish(payload, topic.value)
|
|
|
|
|
|
class EventMetadataSubscriber(Subscriber):
|
|
"""Simplifies receiving event metadata."""
|
|
|
|
topic_base = "event_metadata/"
|
|
|
|
def __init__(self, topic: EventMetadataTypeEnum) -> None:
|
|
super().__init__(topic.value)
|
|
|
|
def check_for_update(self, timeout: float = 1) -> tuple | None:
|
|
return super().check_for_update(timeout)
|
|
|
|
def _return_object(self, topic: str, payload: tuple) -> tuple:
|
|
if payload is None:
|
|
return (None, None)
|
|
|
|
topic = EventMetadataTypeEnum[topic[len(self.topic_base) :]]
|
|
return (topic, payload)
|