Skip to content

Add 'halpi get <measurement>' command for retrieving individual values #65

@mairas

Description

@mairas

Description

The Python halpi CLI has a get command that retrieves individual measurements and runtime values from the daemon. This command is missing from the Rust implementation.

Python CLI Behavior

halpi get V_in              # Get input voltage only
halpi get V_supercap        # Get supercap voltage only
halpi get state             # Get state only
halpi get firmware_version  # Get firmware version only
# etc.

This command calls the /values/<key> endpoint and prints just the value (not in a table format like status).

Reference Implementation

Python implementation: HALPI2-python-daemon/src/halpi/cli.py:248-267

@app.command("get")
def get(
    measurement: str = typer.Argument(
        ...,
        help=(
            "Measurement to retrieve (e.g., V_in, V_supercap, I_in, "
            "T_mcu, state, 5v_output_enabled, usb_port_state, watchdog_enabled, "
            "watchdog_timeout, watchdog_elapsed, hardware_version, firmware_version, "
            "device_id)"
        ),
    ),
) -> None:
    """Get individual measurements and runtime values."""
    try:
        value = asyncio.run(async_get_value_key(state["socket"], measurement))
        console.print(value)
    except Exception as e:
        console.print(f"Error getting measurement '{measurement}': {e}", style="red")
        raise typer.Exit(code=1)

Proposed Implementation

Add a new Get command to the Rust CLI:

#[derive(Subcommand)]
enum Commands {
    // ... existing commands ...
    
    /// Get individual measurements and runtime values
    Get {
        /// Measurement key to retrieve (e.g., V_in, state, firmware_version)
        measurement: String,
    },
}

The command should:

  1. Accept a measurement key as an argument
  2. Call the /values/<key> endpoint via the Unix socket
  3. Print just the value (not formatted in a table)
  4. Exit with error code 1 if the key doesn't exist or another error occurs

API Compatibility

This is required for 100% CLI compatibility with the Python halpid 4.x version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions