Subscriber is Actuator now

This commit is contained in:
Gregor Reitzenstein 2020-09-17 15:36:42 +02:00
parent 0ea9177e14
commit 4bd62216e2
2 changed files with 3 additions and 30 deletions

View File

@ -48,16 +48,8 @@ impl Shelly {
#[async_trait]
impl Actuator for Shelly {
async fn power_on(&mut self, name: String) {
let topic = format!("shellies/{}/relay/0/command", name);
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
async fn subscribe(&mut self, signal: StatusSignal) {
self.signal.replace(signal);
}
}

View File

@ -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>>;
#[async_trait]
pub trait Subscriber {
pub trait Actuator: Stream<Item = future::BoxFuture<'static, ()>> {
async fn subscribe(&mut self, signal: StatusSignal);
}
@ -60,16 +51,6 @@ struct Dummy {
}
#[async_trait]
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) {
self.signal.replace(signal);
}