oc2_hlapi_v2 0.2.0

A client for the new version of OpenComputers II's HLAPI
Documentation
use std::convert::Infallible;

use uuid::Uuid;

use crate::client::{DeviceBase, HlapiClient, HlapiClientError};

#[derive(Debug, Clone)]
/// A composter device
///
/// [OC2 Docs](https://fnuecke.github.io/oc2/manual/en_us/device/composter.html)
pub struct Composter {
    client: HlapiClient,
    uuid: Uuid,
}

impl Composter {
    /// Gets how full the composter is, from 0 to 8.
    pub fn get_level(&self) -> Result<u8, HlapiClientError> {
        Ok(self.call("getLevel", &[], &[])?.0)
    }
}

impl DeviceBase for Composter {
    const TYPE: &'static str = "composter";

    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
    }
}