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 beehive device
///
/// [OC2 Docs](https://fnuecke.github.io/oc2/manual/en_us/device/beehive.html)
pub struct Beehive {
    client: HlapiClient,
    uuid: Uuid,
}

impl Beehive {
    /// Gets how many bees are inside the hive
    pub fn get_bee_count(&self) -> Result<u8, HlapiClientError> {
        Ok(self.call("getBeeCount", &[], &[])?.0)
    }

    /// Gets how much honey the hive holds, from 0 to 5.
    pub fn get_honey_level(&self) -> Result<u8, HlapiClientError> {
        Ok(self.call("getHoneyLevel", &[], &[])?.0)
    }

    /// Gets whether the hive's bees are currently sedated.
    pub fn is_sedated(&self) -> Result<bool, HlapiClientError> {
        Ok(self.call("isSedated", &[], &[])?.0)
    }
}

impl DeviceBase for Beehive {
    const TYPE: &'static str = "beehive";

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