Skip to content

Commit

Permalink
Merge pull request #113 from fel115/nc_status_update
Browse files Browse the repository at this point in the history
added Ping module to information output; added Status for Battery
  • Loading branch information
markus2330 authored Oct 16, 2023
2 parents ff54734 + fb63437 commit a446ad4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/bat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use tokio::time::interval;

use crate::nextcloud::NextcloudChat;
use crate::nextcloud::NextcloudEvent;
use crate::nextcloud::NextcloudStatus;
use crate::types::ModuleError;

const START_CAPACITY_THRESHOLD: u8 = 50;
Expand All @@ -24,7 +25,7 @@ pub struct Bat {
impl Bat {
pub fn new() -> Self {
Self {
capacity: 0,
capacity: 100,
capacity_threshold: START_CAPACITY_THRESHOLD,
}
}
Expand All @@ -48,6 +49,12 @@ impl Bat {
if new_capacity != self.capacity {
self.capacity = new_capacity;
if self.capacity < self.capacity_threshold {
nextcloud_sender
.send(NextcloudEvent::Status(
NextcloudStatus::Online,
gettext!("🪫 ON {}", self.capacity),
))
.await?;
nextcloud_sender
.send(NextcloudEvent::Chat(
NextcloudChat::Default,
Expand All @@ -65,6 +72,12 @@ impl Bat {
}
} else if self.capacity == 100 {
self.capacity_threshold = START_CAPACITY_THRESHOLD;
nextcloud_sender
.send(NextcloudEvent::Status(
NextcloudStatus::Online,
gettext!("🔋 ON {}", self.capacity),
))
.await?;
nextcloud_sender
.send(NextcloudEvent::Chat(
NextcloudChat::Default,
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ async fn main() -> Result<(), ModuleError> {

nextcloud_sender.send(
NextcloudEvent::Chat(NextcloudChat::Default,
gettext!("Enabled Modules: \nButtons: {}\n, Garage: {}\n, Sensors: {}\n, ModIR: {}\n, Environment: {}\n, Weatherstation: {}\n, Battery: {}\n, Watchdog: {}\n",
gettext!("Enabled Modules: \nButtons: {},\n Garage: {},\n Sensors: {},\n ModIR: {},\n Environment: {},\n Weatherstation: {},\n Battery: {},\n Watchdog: {},\n Ping: {}\n",
buttons_enabled,
garage_enabled,
sensors_enabled,
Expand All @@ -237,6 +237,7 @@ async fn main() -> Result<(), ModuleError> {
weatherstation_enabled,
bat_enabled,
watchdog_enabled,
ping_enabled,
))).await?;

join_all(tasks).await;
Expand Down

0 comments on commit a446ad4

Please sign in to comment.