Some cleanup and added light sensor
This commit is contained in:
41
src/mqtt.rs
41
src/mqtt.rs
@@ -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)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user