mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-12-22 19:53:49 +01:00
Actually make the shellies switch
This commit is contained in:
parent
4bd62216e2
commit
f4d5a70841
@ -3,6 +3,7 @@ use slog::Logger;
|
||||
use crate::config::Settings;
|
||||
use crate::registries::{Registries, Actuator, ActBox, StatusSignal};
|
||||
use crate::error::Result;
|
||||
use crate::machine::Status;
|
||||
|
||||
use std::pin::Pin;
|
||||
use futures::prelude::*;
|
||||
@ -59,14 +60,20 @@ impl Stream for Shelly {
|
||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
|
||||
let unpin = Pin::into_inner(self);
|
||||
if let Some(ref mut s) = unpin.signal {
|
||||
let status = ready!(Signal::poll_change(Pin::new(s), cx));
|
||||
let topic = format!("shellies/{}/relay/0/command", unpin.name);
|
||||
let msg = mqtt::Message::new(topic, "on", 0);
|
||||
let f = unpin.client.publish(msg).map(|_| ());
|
||||
if let Some(status) = ready!(Signal::poll_change(Pin::new(s), cx)) {
|
||||
let topic = format!("shellies/{}/relay/0/command", unpin.name);
|
||||
let pl = match status {
|
||||
Status::Free => "off",
|
||||
Status::Occupied => "on",
|
||||
Status::Blocked => "off",
|
||||
};
|
||||
let msg = mqtt::Message::new(topic, pl, 0);
|
||||
let f = unpin.client.publish(msg).map(|_| ());
|
||||
|
||||
Poll::Ready(Some(Box::pin(f)))
|
||||
} else {
|
||||
Poll::Pending
|
||||
return Poll::Ready(Some(Box::pin(f)));
|
||||
}
|
||||
}
|
||||
|
||||
Poll::Pending
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user