mirror of
https://github.com/aramperes/nut-rs.git
synced 2025-09-09 05:28:31 -04:00
parent
ea8ecdbf0c
commit
fd1f72e1d0
1 changed files with 44 additions and 0 deletions
|
@ -88,6 +88,10 @@ pub enum Response {
|
||||||
///
|
///
|
||||||
/// Params: (var name, var value)
|
/// Params: (var name, var value)
|
||||||
Rw(String, String),
|
Rw(String, String),
|
||||||
|
/// A variable description (DESC) response.
|
||||||
|
///
|
||||||
|
/// Params: (variable description)
|
||||||
|
Desc(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
|
@ -273,6 +277,30 @@ impl Response {
|
||||||
}?;
|
}?;
|
||||||
Ok(Response::CmdDesc(desc))
|
Ok(Response::CmdDesc(desc))
|
||||||
}
|
}
|
||||||
|
"DESC" => {
|
||||||
|
let _device = if args.is_empty() {
|
||||||
|
Err(ClientError::from(NutError::Generic(
|
||||||
|
"Unspecified DESC device in response".into(),
|
||||||
|
)))
|
||||||
|
} else {
|
||||||
|
Ok(args.remove(0))
|
||||||
|
}?;
|
||||||
|
let _name = if args.is_empty() {
|
||||||
|
Err(ClientError::from(NutError::Generic(
|
||||||
|
"Unspecified DESC name in response".into(),
|
||||||
|
)))
|
||||||
|
} else {
|
||||||
|
Ok(args.remove(0))
|
||||||
|
}?;
|
||||||
|
let desc = if args.is_empty() {
|
||||||
|
Err(ClientError::from(NutError::Generic(
|
||||||
|
"Unspecified DESC description in response".into(),
|
||||||
|
)))
|
||||||
|
} else {
|
||||||
|
Ok(args.remove(0))
|
||||||
|
}?;
|
||||||
|
Ok(Response::Desc(desc))
|
||||||
|
}
|
||||||
_ => Err(NutError::UnknownResponseType(cmd_name).into()),
|
_ => Err(NutError::UnknownResponseType(cmd_name).into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -344,6 +372,14 @@ impl Response {
|
||||||
Err(NutError::UnexpectedResponse.into())
|
Err(NutError::UnexpectedResponse.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn expect_desc(&self) -> crate::Result<String> {
|
||||||
|
if let Self::Desc(description) = &self {
|
||||||
|
Ok(description.to_owned())
|
||||||
|
} else {
|
||||||
|
Err(NutError::UnexpectedResponse.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A macro for implementing `LIST` commands.
|
/// A macro for implementing `LIST` commands.
|
||||||
|
@ -594,6 +630,14 @@ implement_get_commands! {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Queries the description of a UPS variable.
|
||||||
|
pub fn get_var_description(ups_name: &str, variable: &str) -> String {
|
||||||
|
(
|
||||||
|
{ &["DESC", ups_name, variable] },
|
||||||
|
{ |row: Response| row.expect_desc() },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Queries the description of a UPS command.
|
/// Queries the description of a UPS command.
|
||||||
pub fn get_command_description(ups_name: &str, variable: &str) -> String {
|
pub fn get_command_description(ups_name: &str, variable: &str) -> String {
|
||||||
(
|
(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue