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

impl Beacon {
    /// Gets how many levels the pyramid below the beacon has, from 0 to 4.
    pub fn get_levels(&self) -> Result<u8, HlapiClientError> {
        Ok(self.call("getLevels", &[], &[])?.0)
    }

    /// Gets the primary effect the beacon grants, if set
    pub fn get_primary_effect(&self) -> Result<Option<String>, HlapiClientError> {
        Ok(self.call("getPrimaryEffect", &[], &[])?.0)
    }

    /// Gets the secondary effect the beacon grants, if set
    pub fn get_secondary_effect(&self) -> Result<Option<String>, HlapiClientError> {
        Ok(self.call("getSecondaryEffect", &[], &[])?.0)
    }
}

impl DeviceBase for Beacon {
    const TYPE: &'static str = "beacon";

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