mirror of
https://github.com/aramperes/nut-rs.git
synced 2025-09-08 05:08:31 -04:00
parent
2360bd4a3f
commit
cf0f058c7a
1 changed files with 37 additions and 0 deletions
|
@ -84,6 +84,10 @@ pub enum Response {
|
|||
///
|
||||
/// Params: (command description)
|
||||
CmdDesc(String),
|
||||
/// A UPS description (UPSDESC) response.
|
||||
///
|
||||
/// Params: (UPS description)
|
||||
UpsDesc(String),
|
||||
/// A mutable variable (RW) response.
|
||||
///
|
||||
/// Params: (var name, var value)
|
||||
|
@ -281,6 +285,23 @@ impl Response {
|
|||
}?;
|
||||
Ok(Response::CmdDesc(desc))
|
||||
}
|
||||
"UPSDESC" => {
|
||||
let _device = if args.is_empty() {
|
||||
Err(ClientError::from(NutError::Generic(
|
||||
"Unspecified UPSDESC device in response".into(),
|
||||
)))
|
||||
} else {
|
||||
Ok(args.remove(0))
|
||||
}?;
|
||||
let desc = if args.is_empty() {
|
||||
Err(ClientError::from(NutError::Generic(
|
||||
"Unspecified UPSDESC description in response".into(),
|
||||
)))
|
||||
} else {
|
||||
Ok(args.remove(0))
|
||||
}?;
|
||||
Ok(Response::UpsDesc(desc))
|
||||
}
|
||||
"DESC" => {
|
||||
let _device = if args.is_empty() {
|
||||
Err(ClientError::from(NutError::Generic(
|
||||
|
@ -399,6 +420,14 @@ impl Response {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn expect_upsdesc(&self) -> crate::Result<String> {
|
||||
if let Self::UpsDesc(description) = &self {
|
||||
Ok(description.to_owned())
|
||||
} else {
|
||||
Err(NutError::UnexpectedResponse.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_desc(&self) -> crate::Result<String> {
|
||||
if let Self::Desc(description) = &self {
|
||||
Ok(description.to_owned())
|
||||
|
@ -680,6 +709,14 @@ implement_get_commands! {
|
|||
)
|
||||
}
|
||||
|
||||
/// Queries the description of a UPS device.
|
||||
pub fn get_ups_description(ups_name: &str) -> String {
|
||||
(
|
||||
{ &["UPSDESC", ups_name] },
|
||||
{ |row: Response| row.expect_upsdesc() },
|
||||
)
|
||||
}
|
||||
|
||||
/// Queries the number of logins to the specified UPS.
|
||||
pub fn get_num_logins(ups_name: &str) -> i32 {
|
||||
(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue