mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-22 14:57:56 +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::config::Settings;
|
||||||
use crate::registries::{Registries, Actuator, ActBox, StatusSignal};
|
use crate::registries::{Registries, Actuator, ActBox, StatusSignal};
|
||||||
use crate::error::Result;
|
use crate::error::Result;
|
||||||
|
use crate::machine::Status;
|
||||||
|
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use futures::prelude::*;
|
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>> {
|
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
|
||||||
let unpin = Pin::into_inner(self);
|
let unpin = Pin::into_inner(self);
|
||||||
if let Some(ref mut s) = unpin.signal {
|
if let Some(ref mut s) = unpin.signal {
|
||||||
let status = ready!(Signal::poll_change(Pin::new(s), cx));
|
if let Some(status) = ready!(Signal::poll_change(Pin::new(s), cx)) {
|
||||||
let topic = format!("shellies/{}/relay/0/command", unpin.name);
|
let topic = format!("shellies/{}/relay/0/command", unpin.name);
|
||||||
let msg = mqtt::Message::new(topic, "on", 0);
|
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(|_| ());
|
let f = unpin.client.publish(msg).map(|_| ());
|
||||||
|
|
||||||
Poll::Ready(Some(Box::pin(f)))
|
return Poll::Ready(Some(Box::pin(f)));
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user