Skip to content

Commit

Permalink
add option to disable full design value
Browse files Browse the repository at this point in the history
  • Loading branch information
doums committed Oct 14, 2020
1 parent 11cd873 commit 839ab21
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bato"
version = "0.1.0"
version = "0.1.1"
authors = ["pierre <dommerc.pierre@gmail.com>"]
edition = "2018"
links = "notilus"
Expand Down
5 changes: 5 additions & 0 deletions bato.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ critical_level: 5
#
low_level: 30

# full_design: bool, default: true
#
# Whether or not the current level is calculated based on the full design value.
#
full_design: true

# # # # # # # # #
# notifications #
Expand Down
13 changes: 11 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct Config {
pub bat_name: Option<String>,
pub low_level: u32,
pub critical_level: u32,
pub full_design: Option<bool>,
critical: Notification,
low: Notification,
full: Notification,
Expand All @@ -52,6 +53,7 @@ pub struct Bato {
config: Config,
critical_notified: bool,
low_notified: bool,
full_design: bool,
full_notified: bool,
status_notified: bool,
previous_status: String,
Expand All @@ -73,11 +75,16 @@ impl<'a> Bato {
if config.full.urgency.is_none() {
config.full.urgency = Some(Urgency::Low)
}
let mut full_design = true;
if let Some(v) = config.full_design {
full_design = v;
}
Bato {
bat_name,
config,
critical_notified: false,
notification: ptr::null_mut(),
full_design,
low_notified: false,
full_notified: false,
status_notified: false,
Expand All @@ -96,8 +103,10 @@ impl<'a> Bato {

pub fn check(&mut self) -> Result<(), Error> {
let mut current_notification: Option<&Notification> = None;
let energy_full =
read_and_parse(&format!("{}{}/energy_full_design", SYS_PATH, self.bat_name))?;
let energy_full = match self.full_design {
true => read_and_parse(&format!("{}{}/energy_full_design", SYS_PATH, self.bat_name))?,
false => read_and_parse(&format!("{}{}/energy_full", SYS_PATH, self.bat_name))?,
};
let energy_now = read_and_parse(&format!("{}{}/energy_now", SYS_PATH, self.bat_name))?;
let status = read_and_trim(&format!("{}{}/status", SYS_PATH, self.bat_name))?;
let capacity = energy_full as u64;
Expand Down

0 comments on commit 839ab21

Please sign in to comment.