Skip to content

Commit

Permalink
Only enable ping if server supports it
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesiam committed Jan 17, 2024
1 parent 4d52ef3 commit 3a91fc4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
21 changes: 15 additions & 6 deletions installer/satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ def satellite_menu(last_choice: Optional[str]) -> Optional[str]:
def configure_feedback(settings: Settings) -> None:
choice: Optional[str] = None
while True:
choice = menu("Main > Satellite > Feedback", [("respeaker", "ReSpeaker")])
choice = menu(
"Main > Satellite > Feedback",
[("respeaker", "ReSpeaker")],
menu_args=["--ok-button", "Select", "--cancel-button", "Back"],
)
if choice == "respeaker":
selected_service: Optional[str] = None
if settings.satellite.event_service_command:
Expand All @@ -94,18 +98,23 @@ def configure_feedback(settings: Settings) -> None:
event_service = radiolist(
"Event Service:",
[
("none", "None"),
("2mic", "2mic LEDs"),
("4mic", "4mic LEDs"),
],
selected_service,
)

if event_service is not None:
settings.satellite.event_service_command = [
str(PROGRAM_DIR / "script" / f"run_{event_service}"),
"--uri",
"tcp://127.0.0.1:10500",
]
if event_service == "none":
settings.satellite.event_service_command = None
else:
settings.satellite.event_service_command = [
str(PROGRAM_DIR / "script" / f"run_{event_service}"),
"--uri",
"tcp://127.0.0.1:10500",
]

settings.save()
else:
break
6 changes: 5 additions & 1 deletion wyoming_satellite/satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(self, settings: SatelliteSettings) -> None:
self._event_task: Optional[asyncio.Task] = None
self._event_queue: "Optional[asyncio.Queue[Event]]" = None

self._ping_server_enabled: bool = False
self._pong_received_event = asyncio.Event()
self._ping_server_task = asyncio.create_task(self._ping_server(), name="ping")

Expand Down Expand Up @@ -170,7 +171,7 @@ async def _ping_server(self) -> None:
try:
while self.is_running:
await asyncio.sleep(_PING_SEND_DELAY)
if self.server_id is None:
if (self.server_id is None) or (not self._ping_server_enabled):
# No server connected
continue

Expand Down Expand Up @@ -220,6 +221,9 @@ async def event_from_server(self, event: Event) -> None:
# Respond with pong
ping = Ping.from_event(event)
await self.event_to_server(Pong(text=ping.text).event())

# Enable pinging
self._ping_server_enabled = True
elif Pong.is_type(event.type):
# Response from our ping
self._pong_received_event.set()
Expand Down

0 comments on commit 3a91fc4

Please sign in to comment.