mirror of
https://github.com/aramperes/nut-rs.git
synced 2025-09-09 13:38:30 -04:00
parent
b6e3a96aa1
commit
0e18b57624
4 changed files with 72 additions and 4 deletions
|
@ -84,6 +84,10 @@ pub enum Response {
|
|||
///
|
||||
/// Params: (command description)
|
||||
CmdDesc(String),
|
||||
/// A mutable variable (RW) response.
|
||||
///
|
||||
/// Params: (var name, var value)
|
||||
Rw(String, String),
|
||||
}
|
||||
|
||||
impl Response {
|
||||
|
@ -170,6 +174,30 @@ impl Response {
|
|||
}?;
|
||||
Ok(Response::Var(var_name, var_value))
|
||||
}
|
||||
"RW" => {
|
||||
let _var_device = if args.is_empty() {
|
||||
Err(ClientError::from(NutError::Generic(
|
||||
"Unspecified RW device name in response".into(),
|
||||
)))
|
||||
} else {
|
||||
Ok(args.remove(0))
|
||||
}?;
|
||||
let var_name = if args.is_empty() {
|
||||
Err(ClientError::from(NutError::Generic(
|
||||
"Unspecified RW name in response".into(),
|
||||
)))
|
||||
} else {
|
||||
Ok(args.remove(0))
|
||||
}?;
|
||||
let var_value = if args.is_empty() {
|
||||
Err(ClientError::from(NutError::Generic(
|
||||
"Unspecified RW value in response".into(),
|
||||
)))
|
||||
} else {
|
||||
Ok(args.remove(0))
|
||||
}?;
|
||||
Ok(Response::Rw(var_name, var_value))
|
||||
}
|
||||
"UPS" => {
|
||||
let name = if args.is_empty() {
|
||||
Err(ClientError::from(NutError::Generic(
|
||||
|
@ -277,6 +305,14 @@ impl Response {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn expect_rw(&self) -> crate::Result<Variable> {
|
||||
if let Self::Rw(name, value) = &self {
|
||||
Ok(Variable::parse(name, value.to_owned()))
|
||||
} else {
|
||||
Err(NutError::UnexpectedResponse.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_ups(&self) -> crate::Result<(String, String)> {
|
||||
if let Self::Ups(name, description) = &self {
|
||||
Ok((name.to_owned(), description.to_owned()))
|
||||
|
@ -532,6 +568,14 @@ implement_list_commands! {
|
|||
)
|
||||
}
|
||||
|
||||
/// Queries the list of mutable variables for a UPS device.
|
||||
pub fn list_mutable_variables(ups_name: &str) -> Vec<Variable> {
|
||||
(
|
||||
{ &["RW", ups_name] },
|
||||
{ |row: Response| row.expect_rw() },
|
||||
)
|
||||
}
|
||||
|
||||
/// Queries the list of commands available for the given device.
|
||||
pub fn list_commands(ups_name: &str) -> Vec<String> {
|
||||
(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue