Add battery sub command
This commit is contained in:
2 files changed
+50
No files matched your search
@@ -0,0 +1,8 @@
|
||||
use clap::Parser;
|
||||
|
||||
/// The battery command will dump the battery status to XML
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct Opt {
|
||||
/// The name of the camera. Must be a name in the config
|
||||
pub camera: String,
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
///
|
||||
/// # Neolink Battery
|
||||
///
|
||||
/// This module handles the printing of the Battery status
|
||||
/// in xml format
|
||||
///
|
||||
/// # Usage
|
||||
///
|
||||
/// ```bash
|
||||
/// neolink battery --config=config.toml CameraName
|
||||
/// ```
|
||||
///
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
mod cmdline;
|
||||
|
||||
use super::config::Config;
|
||||
use crate::utils::find_and_connect;
|
||||
pub(crate) use cmdline::Opt;
|
||||
|
||||
/// Entry point for the battery subcommand
|
||||
///
|
||||
/// Opt is the command line options
|
||||
pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> {
|
||||
let camera = find_and_connect(&config, &opt.camera).await?;
|
||||
|
||||
let state = camera
|
||||
.battery_info()
|
||||
.await
|
||||
.context("Unable to get camera Battery state")?;
|
||||
let ser = String::from_utf8(
|
||||
yaserde::ser::serialize_with_writer(&state, vec![], &Default::default())
|
||||
.expect("Should Ser the struct"),
|
||||
)
|
||||
.expect("Should be UTF8");
|
||||
println!("{}", ser);
|
||||
|
||||
let _ = camera.logout().await;
|
||||
camera.disconnect().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user