use std::{convert::Infallible, time::Duration};
use uuid::Uuid;
use crate::client::{DeviceBase, HlapiClient, HlapiClientError};
#[derive(Debug, Clone)]
pub struct BrewingStand {
client: HlapiClient,
uuid: Uuid,
}
impl BrewingStand {
pub fn get_brew_time(&self) -> Result<Option<Duration>, HlapiClientError> {
let raw: u32 = self.call("getBrewTime", &[], &[])?.0;
if raw == 0 {
Ok(None)
} else {
Ok(Some(Duration::from_millis(raw as u64 * 50)))
}
}
pub fn get_fuel(&self) -> Result<u32, HlapiClientError> {
Ok(self.call("getFuel", &[], &[])?.0)
}
}
impl DeviceBase for BrewingStand {
const TYPE: &'static str = "brewing_stand";
type Event = Infallible;
fn new(client: HlapiClient, uuid: Uuid) -> Result<Self, HlapiClientError> {
Ok(Self { client, uuid })
}
fn uuid_base(&self) -> Uuid {
self.uuid
}
fn client(&self) -> &HlapiClient {
&self.client
}
}