use super::CapabilityBase;
use crate::Error;
use dbus_message_parser::Value;
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
pub enum Mode {
Static = 0,
Blink = 1,
}
#[derive(Debug, Clone)]
pub struct MacroEffect(pub(crate) CapabilityBase);
impl MacroEffect {
pub(crate) const INTERFACE: &'static str = "razer.device.led.macromode";
pub(crate) const GET_METHOD: &'static str = "getMacroEffect";
const SET_METHOD: &'static str = "setMacroEffect";
pub async fn get(&self) -> Result<Mode, Error> {
self.0
.call_get_method(Self::INTERFACE, Self::GET_METHOD)
.await
.and_then(|response| match response {
Value::Int32(0) => Ok(Mode::Static),
Value::Int32(1) => Ok(Mode::Blink),
_ => Err(Error::InvalidResponse),
})
}
pub async fn set(&self, mode: Mode) -> Result<(), Error> {
self.0
.call_set_method(
Self::INTERFACE,
Self::SET_METHOD,
vec![Value::Int32(mode as i32)],
)
.await
}
pub async fn set_static(&self) -> Result<(), Error> {
self.set(Mode::Static).await
}
pub async fn set_blink(&self) -> Result<(), Error> {
self.set(Mode::Blink).await
}
}