Pick the companion device at startup only
The devices tool doubled as a mid-session device switcher: its menu prompt re-ran the picker and reassigned the active device. Drop that so selection is a startup-only concern (or --port on the CLI); the tool is now a read-only inventory in both the menu and CLI. With the re-pick gone, startup is the sole caller of prompt_device, so its cancel_label parameter (added only to swap in a "Back" label) is removed and the "Skip…" label inlined. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
7dbe4373be
commit
0c0880b37d
2 files changed
+11
-45
No files matched your search
@@ -1,9 +1,9 @@
|
||||
"""The ``devices`` tool: enumerate serial companion devices and (in the menu) pick one.
|
||||
"""The ``devices`` tool: enumerate attached serial companion devices.
|
||||
|
||||
Discovery never opens the radio — it only lists what is attached. On the CLI this is a
|
||||
read-only inventory; selection there happens by passing ``--port`` to a command, which is
|
||||
remembered after it connects. In the interactive menu this tool additionally offers the
|
||||
device picker to change the session's active device.
|
||||
Discovery never opens the radio — it only lists what is attached. This is a read-only
|
||||
inventory in both the menu and the CLI; it flags likely LoRa hardware and marks the active
|
||||
and remembered devices. Selecting a companion is a startup-only concern: pass ``--port`` on
|
||||
the CLI (remembered after it connects), or pick from the prompt shown when the menu launches.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -31,40 +31,10 @@ class DevicesTool(Tool):
|
||||
"""List attached serial devices, flag likely LoRa hardware, mark the default."""
|
||||
|
||||
name = "devices"
|
||||
help = "List attached serial devices and pick the companion to use."
|
||||
help = "List attached serial devices and flag likely LoRa hardware."
|
||||
category = "Device"
|
||||
order = 5
|
||||
|
||||
async def prompt_params(self, ctx: AppContext) -> dict[str, Any]:
|
||||
"""In the menu, show the device picker so the user can change the active device.
|
||||
|
||||
The picker itself carries a "Back" row, so it reads like every other menu screen
|
||||
rather than a bare yes/no confirmation.
|
||||
|
||||
Args:
|
||||
ctx: Shared application context.
|
||||
|
||||
Returns:
|
||||
Always ``{}`` — the table in :meth:`run` reflects the (possibly changed) device.
|
||||
"""
|
||||
if ctx.mock:
|
||||
return {}
|
||||
|
||||
from ..ui.device_picker import prompt_device
|
||||
|
||||
devices = discover_devices()
|
||||
chosen = await prompt_device(
|
||||
ctx.ui, devices, ctx.device_store.load(), cancel_label="Back"
|
||||
)
|
||||
if chosen is not None:
|
||||
ctx.selected_device = chosen
|
||||
ctx.port_override = chosen.port
|
||||
ctx.ui.note(
|
||||
f"[ok]●[/ok] active device set to [accent]{chosen.label}[/accent] "
|
||||
"[muted](remembered once it connects)[/muted]"
|
||||
)
|
||||
return {}
|
||||
|
||||
async def run(self, ctx: AppContext, params: dict[str, Any]) -> ToolResult:
|
||||
"""Enumerate serial devices and render them as a table.
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"""Interactive companion-device picker, rendered in the full-screen session.
|
||||
|
||||
Shown at the start of the interactive menu (and from the ``devices`` tool) when no port was
|
||||
given explicitly. It lists the discovered devices, marks the remembered "last known good"
|
||||
one, and preselects it as the default. The chosen device becomes the session's active
|
||||
device; it is persisted as the new default once it actually connects.
|
||||
Shown once at the start of the interactive menu when no port was given explicitly. It lists
|
||||
the discovered devices, marks the remembered "last known good" one, and preselects it as the
|
||||
default. The chosen device becomes the session's active device; it is persisted as the new
|
||||
default once it actually connects.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -32,8 +32,6 @@ async def prompt_device(
|
||||
ui: "Ui",
|
||||
devices: list[DiscoveredDevice],
|
||||
remembered: Optional[RememberedDevice],
|
||||
*,
|
||||
cancel_label: str = "Skip (use --mock / configure later)",
|
||||
) -> Optional[DiscoveredDevice]:
|
||||
"""Prompt the user to choose a companion device.
|
||||
|
||||
@@ -41,8 +39,6 @@ async def prompt_device(
|
||||
ui: The interactive UI surface used to render the picker.
|
||||
devices: Discovered devices (likely-LoRa first).
|
||||
remembered: The remembered default, if any, used to mark and preselect a row.
|
||||
cancel_label: Label for the final "don't pick" row — "Skip…" at startup (there is
|
||||
no going back yet), "Back" when re-picking from the devices tool.
|
||||
|
||||
Returns:
|
||||
The chosen :class:`DiscoveredDevice`, or ``None`` if the user cancelled or chose the
|
||||
@@ -74,6 +70,6 @@ async def prompt_device(
|
||||
default = device
|
||||
|
||||
items.append(Separator(" "))
|
||||
items.append(Choice(title=cancel_label, value=None))
|
||||
items.append(Choice(title="Skip (use --mock / configure later)", value=None))
|
||||
|
||||
return await ui.select("Select a companion device:", items, default=default)
|
||||
Reference in new issue
Block a user