Skip to content

Commit

Permalink
Add report fn to persisted shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasKoch committed Sep 26, 2024
1 parent f924e1e commit 1763f6c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/shadows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ where
}
}

pub async fn delete_shadow(&mut self) -> Result<(), Error> {
pub async fn delete_shadow(&self) -> Result<(), Error> {
// Wait for mqtt to connect
self.mqtt.wait_connected().await;

Expand Down Expand Up @@ -444,7 +444,7 @@ where
}

/// Get an immutable reference to the internal local state.
pub async fn try_get(&mut self) -> Result<S, Error> {
pub async fn try_get(&self) -> Result<S, Error> {
self.dao.lock().await.read().await
}

Expand All @@ -465,6 +465,14 @@ where
Ok(state)
}

/// Report the state of the shadow.
pub async fn report(&self) -> Result<(), Error> {
let state = self.dao.lock().await.read().await?;

self.handler.report(&state).await?;
Ok(())
}

/// Update the state of the shadow.
///
/// This function will update the desired state of the shadow in the cloud,
Expand All @@ -491,7 +499,7 @@ where
Ok(())
}

pub async fn delete_shadow(&mut self) -> Result<(), Error> {
pub async fn delete_shadow(&self) -> Result<(), Error> {
self.handler.delete_shadow().await?;
self.dao.lock().await.write(&S::default()).await?;
Ok(())
Expand Down

0 comments on commit 1763f6c

Please sign in to comment.