Expand description
La Marzocco CLI and Library
A command-line interface and library for controlling La Marzocco espresso machines.
This library provides functionality to:
- Authenticate with La Marzocco cloud service
- List machines connected to an account
- Turn machines on and off remotely
- Automatic JWT token management with expiration checking
- Token refresh callbacks for custom token persistence
§Library Usage
use lm_rs::{AuthenticationClient, ApiClient, TokenRefreshCallback, Credentials};
use std::sync::Arc;
// Authenticate and get tokens
let auth_client = AuthenticationClient::new();
let tokens = auth_client.login("username", "password").await?;
// Create API client with token refresh callback
struct MyTokenStorage;
impl TokenRefreshCallback for MyTokenStorage {
fn on_tokens_refreshed(&self, credentials: &Credentials) {
// Save refreshed tokens to your storage
println!("Tokens refreshed for user: {}", credentials.username);
}
}
let callback = Arc::new(MyTokenStorage);
let mut api_client = ApiClient::new(tokens, Some(callback));
// Use API client for machine operations
let machines = api_client.get_machines().await?;
if let Some(machine) = machines.first() {
api_client.turn_on_machine(&machine.serial_number).await?;
}
§CLI Usage
The main functionality is also provided through the CLI binary for direct command-line usage.
Re-exports§
pub use auth::is_token_expired;
pub use auth::ApiClient;
pub use auth::AuthenticationClient;
pub use auth::TokenRefreshCallback;
pub use types::Credentials;
pub use client::LaMarzoccoClient;
pub use types::Machine;
pub use types::MachineCommand;
pub use types::MachineStatus;