mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-14 03:07:57 +01:00
Subscriber is Actuator now
This commit is contained in:
parent
0ea9177e14
commit
4bd62216e2
@ -48,16 +48,8 @@ impl Shelly {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Actuator for Shelly {
|
impl Actuator for Shelly {
|
||||||
async fn power_on(&mut self, name: String) {
|
async fn subscribe(&mut self, signal: StatusSignal) {
|
||||||
let topic = format!("shellies/{}/relay/0/command", name);
|
self.signal.replace(signal);
|
||||||
let msg = mqtt::Message::new(topic, "on", 0);
|
|
||||||
self.client.publish(msg).map(|_| ()).await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn power_off(&mut self, name: String) {
|
|
||||||
let topic = format!("shellies/{}/relay/0/command", name);
|
|
||||||
let msg = mqtt::Message::new(topic, "off", 0);
|
|
||||||
self.client.publish(msg).map(|_| ()).await
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,19 +36,10 @@ impl Actuators {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
pub trait Actuator: Stream<Item = future::BoxFuture<'static, ()>> {
|
|
||||||
// TODO: Is it smarter to pass a (reference to?) a machine instead of 'name'? Do we need to
|
|
||||||
// pass basically arbitrary parameters to the Actuator?
|
|
||||||
async fn power_on(&mut self, name: String);
|
|
||||||
async fn power_off(&mut self, name: String);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type StatusSignal = Pin<Box<dyn Signal<Item = Status> + Send + Sync>>;
|
pub type StatusSignal = Pin<Box<dyn Signal<Item = Status> + Send + Sync>>;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Subscriber {
|
pub trait Actuator: Stream<Item = future::BoxFuture<'static, ()>> {
|
||||||
async fn subscribe(&mut self, signal: StatusSignal);
|
async fn subscribe(&mut self, signal: StatusSignal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,16 +51,6 @@ struct Dummy {
|
|||||||
}
|
}
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Actuator for Dummy {
|
impl Actuator for Dummy {
|
||||||
async fn power_on(&mut self, _name: String) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
async fn power_off(&mut self, _name: String) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl Subscriber for Dummy {
|
|
||||||
async fn subscribe(&mut self, signal: StatusSignal) {
|
async fn subscribe(&mut self, signal: StatusSignal) {
|
||||||
self.signal.replace(signal);
|
self.signal.replace(signal);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user