Files
MeshTerm/meshterm/tools/device_actions.py
T
Jean-Pierre MartineauandClaude Fable 5 920b3f8b83 Promote Send advert to the main menu as its own tool
Announcing the node is the everyday operation in the Device actions
bucket, but it sat two screens deep and out of reach of the main menu's
type-to-filter. Give it a top-level entry (order 10, right after Device
actions; Device info shifts to 11) via a new menu-only tool that reuses
the existing advert flow through a standalone send_advert() entry point.
Only SELF_INFO is read on open — the advert op and contact card never
need the full snapshot — so it stays snappy over Bluetooth. The row
inside Device actions stays, and scripting remains under `config
advert` / `config share`, so no new CLI subcommand.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-10 01:27:41 -04:00

74 lines
2.7 KiB
Python

"""The ``device-actions`` tool: immediate operations on the companion device itself.
Opens the Device actions screen (see :func:`meshterm.ui.config_editor.device_actions`) —
adverts, backup/restore, the identity key, reboot, and factory reset. Where the sibling
``config`` tool *stages* value changes for review, everything here acts on the box the
moment it is confirmed, so the two concerns get their own menu entries and screens.
Menu-only: every action already has a first-class scripted equivalent under the ``config``
CLI group (``config backup``, ``config restore``, ``config reboot``, ...), so no duplicate
subcommand is registered here.
The advert action is additionally promoted to its own main-menu entry (the sibling
``advert`` tool — see :mod:`meshterm.tools.advert`): it is the everyday operation in this
bucket, so it earns a top-level row while remaining available here with the rest.
"""
from __future__ import annotations
from typing import Any, Optional
import typer
from ..context import AppContext
from .base import Tool, ToolResult, register
@register
class DeviceActionsTool(Tool):
"""Run immediate device operations: advert, backup, identity key, reboot, reset."""
name = "device-actions"
title = "Device actions"
help = "Act on the device itself — advert, backup, identity key, reboot, reset"
category = "Device"
order = 9
async def prompt_params(self, ctx: AppContext) -> Optional[dict[str, Any]]:
"""Run the interactive actions screen; there are never parameters to collect.
Each action executes and presents its result inside the screen itself, so by the
time the user backs out there is nothing left for :meth:`run` to do — returning
``None`` tells the menu the invocation is complete (the same pattern as backing
out of the config editor with nothing staged).
Args:
ctx: Shared application context.
Returns:
Always ``None``.
"""
from ..ui.config_editor import device_actions
await device_actions(ctx)
return None
async def run(self, ctx: AppContext, params: dict[str, Any]) -> ToolResult:
"""Nothing runs here: the actions execute inside :meth:`prompt_params`.
Args:
ctx: Shared application context.
params: Unused.
Returns:
An empty :class:`ToolResult` (only reachable from a scripted call).
"""
return ToolResult(summary={})
def register_cli(self, app: typer.Typer) -> None:
"""Register no CLI command — the scripted equivalents live under ``config``.
Args:
app: The Typer application (untouched).
"""