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

impl Charger {
    /// Gets whether the charger is currently charging a device on top of it.
    pub fn is_charging(&self) -> Result<bool, HlapiClientError> {
        Ok(self.call("isCharging", &[], &[])?.0)
    }
}

impl DeviceBase for Charger {
    const TYPE: &'static str = "charger";

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