Debian Codegraph @

wyoming/satellite.py

raw
1 """Satellite events."""
2
3 from dataclasses import dataclass
4
5 from .event import Event, Eventable
6
7 _RUN_SATELLITE_TYPE = "run-satellite"
8 _PAUSE_SATELLITE_TYPE = "pause-satellite"
9 _STREAMING_STARTED_TYPE = "streaming-started"
10 _STREAMING_STOPPED_TYPE = "streaming-stopped"
11 _SATELLITE_CONNECTED_TYPE = "satellite-connected"
12 _SATELLITE_DISCONNECTED_TYPE = "satellite-disconnected"
13
14
15 @dataclass
16 class RunSatellite(Eventable):
17 """Informs the satellite that the server is ready to run a pipeline."""
18
19 @staticmethod
20 def is_type(event_type: str) -> bool:
21 return event_type == _RUN_SATELLITE_TYPE
22
23 def event(self) -> Event:
24 return Event(type=_RUN_SATELLITE_TYPE)
25
26 @staticmethod
27 def from_event(event: Event) -> "RunSatellite":
28 return RunSatellite()
29
30
31 @dataclass
32 class PauseSatellite(Eventable):
33 """Informs the satellite that the server is not ready to run a pipeline."""
34
35 @staticmethod
36 def is_type(event_type: str) -> bool:
37 return event_type == _PAUSE_SATELLITE_TYPE
38
39 def event(self) -> Event:
40 return Event(type=_PAUSE_SATELLITE_TYPE)
41
42 @staticmethod
43 def from_event(event: Event) -> "PauseSatellite":
44 return PauseSatellite()
45
46
47 @dataclass
48 class StreamingStarted(Eventable):
49 """Satellite has started streaming audio to server."""
50
51 @staticmethod
52 def is_type(event_type: str) -> bool:
53 return event_type == _STREAMING_STARTED_TYPE
54
55 def event(self) -> Event:
56 return Event(type=_STREAMING_STARTED_TYPE)
57
58 @staticmethod
59 def from_event(event: Event) -> "StreamingStarted":
60 return StreamingStarted()
61
62
63 @dataclass
64 class StreamingStopped(Eventable):
65 """Satellite has stopped streaming audio to server."""
66
67 @staticmethod
68 def is_type(event_type: str) -> bool:
69 return event_type == _STREAMING_STOPPED_TYPE
70
71 def event(self) -> Event:
72 return Event(type=_STREAMING_STOPPED_TYPE)
73
74 @staticmethod
75 def from_event(event: Event) -> "StreamingStopped":
76 return StreamingStopped()
77
78
79 @dataclass
80 class SatelliteConnected(Eventable):
81 """Satellite has connected to server."""
82
83 @staticmethod
84 def is_type(event_type: str) -> bool:
85 return event_type == _SATELLITE_CONNECTED_TYPE
86
87 def event(self) -> Event:
88 return Event(type=_SATELLITE_CONNECTED_TYPE)
89
90 @staticmethod
91 def from_event(event: Event) -> "SatelliteConnected":
92 return SatelliteConnected()
93
94
95 @dataclass
96 class SatelliteDisconnected(Eventable):
97 """Satellite has disconnected from server."""
98
99 @staticmethod
100 def is_type(event_type: str) -> bool:
101 return event_type == _SATELLITE_DISCONNECTED_TYPE
102
103 def event(self) -> Event:
104 return Event(type=_SATELLITE_DISCONNECTED_TYPE)
105
106 @staticmethod
107 def from_event(event: Event) -> "SatelliteDisconnected":
108 return SatelliteDisconnected()