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

impl EnergyStorage {
    /// Gets whether energy can be taken out of the storage
    pub fn can_extract_energy(&self) -> Result<bool, HlapiClientError> {
        Ok(self.call("canExtractEnergy", &[], &[])?.0)
    }

    /// Gets whether energy can be put into the the storage
    pub fn can_receive_energy(&self) -> Result<bool, HlapiClientError> {
        Ok(self.call("canReceiveEnergy", &[], &[])?.0)
    }

    /// Gets how much energy is currently stored
    pub fn get_energy_stored(&self) -> Result<u32, HlapiClientError> {
        Ok(self.call("getEnergyStored", &[], &[])?.0)
    }

    /// Gets how much energy can be stored at most
    pub fn get_max_energy_stored(&self) -> Result<u32, HlapiClientError> {
        Ok(self.call("getMaxEnergyStored", &[], &[])?.0)
    }
}

impl DeviceBase for EnergyStorage {
    const TYPE: &'static str = "energy_storage";

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