From 4bd62216e277097ef6fca6d374e339e99487ec35 Mon Sep 17 00:00:00 2001 From: Gregor Reitzenstein Date: Thu, 17 Sep 2020 15:36:42 +0200 Subject: [PATCH] Subscriber is Actuator now --- src/modules/shelly.rs | 12 ++---------- src/registries/actuators.rs | 21 +-------------------- 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/src/modules/shelly.rs b/src/modules/shelly.rs index 7e706f5..d7da62b 100644 --- a/src/modules/shelly.rs +++ b/src/modules/shelly.rs @@ -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); } } diff --git a/src/registries/actuators.rs b/src/registries/actuators.rs index 1e6a6e5..936d503 100644 --- a/src/registries/actuators.rs +++ b/src/registries/actuators.rs @@ -36,19 +36,10 @@ impl Actuators { } } - -#[async_trait] -pub trait Actuator: Stream> { - // 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 + Send + Sync>>; #[async_trait] -pub trait Subscriber { +pub trait Actuator: Stream> { 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); }