use zb_core::Destination;
use zb_zcl::on_off::{Effect, Off, OffWithEffect, On, Toggle};
use crate::api::Zcl;
use crate::{Error, TransmissionResponse};
pub trait OnOff {
fn on(
&self,
destination: Destination,
) -> impl Future<Output = Result<TransmissionResponse, Error>> + Send;
fn off(
&self,
destination: Destination,
) -> impl Future<Output = Result<TransmissionResponse, Error>> + Send;
fn off_with_effect(
&self,
destination: Destination,
effect: Effect,
) -> impl Future<Output = Result<TransmissionResponse, Error>> + Send;
fn toggle(
&self,
destination: Destination,
) -> impl Future<Output = Result<TransmissionResponse, Error>> + Send;
}
impl<T> OnOff for T
where
T: Zcl + Sync,
{
async fn on(&self, destination: Destination) -> Result<TransmissionResponse, Error> {
self.transmit(destination, On).await
}
async fn off(&self, destination: Destination) -> Result<TransmissionResponse, Error> {
self.transmit(destination, Off).await
}
async fn off_with_effect(
&self,
destination: Destination,
effect: Effect,
) -> Result<TransmissionResponse, Error> {
self.transmit(destination, OffWithEffect::new(effect)).await
}
async fn toggle(&self, destination: Destination) -> Result<TransmissionResponse, Error> {
self.transmit(destination, Toggle).await
}
}