Some cleanup and added light sensor

This commit is contained in:
2023-01-03 20:46:37 +01:00
parent cfd10a7daf
commit c9b2127eed
10 changed files with 182 additions and 43 deletions

View File

@@ -136,3 +136,44 @@ impl TryFrom<&Publish> for RemoteMessage {
.or(Err(anyhow::anyhow!("Invalid message payload received: {:?}", message.payload)))
}
}
#[derive(Debug, Deserialize)]
pub struct PresenceMessage {
state: bool
}
impl PresenceMessage {
pub fn present(&self) -> bool {
self.state
}
}
impl TryFrom<&Publish> for PresenceMessage {
type Error = anyhow::Error;
fn try_from(message: &Publish) -> Result<Self, Self::Error> {
serde_json::from_slice(&message.payload)
.or(Err(anyhow::anyhow!("Invalid message payload received: {:?}", message.payload)))
}
}
#[derive(Debug, Deserialize)]
pub struct BrightnessMessage {
illuminance: isize,
}
impl BrightnessMessage {
pub fn illuminance(&self) -> isize {
self.illuminance
}
}
impl TryFrom<&Publish> for BrightnessMessage {
type Error = anyhow::Error;
fn try_from(message: &Publish) -> Result<Self, Self::Error> {
serde_json::from_slice(&message.payload)
.or(Err(anyhow::anyhow!("Invalid message payload received: {:?}", message.payload)))
}
}