refactor(playout): add typings and fix linting errors
move EVENT_KEY_FORMAT to events module properly type fetch queue event start/end can be str or datetime
This commit is contained in:
parent
3fba7c73d3
commit
e88e843b65
11 changed files with 286 additions and 213 deletions
|
@ -1,8 +1,23 @@
|
|||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from typing import Dict, Literal, TypedDict, Union
|
||||
from typing import Dict, Literal, Optional, TypedDict, Union
|
||||
|
||||
from typing_extensions import NotRequired
|
||||
|
||||
EVENT_KEY_FORMAT = "%Y-%m-%d-%H-%M-%S"
|
||||
|
||||
|
||||
def event_key_to_datetime(value: Union[str, datetime]) -> datetime:
|
||||
if isinstance(value, datetime):
|
||||
return value
|
||||
return datetime.strptime(value, EVENT_KEY_FORMAT)
|
||||
|
||||
|
||||
def datetime_to_event_key(value: Union[str, datetime]) -> str:
|
||||
if isinstance(value, str):
|
||||
return value
|
||||
return value.strftime(EVENT_KEY_FORMAT)
|
||||
|
||||
|
||||
class EventKind(str, Enum):
|
||||
FILE = "file"
|
||||
|
@ -14,9 +29,9 @@ class EventKind(str, Enum):
|
|||
|
||||
|
||||
class BaseEvent(TypedDict):
|
||||
# TODO: Convert start/end to datetime
|
||||
start: str
|
||||
end: str
|
||||
# TODO: Only use datetime
|
||||
start: Union[str, datetime]
|
||||
end: Union[str, datetime]
|
||||
|
||||
|
||||
class FileEventMetadata(TypedDict):
|
||||
|
@ -30,7 +45,7 @@ class FileEvent(BaseEvent):
|
|||
|
||||
# Schedule
|
||||
row_id: int
|
||||
uri: str
|
||||
uri: Optional[str]
|
||||
id: int
|
||||
|
||||
# Show data
|
||||
|
@ -48,6 +63,11 @@ class FileEvent(BaseEvent):
|
|||
replay_gain: float
|
||||
filesize: int
|
||||
|
||||
# Runtime
|
||||
dst: NotRequired[str]
|
||||
file_ready: NotRequired[bool]
|
||||
file_ext: NotRequired[str]
|
||||
|
||||
|
||||
class WebStreamEvent(BaseEvent):
|
||||
type: Literal[
|
||||
|
@ -78,4 +98,6 @@ class ActionEvent(BaseEvent):
|
|||
|
||||
|
||||
AnyEvent = Union[FileEvent, WebStreamEvent, ActionEvent]
|
||||
|
||||
FileEvents = Dict[str, FileEvent]
|
||||
Events = Dict[str, AnyEvent]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue