Add ping
This commit is contained in:
@@ -36,6 +36,7 @@ class SatelliteSettings(DataClassJsonMixin):
|
||||
name: str = "Wyoming Satellite"
|
||||
type: SatelliteType = SatelliteType.ALWAYS_STREAMING
|
||||
debug: bool = False
|
||||
event_service_command: Optional[List[str]] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
+38
-10
@@ -1,7 +1,7 @@
|
||||
"""Satellite settings."""
|
||||
from typing import Optional
|
||||
|
||||
from .const import SatelliteType, Settings
|
||||
from .const import SatelliteType, Settings, PROGRAM_DIR
|
||||
from .whiptail import error, inputbox, menu, passwordbox, radiolist, run_with_gauge
|
||||
|
||||
|
||||
@@ -29,20 +29,22 @@ def configure_satellite(settings: Settings) -> None:
|
||||
if satellite_type is not None:
|
||||
settings.satellite.type = SatelliteType(satellite_type)
|
||||
settings.save()
|
||||
elif choice in ("stop", "start"):
|
||||
elif choice == "feedback":
|
||||
configure_feedback(settings)
|
||||
elif choice in ("restart", "stop", "start"):
|
||||
password = passwordbox("sudo password:")
|
||||
if not password:
|
||||
continue
|
||||
|
||||
command = ["sudo", "-S", "systemctl", choice, "wyoming-satellite.service"]
|
||||
text = (
|
||||
"Stopping satellite..." if choice == "stop" else "Starting satellite..."
|
||||
text = {"restart": "Restarting", "stop": "Stopping", "start": "Starting"}[
|
||||
choice
|
||||
]
|
||||
success = run_with_gauge(
|
||||
f"{text} satellite...", [command], sudo_password=password
|
||||
)
|
||||
success = run_with_gauge(text, [command], sudo_password=password)
|
||||
if not success:
|
||||
error(
|
||||
"stopping satellite" if choice == "stop" else "starting satellite"
|
||||
)
|
||||
error(f"{text.lower()} satellite")
|
||||
elif choice == "debug":
|
||||
debug = radiolist(
|
||||
"Debug Mode:",
|
||||
@@ -66,10 +68,36 @@ def satellite_menu(last_choice: Optional[str]) -> Optional[str]:
|
||||
[
|
||||
("name", "Satellite Name"),
|
||||
("type", "Satellite Type"),
|
||||
("stop", "Stop Service"),
|
||||
("start", "Start Service"),
|
||||
("feedback", "Feedback"),
|
||||
("restart", "Restart Services"),
|
||||
("stop", "Stop Services"),
|
||||
("start", "Start Services"),
|
||||
("debug", "Set Debug Mode"),
|
||||
],
|
||||
selected_item=last_choice,
|
||||
menu_args=["--ok-button", "Select", "--cancel-button", "Back"],
|
||||
)
|
||||
|
||||
|
||||
def configure_feedback(settings: Settings) -> None:
|
||||
choice: Optional[str] = None
|
||||
while True:
|
||||
choice = menu("Main > Satellite > Feedback", [("respeaker", "ReSpeaker")])
|
||||
if choice == "respeaker":
|
||||
event_service = radiolist(
|
||||
"Event Service:",
|
||||
[
|
||||
("2mic", "2mic LEDs"),
|
||||
("4mic", "4mic LEDs"),
|
||||
],
|
||||
)
|
||||
|
||||
if event_service is not None:
|
||||
settings.satellite.event_service_command = [
|
||||
str(PROGRAM_DIR / "script" / "run_{event_service}"),
|
||||
"--uri",
|
||||
"tcp://127.0.0.1:10500",
|
||||
]
|
||||
settings.save()
|
||||
else:
|
||||
break
|
||||
|
||||
@@ -158,6 +158,29 @@ def generate_services(settings: Settings) -> None:
|
||||
)
|
||||
satellite_requires.append(f"{wake_word_service}.service")
|
||||
|
||||
if settings.satellite.event_service_command:
|
||||
event_service = "wyoming-event"
|
||||
event_command_str = shlex.join(settings.satellite.event_service_command)
|
||||
with open(
|
||||
SERVICES_DIR / f"{event_service}.service", "w", encoding="utf-8"
|
||||
) as service_file:
|
||||
print("[Unit]", file=service_file)
|
||||
print(f"Description=Event service", file=service_file)
|
||||
print("", file=service_file)
|
||||
print("[Service]", file=service_file)
|
||||
print("Type=simple", file=service_file)
|
||||
print(f"User={user_name}", file=service_file)
|
||||
print(f"ExecStart={event_command_str}", file=service_file)
|
||||
print(f"WorkingDirectory={PROGRAM_DIR}", file=service_file)
|
||||
print("Restart=always", file=service_file)
|
||||
print("RestartSec=1", file=service_file)
|
||||
print("", file=service_file)
|
||||
print("[Install]", file=service_file)
|
||||
print("WantedBy=default.target", file=service_file)
|
||||
|
||||
satellite_command.extend(["--event-uri", "tcp://127.0.0.1:10500"])
|
||||
satellite_requires.append(f"{event_service}.service")
|
||||
|
||||
if settings.satellite.debug:
|
||||
satellite_command.extend(
|
||||
["--debug", "--debug-recording-dir", str(LOCAL_DIR / "debug-recording")]
|
||||
|
||||
Reference in New Issue
Block a user